Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: components/policy/core/common/cloud/cloud_policy_client.h

Issue 879233003: Initial RemoteCommandService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remote-commands
Patch Set: addressed #25 Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 which receives fetched remote commands.
54 using RemoteCommandCallback = base::Callback<void(
55 DeviceManagementStatus,
56 const std::vector<enterprise_management::RemoteCommand>&)>;
51 57
52 // Observer interface for state and policy changes. 58 // Observer interface for state and policy changes.
53 class POLICY_EXPORT Observer { 59 class POLICY_EXPORT Observer {
54 public: 60 public:
55 virtual ~Observer(); 61 virtual ~Observer();
56 62
57 // Called when a policy fetch completes successfully. If a policy fetch 63 // Called when a policy fetch completes successfully. If a policy fetch
58 // triggers an error, OnClientError() will fire. 64 // triggers an error, OnClientError() will fire.
59 virtual void OnPolicyFetched(CloudPolicyClient* client) = 0; 65 virtual void OnPolicyFetched(CloudPolicyClient* client) = 0;
60 66
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 137
132 // Uploads device/session status to the server. As above, the client must be 138 // 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| 139 // 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 140 // will be included in the upload status request. The |callback| will be
135 // called when the operation completes. 141 // called when the operation completes.
136 virtual void UploadDeviceStatus( 142 virtual void UploadDeviceStatus(
137 const enterprise_management::DeviceStatusReportRequest* device_status, 143 const enterprise_management::DeviceStatusReportRequest* device_status,
138 const enterprise_management::SessionStatusReportRequest* session_status, 144 const enterprise_management::SessionStatusReportRequest* session_status,
139 const StatusCallback& callback); 145 const StatusCallback& callback);
140 146
147 // Attempts to fetch remote commands, with |last_command_id| being the last
bartfab (slow) 2015/03/12 14:00:55 What does "recorded" mean here? IIUC, you mean com
binjin 2015/03/12 17:58:57 Done.
148 // recorded command ID and |command_results| being results for previous
149 // commands which have not been reported yet. The |callback| will be called
150 // when the operation completes. A negative last command ID indicates that
bartfab (slow) 2015/03/12 14:00:55 Nit: Remove the comment about negative command IDs
binjin 2015/03/12 17:58:57 Done.
151 // no command was recorded.
152 // Note that sending |last_command_id| will also acknowledge this command,
bartfab (slow) 2015/03/12 14:00:55 Nit 1: s/also // Nit 2: s/, and it can be set to n
binjin 2015/03/12 17:58:57 Done.
153 // and it can be set to null indicating that there are no recorded command.
154 virtual void FetchRemoteCommands(
155 scoped_ptr<RemoteCommandJob::UniqueIDType> last_command_id,
156 const std::vector<enterprise_management::RemoteCommandResult>&
157 command_results,
158 const RemoteCommandCallback& callback);
159
141 // Adds an observer to be called back upon policy and state changes. 160 // Adds an observer to be called back upon policy and state changes.
142 void AddObserver(Observer* observer); 161 void AddObserver(Observer* observer);
143 162
144 // Removes the specified observer. 163 // Removes the specified observer.
145 void RemoveObserver(Observer* observer); 164 void RemoveObserver(Observer* observer);
146 165
147 void set_submit_machine_id(bool submit_machine_id) { 166 void set_submit_machine_id(bool submit_machine_id) {
148 submit_machine_id_ = submit_machine_id; 167 submit_machine_id_ = submit_machine_id;
149 } 168 }
150 169
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 const enterprise_management::DeviceManagementResponse& response); 279 const enterprise_management::DeviceManagementResponse& response);
261 280
262 // Callback for status upload requests. 281 // Callback for status upload requests.
263 void OnStatusUploadCompleted( 282 void OnStatusUploadCompleted(
264 const DeviceManagementRequestJob* job, 283 const DeviceManagementRequestJob* job,
265 const StatusCallback& callback, 284 const StatusCallback& callback,
266 DeviceManagementStatus status, 285 DeviceManagementStatus status,
267 int net_error, 286 int net_error,
268 const enterprise_management::DeviceManagementResponse& response); 287 const enterprise_management::DeviceManagementResponse& response);
269 288
289 // Callback for remote command fetch requests.
290 void OnRemoteCommandsFetched(
291 const DeviceManagementRequestJob* job,
292 const RemoteCommandCallback& callback,
293 DeviceManagementStatus status,
294 int net_error,
295 const enterprise_management::DeviceManagementResponse& response);
296
270 // Helper to remove a job from request_jobs_. 297 // Helper to remove a job from request_jobs_.
271 void RemoveJob(const DeviceManagementRequestJob* job); 298 void RemoveJob(const DeviceManagementRequestJob* job);
272 299
273 // Observer notification helpers. 300 // Observer notification helpers.
274 void NotifyPolicyFetched(); 301 void NotifyPolicyFetched();
275 void NotifyRegistrationStateChanged(); 302 void NotifyRegistrationStateChanged();
276 void NotifyRobotAuthCodesFetched(); 303 void NotifyRobotAuthCodesFetched();
277 void NotifyClientError(); 304 void NotifyClientError();
278 305
279 // Data necessary for constructing policy requests. 306 // Data necessary for constructing policy requests.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 ObserverList<Observer, true> observers_; 345 ObserverList<Observer, true> observers_;
319 scoped_refptr<net::URLRequestContextGetter> request_context_; 346 scoped_refptr<net::URLRequestContextGetter> request_context_;
320 347
321 private: 348 private:
322 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient); 349 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient);
323 }; 350 };
324 351
325 } // namespace policy 352 } // namespace policy
326 353
327 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ 354 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698