[email protected] | 1aabf59 | 2013-06-07 08:53:01 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 05d242d | 2013-04-08 21:49:49 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
droger | f847994 | 2014-11-21 17:47:53 | [diff] [blame] | 5 | #ifndef COMPONENTS_WEB_RESOURCE_EULA_ACCEPTED_NOTIFIER_H_ |
6 | #define COMPONENTS_WEB_RESOURCE_EULA_ACCEPTED_NOTIFIER_H_ | ||||
[email protected] | 05d242d | 2013-04-08 21:49:49 | [diff] [blame] | 7 | |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 8 | #include "base/macros.h" |
brettw | f00b9b4 | 2016-02-01 22:11:38 | [diff] [blame] | 9 | #include "components/prefs/pref_change_registrar.h" |
[email protected] | 05d242d | 2013-04-08 21:49:49 | [diff] [blame] | 10 | |
[email protected] | 80373b6 | 2013-06-04 20:37:06 | [diff] [blame] | 11 | class PrefService; |
12 | |||||
droger | c4ccb83 | 2014-11-27 16:10:49 | [diff] [blame] | 13 | namespace web_resource { |
14 | |||||
[email protected] | 80373b6 | 2013-06-04 20:37:06 | [diff] [blame] | 15 | // Helper class for querying the EULA accepted state and receiving a |
16 | // notification when the EULA is accepted. | ||||
[email protected] | 05d242d | 2013-04-08 21:49:49 | [diff] [blame] | 17 | class EulaAcceptedNotifier { |
18 | public: | ||||
19 | // Observes EULA accepted state changes. | ||||
20 | class Observer { | ||||
21 | public: | ||||
Sky Malice | effb908 | 2018-07-18 15:44:44 | [diff] [blame] | 22 | virtual ~Observer() {} |
[email protected] | 05d242d | 2013-04-08 21:49:49 | [diff] [blame] | 23 | virtual void OnEulaAccepted() = 0; |
24 | }; | ||||
25 | |||||
[email protected] | 80373b6 | 2013-06-04 20:37:06 | [diff] [blame] | 26 | explicit EulaAcceptedNotifier(PrefService* local_state); |
[email protected] | 05d242d | 2013-04-08 21:49:49 | [diff] [blame] | 27 | virtual ~EulaAcceptedNotifier(); |
28 | |||||
29 | // Initializes this class with the given |observer|. Must be called before | ||||
30 | // the class is used. | ||||
31 | void Init(Observer* observer); | ||||
32 | |||||
33 | // Returns true if the EULA has been accepted. If the EULA has not yet been | ||||
34 | // accepted, begins monitoring the EULA state and will notify the observer | ||||
35 | // once the EULA has been accepted. | ||||
[email protected] | 80373b6 | 2013-06-04 20:37:06 | [diff] [blame] | 36 | virtual bool IsEulaAccepted(); |
[email protected] | 05d242d | 2013-04-08 21:49:49 | [diff] [blame] | 37 | |
38 | // Factory method for this class. | ||||
droger | f445548 | 2014-11-21 09:50:18 | [diff] [blame] | 39 | static EulaAcceptedNotifier* Create(PrefService* local_state); |
[email protected] | 05d242d | 2013-04-08 21:49:49 | [diff] [blame] | 40 | |
41 | protected: | ||||
[email protected] | 80373b6 | 2013-06-04 20:37:06 | [diff] [blame] | 42 | // Notifies the observer that the EULA has been updated, made protected for |
43 | // testing. | ||||
[email protected] | 05d242d | 2013-04-08 21:49:49 | [diff] [blame] | 44 | void NotifyObserver(); |
45 | |||||
46 | private: | ||||
[email protected] | 80373b6 | 2013-06-04 20:37:06 | [diff] [blame] | 47 | // Callback for EULA accepted pref change notification. |
48 | void OnPrefChanged(); | ||||
49 | |||||
50 | // Local state pref service for querying the EULA accepted pref. | ||||
51 | PrefService* local_state_; | ||||
52 | |||||
53 | // Used to listen for the EULA accepted pref change notification. | ||||
54 | PrefChangeRegistrar registrar_; | ||||
55 | |||||
[email protected] | 05d242d | 2013-04-08 21:49:49 | [diff] [blame] | 56 | // Observer of the EULA accepted notification. |
57 | Observer* observer_; | ||||
58 | |||||
59 | DISALLOW_COPY_AND_ASSIGN(EulaAcceptedNotifier); | ||||
60 | }; | ||||
61 | |||||
droger | c4ccb83 | 2014-11-27 16:10:49 | [diff] [blame] | 62 | } // namespace web_resource |
63 | |||||
droger | f847994 | 2014-11-21 17:47:53 | [diff] [blame] | 64 | #endif // COMPONENTS_WEB_RESOURCE_EULA_ACCEPTED_NOTIFIER_H_ |