OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_POLICY_CLOUD_CLOUD_POLICY_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CLIENT_H_ |
6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CLIENT_H_ | 6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CLIENT_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 virtual ~Observer(); | 46 virtual ~Observer(); |
47 | 47 |
48 // Called when a policy fetch completes successfully. If a policy fetch | 48 // Called when a policy fetch completes successfully. If a policy fetch |
49 // triggers an error, OnClientError() will fire. | 49 // triggers an error, OnClientError() will fire. |
50 virtual void OnPolicyFetched(CloudPolicyClient* client) = 0; | 50 virtual void OnPolicyFetched(CloudPolicyClient* client) = 0; |
51 | 51 |
52 // Called upon registration state changes. This callback is invoked for | 52 // Called upon registration state changes. This callback is invoked for |
53 // successful completion of registration and unregistration requests. | 53 // successful completion of registration and unregistration requests. |
54 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) = 0; | 54 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) = 0; |
55 | 55 |
| 56 // Called when a request for device robot OAuth2 authorization tokens |
| 57 // returns successfully. Only occurs during enrollment. Optional |
| 58 // (default implementation is a noop). |
| 59 virtual void OnRobotAuthCodesFetched(CloudPolicyClient* client); |
| 60 |
56 // Indicates there's been an error in a previously-issued request. | 61 // Indicates there's been an error in a previously-issued request. |
57 virtual void OnClientError(CloudPolicyClient* client) = 0; | 62 virtual void OnClientError(CloudPolicyClient* client) = 0; |
58 }; | 63 }; |
59 | 64 |
60 // Delegate interface for supplying status information to upload to the server | 65 // Delegate interface for supplying status information to upload to the server |
61 // as part of the policy fetch request. | 66 // as part of the policy fetch request. |
62 class StatusProvider { | 67 class StatusProvider { |
63 public: | 68 public: |
64 virtual ~StatusProvider(); | 69 virtual ~StatusProvider(); |
65 | 70 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 105 |
101 // Requests a policy fetch. The client being registered is a prerequisite to | 106 // Requests a policy fetch. The client being registered is a prerequisite to |
102 // this operation and this call will CHECK if the client is not in registered | 107 // this operation and this call will CHECK if the client is not in registered |
103 // state. FetchPolicy() triggers a policy fetch from the cloud. A policy | 108 // state. FetchPolicy() triggers a policy fetch from the cloud. A policy |
104 // change notification is reported to the observers and the new policy blob | 109 // change notification is reported to the observers and the new policy blob |
105 // can be retrieved once the policy fetch operation completes. In case of | 110 // can be retrieved once the policy fetch operation completes. In case of |
106 // multiple requests to fetch policy, new requests will cancel any pending | 111 // multiple requests to fetch policy, new requests will cancel any pending |
107 // requests and the latest request will eventually trigger notifications. | 112 // requests and the latest request will eventually trigger notifications. |
108 virtual void FetchPolicy(); | 113 virtual void FetchPolicy(); |
109 | 114 |
| 115 // Requests OAuth2 auth codes for the device robot account. The client being |
| 116 // registered is a prerequisite to this operation and this call will CHECK if |
| 117 // the client is not in registered state. |
| 118 virtual void FetchRobotAuthCodes(const std::string& auth_token); |
| 119 |
110 // Sends an unregistration request to the server. | 120 // Sends an unregistration request to the server. |
111 virtual void Unregister(); | 121 virtual void Unregister(); |
112 | 122 |
113 // Upload a device certificate to the server. Like FetchPolicy, this method | 123 // Upload a device certificate to the server. Like FetchPolicy, this method |
114 // requires that the client is in a registered state. |certificate_data| must | 124 // requires that the client is in a registered state. |certificate_data| must |
115 // hold the X.509 certificate data to be sent to the server. The |callback| | 125 // hold the X.509 certificate data to be sent to the server. The |callback| |
116 // will be called when the operation completes. | 126 // will be called when the operation completes. |
117 virtual void UploadCertificate(const std::string& certificate_data, | 127 virtual void UploadCertificate(const std::string& certificate_data, |
118 const StatusCallback& callback); | 128 const StatusCallback& callback); |
119 | 129 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 174 |
165 // Returns the policy response for |policy_ns_key|, if found in |responses()|; | 175 // Returns the policy response for |policy_ns_key|, if found in |responses()|; |
166 // otherwise returns NULL. | 176 // otherwise returns NULL. |
167 const enterprise_management::PolicyFetchResponse* GetPolicyFor( | 177 const enterprise_management::PolicyFetchResponse* GetPolicyFor( |
168 const PolicyNamespaceKey& policy_ns_key) const; | 178 const PolicyNamespaceKey& policy_ns_key) const; |
169 | 179 |
170 DeviceManagementStatus status() const { | 180 DeviceManagementStatus status() const { |
171 return status_; | 181 return status_; |
172 } | 182 } |
173 | 183 |
| 184 const std::string& robot_api_auth_code() const { |
| 185 return robot_api_auth_code_; |
| 186 } |
| 187 |
174 protected: | 188 protected: |
175 // A set of PolicyNamespaceKeys to fetch. | 189 // A set of PolicyNamespaceKeys to fetch. |
176 typedef std::set<PolicyNamespaceKey> NamespaceSet; | 190 typedef std::set<PolicyNamespaceKey> NamespaceSet; |
177 | 191 |
178 // Callback for retries of registration requests. | 192 // Callback for retries of registration requests. |
179 void OnRetryRegister(DeviceManagementRequestJob* job); | 193 void OnRetryRegister(DeviceManagementRequestJob* job); |
180 | 194 |
181 // Callback for registration requests. | 195 // Callback for registration requests. |
182 void OnRegisterCompleted( | 196 void OnRegisterCompleted( |
183 DeviceManagementStatus status, | 197 DeviceManagementStatus status, |
184 const enterprise_management::DeviceManagementResponse& response); | 198 const enterprise_management::DeviceManagementResponse& response); |
185 | 199 |
186 // Callback for policy fetch requests. | 200 // Callback for policy fetch requests. |
187 void OnPolicyFetchCompleted( | 201 void OnPolicyFetchCompleted( |
188 DeviceManagementStatus status, | 202 DeviceManagementStatus status, |
189 const enterprise_management::DeviceManagementResponse& response); | 203 const enterprise_management::DeviceManagementResponse& response); |
190 | 204 |
| 205 // Callback for robot account api authorization requests. |
| 206 void OnFetchRobotAuthCodesCompleted( |
| 207 DeviceManagementStatus status, |
| 208 const enterprise_management::DeviceManagementResponse& response); |
| 209 |
191 // Callback for unregistration requests. | 210 // Callback for unregistration requests. |
192 void OnUnregisterCompleted( | 211 void OnUnregisterCompleted( |
193 DeviceManagementStatus status, | 212 DeviceManagementStatus status, |
194 const enterprise_management::DeviceManagementResponse& response); | 213 const enterprise_management::DeviceManagementResponse& response); |
195 | 214 |
196 // Callback for certificate upload requests. | 215 // Callback for certificate upload requests. |
197 void OnCertificateUploadCompleted( | 216 void OnCertificateUploadCompleted( |
198 const StatusCallback& callback, | 217 const StatusCallback& callback, |
199 DeviceManagementStatus status, | 218 DeviceManagementStatus status, |
200 const enterprise_management::DeviceManagementResponse& response); | 219 const enterprise_management::DeviceManagementResponse& response); |
201 | 220 |
202 // Observer notification helpers. | 221 // Observer notification helpers. |
203 void NotifyPolicyFetched(); | 222 void NotifyPolicyFetched(); |
204 void NotifyRegistrationStateChanged(); | 223 void NotifyRegistrationStateChanged(); |
| 224 void NotifyRobotAuthCodesFetched(); |
205 void NotifyClientError(); | 225 void NotifyClientError(); |
206 | 226 |
207 // Data necessary for constructing policy requests. | 227 // Data necessary for constructing policy requests. |
208 const std::string machine_id_; | 228 const std::string machine_id_; |
209 const std::string machine_model_; | 229 const std::string machine_model_; |
210 const UserAffiliation user_affiliation_; | 230 const UserAffiliation user_affiliation_; |
211 NamespaceSet namespaces_to_fetch_; | 231 NamespaceSet namespaces_to_fetch_; |
212 | 232 |
213 std::string dm_token_; | 233 std::string dm_token_; |
214 DeviceMode device_mode_; | 234 DeviceMode device_mode_; |
215 std::string client_id_; | 235 std::string client_id_; |
216 bool submit_machine_id_; | 236 bool submit_machine_id_; |
217 base::Time last_policy_timestamp_; | 237 base::Time last_policy_timestamp_; |
218 int public_key_version_; | 238 int public_key_version_; |
219 bool public_key_version_valid_; | 239 bool public_key_version_valid_; |
| 240 std::string robot_api_auth_code_; |
220 | 241 |
221 // Used for issuing requests to the cloud. | 242 // Used for issuing requests to the cloud. |
222 DeviceManagementService* service_; | 243 DeviceManagementService* service_; |
223 scoped_ptr<DeviceManagementRequestJob> request_job_; | 244 scoped_ptr<DeviceManagementRequestJob> request_job_; |
224 | 245 |
225 // Status upload data is produced by |status_provider_|. | 246 // Status upload data is produced by |status_provider_|. |
226 StatusProvider* status_provider_; | 247 StatusProvider* status_provider_; |
227 | 248 |
228 // The policy responses returned by the last policy fetch operation. | 249 // The policy responses returned by the last policy fetch operation. |
229 ResponseMap responses_; | 250 ResponseMap responses_; |
230 DeviceManagementStatus status_; | 251 DeviceManagementStatus status_; |
231 | 252 |
232 ObserverList<Observer, true> observers_; | 253 ObserverList<Observer, true> observers_; |
233 | 254 |
234 private: | 255 private: |
235 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient); | 256 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient); |
236 }; | 257 }; |
237 | 258 |
238 } // namespace policy | 259 } // namespace policy |
239 | 260 |
240 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CLIENT_H_ | 261 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CLIENT_H_ |
OLD | NEW |