OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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_POLICY_CLOUD_CLOUD_POLICY_CORE_H_ | |
6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CORE_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/observer_list.h" | |
14 #include "base/prefs/pref_member.h" | |
15 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | |
16 | |
17 class PrefService; | |
18 | |
19 namespace base { | |
20 class SequencedTaskRunner; | |
21 } | |
22 | |
23 namespace policy { | |
24 | |
25 class CloudPolicyClient; | |
26 class CloudPolicyRefreshScheduler; | |
27 class CloudPolicyService; | |
28 class CloudPolicyStore; | |
29 | |
30 // CloudPolicyCore glues together the ingredients that are essential for | |
31 // obtaining a fully-functional cloud policy system: CloudPolicyClient and | |
32 // CloudPolicyStore, which are responsible for fetching policy from the cloud | |
33 // and storing it locally, respectively, as well as a CloudPolicyService | |
34 // instance that moves data between the two former components, and | |
35 // CloudPolicyRefreshScheduler which triggers periodic refreshes. | |
36 class CloudPolicyCore { | |
37 public: | |
38 // Callbacks for policy core events. | |
39 class Observer { | |
40 public: | |
41 virtual ~Observer(); | |
42 | |
43 // Called after the core is connected. | |
44 virtual void OnCoreConnected(CloudPolicyCore* core) = 0; | |
45 | |
46 // Called after the refresh scheduler is started. | |
47 virtual void OnRefreshSchedulerStarted(CloudPolicyCore* core) = 0; | |
48 | |
49 // Called before the core is disconnected. | |
50 virtual void OnCoreDisconnecting(CloudPolicyCore* core) = 0; | |
51 }; | |
52 | |
53 // |task_runner| is the runner for policy refresh tasks. | |
54 CloudPolicyCore(const PolicyNamespaceKey& policy_ns_key, | |
55 CloudPolicyStore* store, | |
56 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | |
57 ~CloudPolicyCore(); | |
58 | |
59 CloudPolicyClient* client() { return client_.get(); } | |
60 const CloudPolicyClient* client() const { return client_.get(); } | |
61 | |
62 CloudPolicyStore* store() { return store_; } | |
63 const CloudPolicyStore* store() const { return store_; } | |
64 | |
65 CloudPolicyService* service() { return service_.get(); } | |
66 const CloudPolicyService* service() const { return service_.get(); } | |
67 | |
68 CloudPolicyRefreshScheduler* refresh_scheduler() { | |
69 return refresh_scheduler_.get(); | |
70 } | |
71 const CloudPolicyRefreshScheduler* refresh_scheduler() const { | |
72 return refresh_scheduler_.get(); | |
73 } | |
74 | |
75 // Initializes the cloud connection. | |
76 void Connect(scoped_ptr<CloudPolicyClient> client); | |
77 | |
78 // Shuts down the cloud connection. | |
79 void Disconnect(); | |
80 | |
81 // Requests a policy refresh to be performed soon. This may apply throttling, | |
82 // and the request may not be immediately sent. | |
83 void RefreshSoon(); | |
84 | |
85 // Starts a refresh scheduler in case none is running yet. | |
86 void StartRefreshScheduler(); | |
87 | |
88 // Watches the pref named |refresh_pref_name| in |pref_service| and adjusts | |
89 // |refresh_scheduler_|'s refresh delay accordingly. | |
90 void TrackRefreshDelayPref(PrefService* pref_service, | |
91 const std::string& refresh_pref_name); | |
92 | |
93 // Registers an observer to be notified of policy core events. | |
94 void AddObserver(Observer* observer); | |
95 | |
96 // Removes the specified observer. | |
97 void RemoveObserver(Observer* observer); | |
98 | |
99 private: | |
100 // Updates the refresh scheduler on refresh delay changes. | |
101 void UpdateRefreshDelayFromPref(); | |
102 | |
103 PolicyNamespaceKey policy_ns_key_; | |
104 CloudPolicyStore* store_; | |
105 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
106 scoped_ptr<CloudPolicyClient> client_; | |
107 scoped_ptr<CloudPolicyService> service_; | |
108 scoped_ptr<CloudPolicyRefreshScheduler> refresh_scheduler_; | |
109 scoped_ptr<IntegerPrefMember> refresh_delay_; | |
110 ObserverList<Observer, true> observers_; | |
111 | |
112 DISALLOW_COPY_AND_ASSIGN(CloudPolicyCore); | |
113 }; | |
114 | |
115 } // namespace policy | |
116 | |
117 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CORE_H_ | |
OLD | NEW |