Home | History | Annotate | Download | only in web_resource
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_WEB_RESOURCE_EULA_ACCEPTED_NOTIFIER_H_
      6 #define CHROME_BROWSER_WEB_RESOURCE_EULA_ACCEPTED_NOTIFIER_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/prefs/pref_change_registrar.h"
     10 
     11 class PrefService;
     12 
     13 // Helper class for querying the EULA accepted state and receiving a
     14 // notification when the EULA is accepted.
     15 class EulaAcceptedNotifier {
     16  public:
     17   // Observes EULA accepted state changes.
     18   class Observer {
     19    public:
     20     virtual void OnEulaAccepted() = 0;
     21   };
     22 
     23   explicit EulaAcceptedNotifier(PrefService* local_state);
     24   virtual ~EulaAcceptedNotifier();
     25 
     26   // Initializes this class with the given |observer|. Must be called before
     27   // the class is used.
     28   void Init(Observer* observer);
     29 
     30   // Returns true if the EULA has been accepted. If the EULA has not yet been
     31   // accepted, begins monitoring the EULA state and will notify the observer
     32   // once the EULA has been accepted.
     33   virtual bool IsEulaAccepted();
     34 
     35   // Factory method for this class.
     36   static EulaAcceptedNotifier* Create();
     37 
     38  protected:
     39   // Notifies the observer that the EULA has been updated, made protected for
     40   // testing.
     41   void NotifyObserver();
     42 
     43  private:
     44   // Callback for EULA accepted pref change notification.
     45   void OnPrefChanged();
     46 
     47   // Local state pref service for querying the EULA accepted pref.
     48   PrefService* local_state_;
     49 
     50   // Used to listen for the EULA accepted pref change notification.
     51   PrefChangeRegistrar registrar_;
     52 
     53   // Observer of the EULA accepted notification.
     54   Observer* observer_;
     55 
     56   DISALLOW_COPY_AND_ASSIGN(EulaAcceptedNotifier);
     57 };
     58 
     59 #endif  // CHROME_BROWSER_WEB_RESOURCE_EULA_ACCEPTED_NOTIFIER_H_
     60