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: chrome/browser/policy/device_management_backend_impl.cc

Issue 6409040: New policy protobuf protocol. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/policy/device_management_backend_impl.h" 5 #include "chrome/browser/policy/device_management_backend_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
11 #include "net/base/escape.h" 11 #include "net/base/escape.h"
12 #include "net/url_request/url_request_status.h" 12 #include "net/url_request/url_request_status.h"
13 #include "chrome/browser/policy/device_management_service.h" 13 #include "chrome/browser/policy/device_management_service.h"
14 #include "chrome/common/chrome_version_info.h" 14 #include "chrome/common/chrome_version_info.h"
15 15
16 namespace policy { 16 namespace policy {
17 17
18 // Name constants for URL query parameters. 18 // Name constants for URL query parameters.
19 const char DeviceManagementBackendImpl::kParamRequest[] = "request"; 19 const char DeviceManagementBackendImpl::kParamRequest[] = "request";
20 const char DeviceManagementBackendImpl::kParamDeviceType[] = "devicetype"; 20 const char DeviceManagementBackendImpl::kParamDeviceType[] = "devicetype";
21 const char DeviceManagementBackendImpl::kParamAppType[] = "apptype"; 21 const char DeviceManagementBackendImpl::kParamAppType[] = "apptype";
22 const char DeviceManagementBackendImpl::kParamDeviceID[] = "deviceid"; 22 const char DeviceManagementBackendImpl::kParamDeviceID[] = "deviceid";
23 const char DeviceManagementBackendImpl::kParamAgent[] = "agent"; 23 const char DeviceManagementBackendImpl::kParamAgent[] = "agent";
24 24
25 // String constants for the device and app type we report to the server. 25 // String constants for the device and app type we report to the server.
26 const char DeviceManagementBackendImpl::kValueRequestRegister[] = "register"; 26 const char DeviceManagementBackendImpl::kValueRequestRegister[] = "register";
27 const char DeviceManagementBackendImpl::kValueRequestUnregister[] = 27 const char DeviceManagementBackendImpl::kValueRequestUnregister[] =
28 "unregister"; 28 "unregister";
29 const char DeviceManagementBackendImpl::kValueRequestPolicy[] = "policy"; 29 const char DeviceManagementBackendImpl::kValueRequestPolicy[] = "policy";
30 const char DeviceManagementBackendImpl::kValueRequestCloudPolicy[] =
31 "cloud_policy";
30 const char DeviceManagementBackendImpl::kValueDeviceType[] = "Chrome OS"; 32 const char DeviceManagementBackendImpl::kValueDeviceType[] = "Chrome OS";
31 const char DeviceManagementBackendImpl::kValueAppType[] = "Chrome"; 33 const char DeviceManagementBackendImpl::kValueAppType[] = "Chrome";
32 34
33 namespace { 35 namespace {
34 36
35 const char kValueAgent[] = "%s enterprise management client version %s (%s)"; 37 const char kValueAgent[] = "%s enterprise management client version %s (%s)";
36 38
37 const char kPostContentType[] = "application/protobuf"; 39 const char kPostContentType[] = "application/protobuf";
38 40
39 const char kServiceTokenAuthHeader[] = "Authorization: GoogleLogin auth="; 41 const char kServiceTokenAuthHeader[] = "Authorization: GoogleLogin auth=";
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 const std::string& data) { 165 const std::string& data) {
164 // Delete ourselves when this is done. 166 // Delete ourselves when this is done.
165 scoped_ptr<DeviceManagementJob> scoped_killer(this); 167 scoped_ptr<DeviceManagementJob> scoped_killer(this);
166 168
167 if (status.status() != net::URLRequestStatus::SUCCESS) { 169 if (status.status() != net::URLRequestStatus::SUCCESS) {
168 OnError(DeviceManagementBackend::kErrorRequestFailed); 170 OnError(DeviceManagementBackend::kErrorRequestFailed);
169 return; 171 return;
170 } 172 }
171 173
172 if (response_code != 200) { 174 if (response_code != 200) {
173 OnError(DeviceManagementBackend::kErrorHttpStatus); 175 if (response_code == 400)
176 OnError(DeviceManagementBackend::kErrorRequestInvalid);
177 else
178 OnError(DeviceManagementBackend::kErrorHttpStatus);
174 return; 179 return;
175 } 180 }
176 181
177 em::DeviceManagementResponse response; 182 em::DeviceManagementResponse response;
178 if (!response.ParseFromString(data)) { 183 if (!response.ParseFromString(data)) {
179 OnError(DeviceManagementBackend::kErrorResponseDecoding); 184 OnError(DeviceManagementBackend::kErrorResponseDecoding);
180 return; 185 return;
181 } 186 }
182 187
183 // Check service error code. 188 // Check service error code.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 228 }
224 229
225 // Handles device registration jobs. 230 // Handles device registration jobs.
226 class DeviceManagementRegisterJob : public DeviceManagementJobBase { 231 class DeviceManagementRegisterJob : public DeviceManagementJobBase {
227 public: 232 public:
228 DeviceManagementRegisterJob( 233 DeviceManagementRegisterJob(
229 DeviceManagementBackendImpl* backend_impl, 234 DeviceManagementBackendImpl* backend_impl,
230 const std::string& auth_token, 235 const std::string& auth_token,
231 const std::string& device_id, 236 const std::string& device_id,
232 const em::DeviceRegisterRequest& request, 237 const em::DeviceRegisterRequest& request,
233 DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate); 238 DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate)
239 : DeviceManagementJobBase(
240 backend_impl,
241 DeviceManagementBackendImpl::kValueRequestRegister,
242 device_id),
243 delegate_(delegate) {
244 SetAuthToken(auth_token);
245 em::DeviceManagementRequest request_wrapper;
246 request_wrapper.mutable_register_request()->CopyFrom(request);
247 SetPayload(request_wrapper);
248 }
234 virtual ~DeviceManagementRegisterJob() {} 249 virtual ~DeviceManagementRegisterJob() {}
235 250
236 private: 251 private:
237 // DeviceManagementJobBase overrides. 252 // DeviceManagementJobBase overrides.
238 virtual void OnError(DeviceManagementBackend::ErrorCode error) { 253 virtual void OnError(DeviceManagementBackend::ErrorCode error) {
239 delegate_->OnError(error); 254 delegate_->OnError(error);
240 } 255 }
241 virtual void OnResponse(const em::DeviceManagementResponse& response) { 256 virtual void OnResponse(const em::DeviceManagementResponse& response) {
242 delegate_->HandleRegisterResponse(response.register_response()); 257 delegate_->HandleRegisterResponse(response.register_response());
243 } 258 }
244 259
245 DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate_; 260 DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate_;
246 261
247 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRegisterJob); 262 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRegisterJob);
248 }; 263 };
249 264
250 DeviceManagementRegisterJob::DeviceManagementRegisterJob(
251 DeviceManagementBackendImpl* backend_impl,
252 const std::string& auth_token,
253 const std::string& device_id,
254 const em::DeviceRegisterRequest& request,
255 DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate)
256 : DeviceManagementJobBase(
257 backend_impl,
258 DeviceManagementBackendImpl::kValueRequestRegister,
259 device_id),
260 delegate_(delegate) {
261 SetAuthToken(auth_token);
262 em::DeviceManagementRequest request_wrapper;
263 request_wrapper.mutable_register_request()->CopyFrom(request);
264 SetPayload(request_wrapper);
265 }
266
267 // Handles device unregistration jobs. 265 // Handles device unregistration jobs.
268 class DeviceManagementUnregisterJob : public DeviceManagementJobBase { 266 class DeviceManagementUnregisterJob : public DeviceManagementJobBase {
269 public: 267 public:
270 DeviceManagementUnregisterJob( 268 DeviceManagementUnregisterJob(
271 DeviceManagementBackendImpl* backend_impl, 269 DeviceManagementBackendImpl* backend_impl,
270 const std::string& device_management_token,
272 const std::string& device_id, 271 const std::string& device_id,
273 const std::string& device_management_token,
274 const em::DeviceUnregisterRequest& request, 272 const em::DeviceUnregisterRequest& request,
275 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate); 273 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate)
274 : DeviceManagementJobBase(
275 backend_impl,
276 DeviceManagementBackendImpl::kValueRequestUnregister,
277 device_id),
278 delegate_(delegate) {
279 SetDeviceManagementToken(device_management_token);
280 em::DeviceManagementRequest request_wrapper;
281 request_wrapper.mutable_unregister_request()->CopyFrom(request);
282 SetPayload(request_wrapper);
283 }
276 virtual ~DeviceManagementUnregisterJob() {} 284 virtual ~DeviceManagementUnregisterJob() {}
277 285
278 private: 286 private:
279 // DeviceManagementJobBase overrides. 287 // DeviceManagementJobBase overrides.
280 virtual void OnError(DeviceManagementBackend::ErrorCode error) { 288 virtual void OnError(DeviceManagementBackend::ErrorCode error) {
281 delegate_->OnError(error); 289 delegate_->OnError(error);
282 } 290 }
283 virtual void OnResponse(const em::DeviceManagementResponse& response) { 291 virtual void OnResponse(const em::DeviceManagementResponse& response) {
284 delegate_->HandleUnregisterResponse(response.unregister_response()); 292 delegate_->HandleUnregisterResponse(response.unregister_response());
285 } 293 }
286 294
287 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate_; 295 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate_;
288 296
289 DISALLOW_COPY_AND_ASSIGN(DeviceManagementUnregisterJob); 297 DISALLOW_COPY_AND_ASSIGN(DeviceManagementUnregisterJob);
290 }; 298 };
291 299
292 DeviceManagementUnregisterJob::DeviceManagementUnregisterJob(
293 DeviceManagementBackendImpl* backend_impl,
294 const std::string& device_management_token,
295 const std::string& device_id,
296 const em::DeviceUnregisterRequest& request,
297 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate)
298 : DeviceManagementJobBase(
299 backend_impl,
300 DeviceManagementBackendImpl::kValueRequestUnregister,
301 device_id),
302 delegate_(delegate) {
303 SetDeviceManagementToken(device_management_token);
304 em::DeviceManagementRequest request_wrapper;
305 request_wrapper.mutable_unregister_request()->CopyFrom(request);
306 SetPayload(request_wrapper);
307 }
308
309 // Handles policy request jobs. 300 // Handles policy request jobs.
310 class DeviceManagementPolicyJob : public DeviceManagementJobBase { 301 class DeviceManagementPolicyJob : public DeviceManagementJobBase {
311 public: 302 public:
312 DeviceManagementPolicyJob( 303 DeviceManagementPolicyJob(
313 DeviceManagementBackendImpl* backend_impl, 304 DeviceManagementBackendImpl* backend_impl,
314 const std::string& device_management_token, 305 const std::string& device_management_token,
315 const std::string& device_id, 306 const std::string& device_id,
316 const em::DevicePolicyRequest& request, 307 const em::DevicePolicyRequest& request,
317 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate); 308 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate)
309 : DeviceManagementJobBase(
310 backend_impl,
311 DeviceManagementBackendImpl::kValueRequestPolicy,
312 device_id),
313 delegate_(delegate) {
314 SetDeviceManagementToken(device_management_token);
315 em::DeviceManagementRequest request_wrapper;
316 request_wrapper.mutable_policy_request()->CopyFrom(request);
317 SetPayload(request_wrapper);
318 }
318 virtual ~DeviceManagementPolicyJob() {} 319 virtual ~DeviceManagementPolicyJob() {}
319 320
320 private: 321 private:
321 // DeviceManagementJobBase overrides. 322 // DeviceManagementJobBase overrides.
322 virtual void OnError(DeviceManagementBackend::ErrorCode error) { 323 virtual void OnError(DeviceManagementBackend::ErrorCode error) {
323 delegate_->OnError(error); 324 delegate_->OnError(error);
324 } 325 }
325 virtual void OnResponse(const em::DeviceManagementResponse& response) { 326 virtual void OnResponse(const em::DeviceManagementResponse& response) {
326 delegate_->HandlePolicyResponse(response.policy_response()); 327 delegate_->HandlePolicyResponse(response.policy_response());
327 } 328 }
328 329
329 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate_; 330 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate_;
330 331
331 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyJob); 332 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyJob);
332 }; 333 };
333 334
334 DeviceManagementPolicyJob::DeviceManagementPolicyJob( 335 // Handles cloud policy request jobs.
335 DeviceManagementBackendImpl* backend_impl, 336 class CloudPolicyJob : public DeviceManagementJobBase {
336 const std::string& device_management_token, 337 public:
337 const std::string& device_id, 338 CloudPolicyJob(
338 const em::DevicePolicyRequest& request, 339 DeviceManagementBackendImpl* backend_impl,
339 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate) 340 const std::string& device_management_token,
340 : DeviceManagementJobBase( 341 const std::string& device_id,
342 const em::CloudPolicyRequest& request,
343 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate)
344 : DeviceManagementJobBase(
341 backend_impl, 345 backend_impl,
342 DeviceManagementBackendImpl::kValueRequestPolicy, 346 DeviceManagementBackendImpl::kValueRequestCloudPolicy,
343 device_id), 347 device_id),
344 delegate_(delegate) { 348 delegate_(delegate) {
345 SetDeviceManagementToken(device_management_token); 349 SetDeviceManagementToken(device_management_token);
346 em::DeviceManagementRequest request_wrapper; 350 em::DeviceManagementRequest request_wrapper;
347 request_wrapper.mutable_policy_request()->CopyFrom(request); 351 request_wrapper.mutable_cloud_policy_request()->CopyFrom(request);
348 SetPayload(request_wrapper); 352 SetPayload(request_wrapper);
349 } 353 }
354 virtual ~CloudPolicyJob() {}
355
356 private:
357 // DeviceManagementJobBase overrides.
358 virtual void OnError(DeviceManagementBackend::ErrorCode error) {
359 delegate_->OnError(error);
360 }
361 virtual void OnResponse(const em::DeviceManagementResponse& response) {
362 delegate_->HandleCloudPolicyResponse(response.cloud_policy_response());
363 }
364
365 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate_;
366
367 DISALLOW_COPY_AND_ASSIGN(CloudPolicyJob);
368 };
350 369
351 DeviceManagementBackendImpl::DeviceManagementBackendImpl( 370 DeviceManagementBackendImpl::DeviceManagementBackendImpl(
352 DeviceManagementService* service) 371 DeviceManagementService* service)
353 : service_(service) { 372 : service_(service) {
354 } 373 }
355 374
356 DeviceManagementBackendImpl::~DeviceManagementBackendImpl() { 375 DeviceManagementBackendImpl::~DeviceManagementBackendImpl() {
357 // Swap to a helper, so we don't interfere with the unregistration on delete. 376 // Swap to a helper, so we don't interfere with the unregistration on delete.
358 JobSet to_be_deleted; 377 JobSet to_be_deleted;
359 to_be_deleted.swap(pending_jobs_); 378 to_be_deleted.swap(pending_jobs_);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 421
403 void DeviceManagementBackendImpl::ProcessPolicyRequest( 422 void DeviceManagementBackendImpl::ProcessPolicyRequest(
404 const std::string& device_management_token, 423 const std::string& device_management_token,
405 const std::string& device_id, 424 const std::string& device_id,
406 const em::DevicePolicyRequest& request, 425 const em::DevicePolicyRequest& request,
407 DevicePolicyResponseDelegate* delegate) { 426 DevicePolicyResponseDelegate* delegate) {
408 AddJob(new DeviceManagementPolicyJob(this, device_management_token, device_id, 427 AddJob(new DeviceManagementPolicyJob(this, device_management_token, device_id,
409 request, delegate)); 428 request, delegate));
410 } 429 }
411 430
431 void DeviceManagementBackendImpl::ProcessCloudPolicyRequest(
432 const std::string& device_management_token,
433 const std::string& device_id,
434 const em::CloudPolicyRequest& request,
435 DevicePolicyResponseDelegate* delegate) {
436 AddJob(new CloudPolicyJob(this, device_management_token, device_id,
437 request, delegate));
438 }
439
412 } // namespace policy 440 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/device_management_backend_impl.h ('k') | chrome/browser/policy/device_management_backend_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698