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

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: comments grammar fixes; fix win compile Created 5 years, 10 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 protobuf contained in a
bartfab (slow) 2015/02/17 18:13:52 Nit: Instead of describing the type (it is clear f
binjin 2015/02/18 15:37:50 Done.
54 // std::vector.
55 using RemoteCommandCallback = base::Callback<void(
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
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.
151 virtual void FetchRemoteCommands(
152 RemoteCommandJob::UniqueIDType last_command_id,
153 const std::vector<enterprise_management::RemoteCommandResult>&
154 command_results,
155 const RemoteCommandCallback& callback);
156
141 // Adds an observer to be called back upon policy and state changes. 157 // Adds an observer to be called back upon policy and state changes.
142 void AddObserver(Observer* observer); 158 void AddObserver(Observer* observer);
143 159
144 // Removes the specified observer. 160 // Removes the specified observer.
145 void RemoveObserver(Observer* observer); 161 void RemoveObserver(Observer* observer);
146 162
147 void set_submit_machine_id(bool submit_machine_id) { 163 void set_submit_machine_id(bool submit_machine_id) {
148 submit_machine_id_ = submit_machine_id; 164 submit_machine_id_ = submit_machine_id;
149 } 165 }
150 166
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 const enterprise_management::DeviceManagementResponse& response); 276 const enterprise_management::DeviceManagementResponse& response);
261 277
262 // Callback for status upload requests. 278 // Callback for status upload requests.
263 void OnStatusUploadCompleted( 279 void OnStatusUploadCompleted(
264 const DeviceManagementRequestJob* job, 280 const DeviceManagementRequestJob* job,
265 const StatusCallback& callback, 281 const StatusCallback& callback,
266 DeviceManagementStatus status, 282 DeviceManagementStatus status,
267 int net_error, 283 int net_error,
268 const enterprise_management::DeviceManagementResponse& response); 284 const enterprise_management::DeviceManagementResponse& response);
269 285
286 // Callback for remote commands fetch requests.
287 void OnRemoteCommandsFetched(
288 const DeviceManagementRequestJob* job,
289 const RemoteCommandCallback& callback,
290 DeviceManagementStatus status,
291 int net_error,
292 const enterprise_management::DeviceManagementResponse& response);
293
270 // Helper to remove a job from request_jobs_. 294 // Helper to remove a job from request_jobs_.
271 void RemoveJob(const DeviceManagementRequestJob* job); 295 void RemoveJob(const DeviceManagementRequestJob* job);
272 296
273 // Observer notification helpers. 297 // Observer notification helpers.
274 void NotifyPolicyFetched(); 298 void NotifyPolicyFetched();
275 void NotifyRegistrationStateChanged(); 299 void NotifyRegistrationStateChanged();
276 void NotifyRobotAuthCodesFetched(); 300 void NotifyRobotAuthCodesFetched();
277 void NotifyClientError(); 301 void NotifyClientError();
278 302
279 // Data necessary for constructing policy requests. 303 // Data necessary for constructing policy requests.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 ObserverList<Observer, true> observers_; 342 ObserverList<Observer, true> observers_;
319 scoped_refptr<net::URLRequestContextGetter> request_context_; 343 scoped_refptr<net::URLRequestContextGetter> request_context_;
320 344
321 private: 345 private:
322 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient); 346 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient);
323 }; 347 };
324 348
325 } // namespace policy 349 } // namespace policy
326 350
327 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ 351 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698