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_POLICY_SUBSYSTEM_H_ | |
6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_SUBSYSTEM_H_ | |
7 | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/prefs/public/pref_change_registrar.h" | |
10 #include "net/base/network_change_notifier.h" | |
11 | |
12 class PrefServiceSimple; | |
13 | |
14 namespace policy { | |
15 | |
16 class CloudPolicyCacheBase; | |
17 class CloudPolicyController; | |
18 class CloudPolicyDataStore; | |
19 class DeviceManagementService; | |
20 class DeviceTokenFetcher; | |
21 class PolicyNotifier; | |
22 | |
23 // This class is a container for the infrastructure required to support cloud | |
24 // policy. It glues together the backend, the policy controller and manages the | |
25 // life cycle of the policy providers. | |
26 class CloudPolicySubsystem | |
27 : public net::NetworkChangeNotifier::IPAddressObserver { | |
28 public: | |
29 enum PolicySubsystemState { | |
30 UNENROLLED, // No enrollment attempt has been performed yet. | |
31 BAD_GAIA_TOKEN, // The server rejected the GAIA auth token. | |
32 UNMANAGED, // This device is unmanaged. | |
33 NETWORK_ERROR, // A network error occurred, retrying makes sense. | |
34 LOCAL_ERROR, // Retrying is futile. | |
35 TOKEN_FETCHED, // Device has been successfully registered. | |
36 SUCCESS // Policy has been fetched successfully and is in effect. | |
37 }; | |
38 | |
39 enum ErrorDetails { | |
40 NO_DETAILS, // No error, so no error details either. | |
41 DMTOKEN_NETWORK_ERROR, // DeviceTokenFetcher encountered a network error. | |
42 POLICY_NETWORK_ERROR, // CloudPolicyController encountered a network error. | |
43 BAD_DMTOKEN, // The server rejected the DMToken. | |
44 POLICY_LOCAL_ERROR, // The policy cache encountered a local error. | |
45 SIGNATURE_MISMATCH, // The policy cache detected a signature mismatch. | |
46 BAD_SERIAL_NUMBER, // The serial number of the device is not valid. | |
47 AUTO_ENROLLMENT_ERROR, // Auto-enrollment is not supported. | |
48 BAD_ENROLLMENT_MODE, // The enrollment mode was not recognized. | |
49 MISSING_LICENSES, // There are no valid licenses for this domain left. | |
50 }; | |
51 | |
52 class Observer { | |
53 public: | |
54 virtual ~Observer() {} | |
55 virtual void OnPolicyStateChanged(PolicySubsystemState state, | |
56 ErrorDetails error_details) = 0; | |
57 }; | |
58 | |
59 class ObserverRegistrar { | |
60 public: | |
61 ObserverRegistrar(CloudPolicySubsystem* cloud_policy_subsystem, | |
62 CloudPolicySubsystem::Observer* observer); | |
63 ~ObserverRegistrar(); | |
64 | |
65 private: | |
66 PolicyNotifier* policy_notifier_; | |
67 CloudPolicySubsystem::Observer* observer_; | |
68 DISALLOW_COPY_AND_ASSIGN(ObserverRegistrar); | |
69 }; | |
70 | |
71 CloudPolicySubsystem(CloudPolicyDataStore* data_store, | |
72 CloudPolicyCacheBase* policy_cache, | |
73 const std::string& device_management_url); | |
74 virtual ~CloudPolicySubsystem(); | |
75 | |
76 // Initializes the subsystem. The first network request will only be made | |
77 // after |delay_milliseconds|. It can be scheduled to be happen earlier by | |
78 // calling |ScheduleInitialization|. | |
79 void CompleteInitialization(const char* refresh_pref_name, | |
80 int64 delay_milliseconds); | |
81 | |
82 // Shuts the subsystem down. This must be called before threading and network | |
83 // infrastructure goes away. | |
84 void Shutdown(); | |
85 | |
86 // Returns the externally visible state and corresponding error details. | |
87 PolicySubsystemState state(); | |
88 ErrorDetails error_details(); | |
89 | |
90 // Resets the subsystem back to unenrolled state and cancels any pending | |
91 // retry operations. | |
92 void Reset(); | |
93 | |
94 // Refreshes the policies retrieved by this subsystem. This triggers new | |
95 // policy fetches if possible, otherwise it keeps the current set of policies. | |
96 // If |wait_for_auth_token| is true, then this call will make the policy | |
97 // refresh wait for a pending auth token fetch, in case it hasn't finished | |
98 // yet. Otherwise the refresh completes immediately if the auth token isn't | |
99 // available. | |
100 void RefreshPolicies(bool wait_for_auth_token); | |
101 | |
102 // Registers cloud policy related prefs. | |
103 static void RegisterPrefs(PrefServiceSimple* pref_service); | |
104 | |
105 // Schedule initialization of the policy backend service. | |
106 void ScheduleServiceInitialization(int64 delay_milliseconds); | |
107 | |
108 // Returns the CloudPolicyCacheBase associated with this CloudPolicySubsystem. | |
109 CloudPolicyCacheBase* GetCloudPolicyCacheBase() const; | |
110 | |
111 CloudPolicyDataStore* data_store() { return data_store_; } | |
112 | |
113 private: | |
114 friend class TestingCloudPolicySubsystem; | |
115 | |
116 CloudPolicySubsystem(); | |
117 | |
118 void Initialize(CloudPolicyDataStore* data_store, | |
119 CloudPolicyCacheBase* policy_cache, | |
120 const std::string& device_management_url); | |
121 | |
122 // Updates the policy controller with a new refresh rate value. | |
123 void UpdatePolicyRefreshRate(int64 refresh_rate); | |
124 | |
125 // Returns a weak pointer to this subsystem's PolicyNotifier. | |
126 PolicyNotifier* notifier() { | |
127 return notifier_.get(); | |
128 } | |
129 | |
130 // Factory methods that may be overridden in tests. | |
131 virtual void CreateDeviceTokenFetcher(); | |
132 virtual void CreateCloudPolicyController(); | |
133 | |
134 void OnRefreshPrefChanged(); | |
135 | |
136 // net::NetworkChangeNotifier::IPAddressObserver: | |
137 virtual void OnIPAddressChanged() OVERRIDE; | |
138 | |
139 // Name of the preference to read the refresh rate from. | |
140 const char* refresh_pref_name_; | |
141 | |
142 PrefChangeRegistrar pref_change_registrar_; | |
143 | |
144 CloudPolicyDataStore* data_store_; | |
145 | |
146 // Cloud policy infrastructure stuff. | |
147 scoped_ptr<PolicyNotifier> notifier_; | |
148 scoped_ptr<DeviceManagementService> device_management_service_; | |
149 scoped_ptr<DeviceTokenFetcher> device_token_fetcher_; | |
150 scoped_ptr<CloudPolicyCacheBase> cloud_policy_cache_; | |
151 scoped_ptr<CloudPolicyController> cloud_policy_controller_; | |
152 | |
153 std::string device_management_url_; | |
154 | |
155 DISALLOW_COPY_AND_ASSIGN(CloudPolicySubsystem); | |
156 }; | |
157 | |
158 } // namespace policy | |
159 | |
160 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_SUBSYSTEM_H_ | |
OLD | NEW |