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 30 matching lines...) Expand all Loading... |
41 virtual ~Observer(); | 41 virtual ~Observer(); |
42 | 42 |
43 // Called when a policy fetch completes successfully. If a policy fetch | 43 // Called when a policy fetch completes successfully. If a policy fetch |
44 // triggers an error, OnClientError() will fire. | 44 // triggers an error, OnClientError() will fire. |
45 virtual void OnPolicyFetched(CloudPolicyClient* client) = 0; | 45 virtual void OnPolicyFetched(CloudPolicyClient* client) = 0; |
46 | 46 |
47 // Called upon registration state changes. This callback is invoked for | 47 // Called upon registration state changes. This callback is invoked for |
48 // successful completion of registration and unregistration requests. | 48 // successful completion of registration and unregistration requests. |
49 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) = 0; | 49 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) = 0; |
50 | 50 |
| 51 // Called when a request for device robot OAuth2 authorization tokens |
| 52 // returns successfully. |
| 53 virtual void OnRobotAuthCodesFetched(CloudPolicyClient* client) = 0; |
| 54 |
51 // Indicates there's been an error in a previously-issued request. | 55 // Indicates there's been an error in a previously-issued request. |
52 virtual void OnClientError(CloudPolicyClient* client) = 0; | 56 virtual void OnClientError(CloudPolicyClient* client) = 0; |
53 }; | 57 }; |
54 | 58 |
55 // Delegate interface for supplying status information to upload to the server | 59 // Delegate interface for supplying status information to upload to the server |
56 // as part of the policy fetch request. | 60 // as part of the policy fetch request. |
57 class StatusProvider { | 61 class StatusProvider { |
58 public: | 62 public: |
59 virtual ~StatusProvider(); | 63 virtual ~StatusProvider(); |
60 | 64 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 99 |
96 // Requests a policy fetch. The client being registered is a prerequisite to | 100 // Requests a policy fetch. The client being registered is a prerequisite to |
97 // this operation and this call will CHECK if the client is not in registered | 101 // this operation and this call will CHECK if the client is not in registered |
98 // state. FetchPolicy() triggers a policy fetch from the cloud. A policy | 102 // state. FetchPolicy() triggers a policy fetch from the cloud. A policy |
99 // change notification is reported to the observers and the new policy blob | 103 // change notification is reported to the observers and the new policy blob |
100 // can be retrieved once the policy fetch operation completes. In case of | 104 // can be retrieved once the policy fetch operation completes. In case of |
101 // multiple requests to fetch policy, new requests will cancel any pending | 105 // multiple requests to fetch policy, new requests will cancel any pending |
102 // requests and the latest request will eventually trigger notifications. | 106 // requests and the latest request will eventually trigger notifications. |
103 virtual void FetchPolicy(); | 107 virtual void FetchPolicy(); |
104 | 108 |
| 109 // Requests OAuth2 auth tokens for the device robot account. The client being |
| 110 // registered is a prerequisite to this operation and this call will CHECK if |
| 111 // the client is not in registered state. |
| 112 virtual void FetchRobotAuthTokens(const std::string& auth_token); |
| 113 |
105 // Sends an unregistration request to the server. | 114 // Sends an unregistration request to the server. |
106 virtual void Unregister(); | 115 virtual void Unregister(); |
107 | 116 |
108 // Adds an observer to be called back upon policy and state changes. | 117 // Adds an observer to be called back upon policy and state changes. |
109 void AddObserver(Observer* observer); | 118 void AddObserver(Observer* observer); |
110 | 119 |
111 // Removes the specified observer. | 120 // Removes the specified observer. |
112 void RemoveObserver(Observer* observer); | 121 void RemoveObserver(Observer* observer); |
113 | 122 |
114 void set_submit_machine_id(bool submit_machine_id) { | 123 void set_submit_machine_id(bool submit_machine_id) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 161 |
153 // Returns the policy response for |policy_ns_key|, if found in |responses()|; | 162 // Returns the policy response for |policy_ns_key|, if found in |responses()|; |
154 // otherwise returns NULL. | 163 // otherwise returns NULL. |
155 const enterprise_management::PolicyFetchResponse* GetPolicyFor( | 164 const enterprise_management::PolicyFetchResponse* GetPolicyFor( |
156 const PolicyNamespaceKey& policy_ns_key) const; | 165 const PolicyNamespaceKey& policy_ns_key) const; |
157 | 166 |
158 DeviceManagementStatus status() const { | 167 DeviceManagementStatus status() const { |
159 return status_; | 168 return status_; |
160 } | 169 } |
161 | 170 |
| 171 const std::string& robot_api_auth_code() const { |
| 172 return robot_api_auth_code_; |
| 173 } |
| 174 |
162 protected: | 175 protected: |
163 // A set of PolicyNamespaceKeys to fetch. | 176 // A set of PolicyNamespaceKeys to fetch. |
164 typedef std::set<PolicyNamespaceKey> NamespaceSet; | 177 typedef std::set<PolicyNamespaceKey> NamespaceSet; |
165 | 178 |
166 // Callback for retries of registration requests. | 179 // Callback for retries of registration requests. |
167 void OnRetryRegister(DeviceManagementRequestJob* job); | 180 void OnRetryRegister(DeviceManagementRequestJob* job); |
168 | 181 |
169 // Callback for registration requests. | 182 // Callback for registration requests. |
170 void OnRegisterCompleted( | 183 void OnRegisterCompleted( |
171 DeviceManagementStatus status, | 184 DeviceManagementStatus status, |
172 const enterprise_management::DeviceManagementResponse& response); | 185 const enterprise_management::DeviceManagementResponse& response); |
173 | 186 |
174 // Callback for policy fetch requests. | 187 // Callback for policy fetch requests. |
175 void OnPolicyFetchCompleted( | 188 void OnPolicyFetchCompleted( |
176 DeviceManagementStatus status, | 189 DeviceManagementStatus status, |
177 const enterprise_management::DeviceManagementResponse& response); | 190 const enterprise_management::DeviceManagementResponse& response); |
178 | 191 |
| 192 // Callback for robot account api authorization requests. |
| 193 void OnFetchRobotAuthTokensCompleted( |
| 194 DeviceManagementStatus status, |
| 195 const enterprise_management::DeviceManagementResponse& response); |
| 196 |
179 // Callback for unregistration requests. | 197 // Callback for unregistration requests. |
180 void OnUnregisterCompleted( | 198 void OnUnregisterCompleted( |
181 DeviceManagementStatus status, | 199 DeviceManagementStatus status, |
182 const enterprise_management::DeviceManagementResponse& response); | 200 const enterprise_management::DeviceManagementResponse& response); |
183 | 201 |
184 // Observer notification helpers. | 202 // Observer notification helpers. |
185 void NotifyPolicyFetched(); | 203 void NotifyPolicyFetched(); |
186 void NotifyRegistrationStateChanged(); | 204 void NotifyRegistrationStateChanged(); |
| 205 void NotifyRobotAuthCodesFetched(); |
187 void NotifyClientError(); | 206 void NotifyClientError(); |
188 | 207 |
189 // Data necessary for constructing policy requests. | 208 // Data necessary for constructing policy requests. |
190 const std::string machine_id_; | 209 const std::string machine_id_; |
191 const std::string machine_model_; | 210 const std::string machine_model_; |
192 const UserAffiliation user_affiliation_; | 211 const UserAffiliation user_affiliation_; |
193 NamespaceSet namespaces_to_fetch_; | 212 NamespaceSet namespaces_to_fetch_; |
194 | 213 |
195 std::string dm_token_; | 214 std::string dm_token_; |
196 DeviceMode device_mode_; | 215 DeviceMode device_mode_; |
197 std::string client_id_; | 216 std::string client_id_; |
198 bool submit_machine_id_; | 217 bool submit_machine_id_; |
199 base::Time last_policy_timestamp_; | 218 base::Time last_policy_timestamp_; |
200 int public_key_version_; | 219 int public_key_version_; |
201 bool public_key_version_valid_; | 220 bool public_key_version_valid_; |
| 221 std::string robot_api_auth_code_; |
202 | 222 |
203 // Used for issuing requests to the cloud. | 223 // Used for issuing requests to the cloud. |
204 DeviceManagementService* service_; | 224 DeviceManagementService* service_; |
205 scoped_ptr<DeviceManagementRequestJob> request_job_; | 225 scoped_ptr<DeviceManagementRequestJob> request_job_; |
206 | 226 |
207 // Status upload data is produced by |status_provider_|. | 227 // Status upload data is produced by |status_provider_|. |
208 StatusProvider* status_provider_; | 228 StatusProvider* status_provider_; |
209 | 229 |
210 // The policy responses returned by the last policy fetch operation. | 230 // The policy responses returned by the last policy fetch operation. |
211 ResponseMap responses_; | 231 ResponseMap responses_; |
212 DeviceManagementStatus status_; | 232 DeviceManagementStatus status_; |
213 | 233 |
214 ObserverList<Observer, true> observers_; | 234 ObserverList<Observer, true> observers_; |
215 | 235 |
216 private: | 236 private: |
217 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient); | 237 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient); |
218 }; | 238 }; |
219 | 239 |
220 } // namespace policy | 240 } // namespace policy |
221 | 241 |
222 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CLIENT_H_ | 242 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CLIENT_H_ |
OLD | NEW |