Chromium Code Reviews| 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 COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ | 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ |
| 6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ | 6 #define COMPONENTS_POLICY_CORE_COMMON_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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
| 18 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 20 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 21 #include "components/policy/core/common/remote_commands/remote_command_job.h" | |
| 21 #include "components/policy/policy_export.h" | 22 #include "components/policy/policy_export.h" |
| 22 #include "policy/proto/device_management_backend.pb.h" | 23 #include "policy/proto/device_management_backend.pb.h" |
| 23 | 24 |
| 24 namespace net { | 25 namespace net { |
| 25 class URLRequestContextGetter; | 26 class URLRequestContextGetter; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace policy { | 29 namespace policy { |
| 29 | 30 |
| 30 class DeviceManagementRequestJob; | 31 class DeviceManagementRequestJob; |
| 31 class DeviceManagementService; | 32 class DeviceManagementService; |
| 32 | 33 |
| 33 // Implements the core logic required to talk to the device management service. | 34 // Implements the core logic required to talk to the device management service. |
| 34 // Also keeps track of the current state of the association with the service, | 35 // Also keeps track of the current state of the association with the service, |
| 35 // such as whether there is a valid registration (DMToken is present in that | 36 // such as whether there is a valid registration (DMToken is present in that |
| 36 // case) and whether and what errors occurred in the latest request. | 37 // case) and whether and what errors occurred in the latest request. |
| 37 // | 38 // |
| 38 // Note that CloudPolicyClient doesn't do any validation of policy responses | 39 // Note that CloudPolicyClient doesn't do any validation of policy responses |
| 39 // such as signature and time stamp checks. These happen once the policy gets | 40 // such as signature and time stamp checks. These happen once the policy gets |
| 40 // installed in the cloud policy cache. | 41 // installed in the cloud policy cache. |
| 41 class POLICY_EXPORT CloudPolicyClient { | 42 class POLICY_EXPORT CloudPolicyClient { |
| 42 public: | 43 public: |
| 43 // Maps a (policy type, settings entity ID) pair to its corresponding | 44 // Maps a (policy type, settings entity ID) pair to its corresponding |
| 44 // PolicyFetchResponse. | 45 // PolicyFetchResponse. |
| 45 typedef std::map<std::pair<std::string, std::string>, | 46 using ResponseMap = std::map<std::pair<std::string, std::string>, |
| 46 enterprise_management::PolicyFetchResponse*> ResponseMap; | 47 enterprise_management::PolicyFetchResponse*>; |
| 47 | 48 |
| 48 // A callback which receives boolean status of an operation. If the operation | 49 // A callback which receives boolean status of an operation. If the operation |
| 49 // succeeded, |status| is true. | 50 // succeeded, |status| is true. |
| 50 typedef base::Callback<void(bool status)> StatusCallback; | 51 using StatusCallback = base::Callback<void(bool status)>; |
| 52 | |
| 53 // A callback to send fetched remote commands back. | |
|
bartfab (slow)
2015/02/28 00:01:22
Nit: It sounds like the callback will send the com
binjin
2015/02/28 02:18:04
Done.
| |
| 54 using RemoteCommandCallback = base::Callback<void( | |
| 55 const std::vector<enterprise_management::RemoteCommand>&)>; | |
| 51 | 56 |
| 52 // Observer interface for state and policy changes. | 57 // Observer interface for state and policy changes. |
| 53 class POLICY_EXPORT Observer { | 58 class POLICY_EXPORT Observer { |
| 54 public: | 59 public: |
| 55 virtual ~Observer(); | 60 virtual ~Observer(); |
| 56 | 61 |
| 57 // Called when a policy fetch completes successfully. If a policy fetch | 62 // Called when a policy fetch completes successfully. If a policy fetch |
| 58 // triggers an error, OnClientError() will fire. | 63 // triggers an error, OnClientError() will fire. |
| 59 virtual void OnPolicyFetched(CloudPolicyClient* client) = 0; | 64 virtual void OnPolicyFetched(CloudPolicyClient* client) = 0; |
| 60 | 65 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 | 136 |
| 132 // Uploads device/session status to the server. As above, the client must be | 137 // Uploads device/session status to the server. As above, the client must be |
| 133 // in a registered state. If non-null, |device_status| and |session_status| | 138 // in a registered state. If non-null, |device_status| and |session_status| |
| 134 // will be included in the upload status request. The |callback| will be | 139 // will be included in the upload status request. The |callback| will be |
| 135 // called when the operation completes. | 140 // called when the operation completes. |
| 136 virtual void UploadDeviceStatus( | 141 virtual void UploadDeviceStatus( |
| 137 const enterprise_management::DeviceStatusReportRequest* device_status, | 142 const enterprise_management::DeviceStatusReportRequest* device_status, |
| 138 const enterprise_management::SessionStatusReportRequest* session_status, | 143 const enterprise_management::SessionStatusReportRequest* session_status, |
| 139 const StatusCallback& callback); | 144 const StatusCallback& callback); |
| 140 | 145 |
| 146 // Attempts to fetch remote commands, with |last_command_id| being the last | |
| 147 // recorded command id and |command_results| being results for previous | |
|
bartfab (slow)
2015/02/28 00:01:22
Nit: s/id/ID/
binjin
2015/02/28 02:18:04
Done.
| |
| 148 // commands which have not been reported yet. The |callback| will be called | |
| 149 // when the operation completes. | |
| 150 virtual void FetchRemoteCommands( | |
| 151 RemoteCommandJob::UniqueIDType last_command_id, | |
|
bartfab (slow)
2015/02/28 00:01:22
Nit: During the first fetch, there is no |last_com
binjin
2015/03/09 16:31:56
Done. Used negative numbers to indicate invalid co
| |
| 152 const std::vector<enterprise_management::RemoteCommandResult>& | |
| 153 command_results, | |
| 154 const RemoteCommandCallback& callback); | |
| 155 | |
| 141 // Adds an observer to be called back upon policy and state changes. | 156 // Adds an observer to be called back upon policy and state changes. |
| 142 void AddObserver(Observer* observer); | 157 void AddObserver(Observer* observer); |
| 143 | 158 |
| 144 // Removes the specified observer. | 159 // Removes the specified observer. |
| 145 void RemoveObserver(Observer* observer); | 160 void RemoveObserver(Observer* observer); |
| 146 | 161 |
| 147 void set_submit_machine_id(bool submit_machine_id) { | 162 void set_submit_machine_id(bool submit_machine_id) { |
| 148 submit_machine_id_ = submit_machine_id; | 163 submit_machine_id_ = submit_machine_id; |
| 149 } | 164 } |
| 150 | 165 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 const enterprise_management::DeviceManagementResponse& response); | 275 const enterprise_management::DeviceManagementResponse& response); |
| 261 | 276 |
| 262 // Callback for status upload requests. | 277 // Callback for status upload requests. |
| 263 void OnStatusUploadCompleted( | 278 void OnStatusUploadCompleted( |
| 264 const DeviceManagementRequestJob* job, | 279 const DeviceManagementRequestJob* job, |
| 265 const StatusCallback& callback, | 280 const StatusCallback& callback, |
| 266 DeviceManagementStatus status, | 281 DeviceManagementStatus status, |
| 267 int net_error, | 282 int net_error, |
| 268 const enterprise_management::DeviceManagementResponse& response); | 283 const enterprise_management::DeviceManagementResponse& response); |
| 269 | 284 |
| 285 // Callback for remote commands fetch requests. | |
|
bartfab (slow)
2015/02/28 00:01:22
Nit: s/commands/command/
binjin
2015/02/28 02:18:04
Done.
| |
| 286 void OnRemoteCommandsFetched( | |
| 287 const DeviceManagementRequestJob* job, | |
| 288 const RemoteCommandCallback& callback, | |
| 289 DeviceManagementStatus status, | |
| 290 int net_error, | |
| 291 const enterprise_management::DeviceManagementResponse& response); | |
| 292 | |
| 270 // Helper to remove a job from request_jobs_. | 293 // Helper to remove a job from request_jobs_. |
| 271 void RemoveJob(const DeviceManagementRequestJob* job); | 294 void RemoveJob(const DeviceManagementRequestJob* job); |
| 272 | 295 |
| 273 // Observer notification helpers. | 296 // Observer notification helpers. |
| 274 void NotifyPolicyFetched(); | 297 void NotifyPolicyFetched(); |
| 275 void NotifyRegistrationStateChanged(); | 298 void NotifyRegistrationStateChanged(); |
| 276 void NotifyRobotAuthCodesFetched(); | 299 void NotifyRobotAuthCodesFetched(); |
| 277 void NotifyClientError(); | 300 void NotifyClientError(); |
| 278 | 301 |
| 279 // Data necessary for constructing policy requests. | 302 // Data necessary for constructing policy requests. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 ObserverList<Observer, true> observers_; | 341 ObserverList<Observer, true> observers_; |
| 319 scoped_refptr<net::URLRequestContextGetter> request_context_; | 342 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 320 | 343 |
| 321 private: | 344 private: |
| 322 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient); | 345 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient); |
| 323 }; | 346 }; |
| 324 | 347 |
| 325 } // namespace policy | 348 } // namespace policy |
| 326 | 349 |
| 327 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ | 350 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ |
| OLD | NEW |