OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_METRICS_VARIATIONS_EULA_ACCEPTED_NOTIFIER_H_ | 5 #ifndef CHROME_BROWSER_METRICS_VARIATIONS_EULA_ACCEPTED_NOTIFIER_H_ |
6 #define CHROME_BROWSER_METRICS_VARIATIONS_EULA_ACCEPTED_NOTIFIER_H_ | 6 #define CHROME_BROWSER_METRICS_VARIATIONS_EULA_ACCEPTED_NOTIFIER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/prefs/pref_change_registrar.h" |
9 | 10 |
10 // Interface for querying the EULA accepted state and receiving a notification | 11 class PrefService; |
11 // when the EULA is accepted. This abstracts away the platform-specific logic | 12 |
12 // for EULA notifications on different platforms. | 13 // Helper class for querying the EULA accepted state and receiving a |
| 14 // notification when the EULA is accepted. |
13 class EulaAcceptedNotifier { | 15 class EulaAcceptedNotifier { |
14 public: | 16 public: |
15 // Observes EULA accepted state changes. | 17 // Observes EULA accepted state changes. |
16 class Observer { | 18 class Observer { |
17 public: | 19 public: |
18 virtual void OnEulaAccepted() = 0; | 20 virtual void OnEulaAccepted() = 0; |
19 }; | 21 }; |
20 | 22 |
21 EulaAcceptedNotifier(); | 23 explicit EulaAcceptedNotifier(PrefService* local_state); |
22 virtual ~EulaAcceptedNotifier(); | 24 virtual ~EulaAcceptedNotifier(); |
23 | 25 |
24 // Initializes this class with the given |observer|. Must be called before | 26 // Initializes this class with the given |observer|. Must be called before |
25 // the class is used. | 27 // the class is used. |
26 void Init(Observer* observer); | 28 void Init(Observer* observer); |
27 | 29 |
28 // Returns true if the EULA has been accepted. If the EULA has not yet been | 30 // Returns true if the EULA has been accepted. If the EULA has not yet been |
29 // accepted, begins monitoring the EULA state and will notify the observer | 31 // accepted, begins monitoring the EULA state and will notify the observer |
30 // once the EULA has been accepted. | 32 // once the EULA has been accepted. |
31 virtual bool IsEulaAccepted() = 0; | 33 virtual bool IsEulaAccepted(); |
32 | 34 |
33 // Factory method for this class. | 35 // Factory method for this class. |
34 static EulaAcceptedNotifier* Create(); | 36 static EulaAcceptedNotifier* Create(); |
35 | 37 |
36 protected: | 38 protected: |
37 // Notifies the observer that the EULA has been updated, to be called by | 39 // Notifies the observer that the EULA has been updated, made protected for |
38 // platform-specific subclasses. | 40 // testing. |
39 void NotifyObserver(); | 41 void NotifyObserver(); |
40 | 42 |
41 private: | 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 |
42 // Observer of the EULA accepted notification. | 53 // Observer of the EULA accepted notification. |
43 Observer* observer_; | 54 Observer* observer_; |
44 | 55 |
45 DISALLOW_COPY_AND_ASSIGN(EulaAcceptedNotifier); | 56 DISALLOW_COPY_AND_ASSIGN(EulaAcceptedNotifier); |
46 }; | 57 }; |
47 | 58 |
48 #endif // CHROME_BROWSER_METRICS_VARIATIONS_EULA_ACCEPTED_NOTIFIER_H_ | 59 #endif // CHROME_BROWSER_METRICS_VARIATIONS_EULA_ACCEPTED_NOTIFIER_H_ |
OLD | NEW |