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

Side by Side Diff: chrome/browser/policy/device_management_backend_impl.cc

Issue 5162006: Always send the device ID when making device management requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years, 1 month 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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.
19 const char DeviceManagementBackendImpl::kParamRequest[] = "request";
20 const char DeviceManagementBackendImpl::kParamDeviceType[] = "devicetype";
21 const char DeviceManagementBackendImpl::kParamAppType[] = "apptype";
22 const char DeviceManagementBackendImpl::kParamDeviceID[] = "deviceid";
23 const char DeviceManagementBackendImpl::kParamAgent[] = "agent";
24
25 // String constants for the device and app type we report to the server.
26 const char DeviceManagementBackendImpl::kValueRequestRegister[] = "register";
27 const char DeviceManagementBackendImpl::kValueRequestUnregister[] =
28 "unregister";
29 const char DeviceManagementBackendImpl::kValueRequestPolicy[] = "policy";
30 const char DeviceManagementBackendImpl::kValueDeviceType[] = "Chrome OS";
31 const char DeviceManagementBackendImpl::kValueAppType[] = "Chrome";
32
18 namespace { 33 namespace {
19 34
20 // Name constants for URL query parameters. 35 const char kValueAgent[] = "%s enterprise management client version %s (%s)";
21 const char kServiceParamRequest[] = "request";
22 const char kServiceParamDeviceType[] = "devicetype";
23 const char kServiceParamAppType[] = "apptype";
24 const char kServiceParamDeviceID[] = "deviceid";
25 const char kServiceParamAgent[] = "agent";
26 36
27 // String constants for the device and app type we report to the server. 37 const char kPostContentType[] = "application/octet-stream";
28 const char kServiceValueDeviceType[] = "Chrome OS";
29 const char kServiceValueAppType[] = "Chrome";
30
31 const char kServiceValueAgent[] =
32 "%s enterprise management client version %s (%s)";
33 38
34 const char kServiceTokenAuthHeader[] = "Authorization: GoogleLogin auth="; 39 const char kServiceTokenAuthHeader[] = "Authorization: GoogleLogin auth=";
35 const char kDMTokenAuthHeader[] = "Authorization: GoogleDMToken token="; 40 const char kDMTokenAuthHeader[] = "Authorization: GoogleDMToken token=";
36 41
37 // Helper class for URL query parameter encoding/decoding. 42 // Helper class for URL query parameter encoding/decoding.
38 class URLQueryParameters { 43 class URLQueryParameters {
39 public: 44 public:
40 URLQueryParameters() {} 45 URLQueryParameters() {}
41 46
42 // Add a query parameter. 47 // Add a query parameter.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 virtual void HandleResponse(const URLRequestStatus& status, 93 virtual void HandleResponse(const URLRequestStatus& status,
89 int response_code, 94 int response_code,
90 const ResponseCookies& cookies, 95 const ResponseCookies& cookies,
91 const std::string& data); 96 const std::string& data);
92 virtual GURL GetURL(const std::string& server_url); 97 virtual GURL GetURL(const std::string& server_url);
93 virtual void ConfigureRequest(URLFetcher* fetcher); 98 virtual void ConfigureRequest(URLFetcher* fetcher);
94 99
95 protected: 100 protected:
96 // Constructs a device management job running for the given backend. 101 // Constructs a device management job running for the given backend.
97 DeviceManagementJobBase(DeviceManagementBackendImpl* backend_impl, 102 DeviceManagementJobBase(DeviceManagementBackendImpl* backend_impl,
98 const std::string& request_type) 103 const std::string& request_type,
104 const std::string& device_id)
99 : backend_impl_(backend_impl) { 105 : backend_impl_(backend_impl) {
100 query_params_.Put(kServiceParamRequest, request_type); 106 query_params_.Put(DeviceManagementBackendImpl::kParamRequest, request_type);
101 query_params_.Put(kServiceParamDeviceType, kServiceValueDeviceType); 107 query_params_.Put(DeviceManagementBackendImpl::kParamDeviceType,
102 query_params_.Put(kServiceParamAppType, kServiceValueAppType); 108 DeviceManagementBackendImpl::kValueDeviceType);
103 chrome::VersionInfo version_info; 109 query_params_.Put(DeviceManagementBackendImpl::kParamAppType,
104 std::string agent = base::StringPrintf(kServiceValueAgent, 110 DeviceManagementBackendImpl::kValueAppType);
105 version_info.Name().c_str(), 111 query_params_.Put(DeviceManagementBackendImpl::kParamDeviceID, device_id);
106 version_info.Version().c_str(), 112 query_params_.Put(DeviceManagementBackendImpl::kParamAgent,
107 version_info.LastChange().c_str()); 113 DeviceManagementBackendImpl::GetAgentString());
108 query_params_.Put(kServiceParamAgent, agent);
109 } 114 }
110 115
111 void SetQueryParam(const std::string& name, const std::string& value) { 116 void SetQueryParam(const std::string& name, const std::string& value) {
112 query_params_.Put(name, value); 117 query_params_.Put(name, value);
113 } 118 }
114 119
115 void SetAuthToken(const std::string& auth_token) { 120 void SetAuthToken(const std::string& auth_token) {
116 auth_token_ = auth_token; 121 auth_token_ = auth_token;
117 } 122 }
118 123
119 void SetDeviceManagementToken(const std::string& device_management_token) { 124 void SetDeviceManagementToken(const std::string& device_management_token) {
120 device_management_token_ = device_management_token; 125 device_management_token_ = device_management_token;
121 } 126 }
122 127
123 void SetDeviceID(const std::string& device_id) {
124 query_params_.Put(kServiceParamDeviceID, device_id);
125 }
126
127 void SetPayload(const em::DeviceManagementRequest& request) { 128 void SetPayload(const em::DeviceManagementRequest& request) {
128 if (!request.SerializeToString(&payload_)) { 129 if (!request.SerializeToString(&payload_)) {
129 NOTREACHED(); 130 NOTREACHED();
130 LOG(ERROR) << "Failed to serialize request."; 131 LOG(ERROR) << "Failed to serialize request.";
131 } 132 }
132 } 133 }
133 134
134 private: 135 private:
135 // Implemented by subclasses to handle decoded responses and errors. 136 // Implemented by subclasses to handle decoded responses and errors.
136 virtual void OnResponse( 137 virtual void OnResponse(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 204
204 OnResponse(response); 205 OnResponse(response);
205 } 206 }
206 207
207 GURL DeviceManagementJobBase::GetURL( 208 GURL DeviceManagementJobBase::GetURL(
208 const std::string& server_url) { 209 const std::string& server_url) {
209 return GURL(server_url + '?' + query_params_.Encode()); 210 return GURL(server_url + '?' + query_params_.Encode());
210 } 211 }
211 212
212 void DeviceManagementJobBase::ConfigureRequest(URLFetcher* fetcher) { 213 void DeviceManagementJobBase::ConfigureRequest(URLFetcher* fetcher) {
213 fetcher->set_upload_data("application/octet-stream", payload_); 214 fetcher->set_upload_data(kPostContentType, payload_);
214 std::string extra_headers; 215 std::string extra_headers;
215 if (!auth_token_.empty()) 216 if (!auth_token_.empty())
216 extra_headers += kServiceTokenAuthHeader + auth_token_ + "\n"; 217 extra_headers += kServiceTokenAuthHeader + auth_token_ + "\n";
217 if (!device_management_token_.empty()) 218 if (!device_management_token_.empty())
218 extra_headers += kDMTokenAuthHeader + device_management_token_ + "\n"; 219 extra_headers += kDMTokenAuthHeader + device_management_token_ + "\n";
219 fetcher->set_extra_request_headers(extra_headers); 220 fetcher->set_extra_request_headers(extra_headers);
220 } 221 }
221 222
222 // Handles device registration jobs. 223 // Handles device registration jobs.
223 class DeviceManagementRegisterJob : public DeviceManagementJobBase { 224 class DeviceManagementRegisterJob : public DeviceManagementJobBase {
(...skipping 19 matching lines...) Expand all
243 244
244 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRegisterJob); 245 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRegisterJob);
245 }; 246 };
246 247
247 DeviceManagementRegisterJob::DeviceManagementRegisterJob( 248 DeviceManagementRegisterJob::DeviceManagementRegisterJob(
248 DeviceManagementBackendImpl* backend_impl, 249 DeviceManagementBackendImpl* backend_impl,
249 const std::string& auth_token, 250 const std::string& auth_token,
250 const std::string& device_id, 251 const std::string& device_id,
251 const em::DeviceRegisterRequest& request, 252 const em::DeviceRegisterRequest& request,
252 DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate) 253 DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate)
253 : DeviceManagementJobBase(backend_impl, "register"), 254 : DeviceManagementJobBase(
255 backend_impl,
256 DeviceManagementBackendImpl::kValueRequestRegister,
257 device_id),
254 delegate_(delegate) { 258 delegate_(delegate) {
255 SetDeviceID(device_id);
256 SetAuthToken(auth_token); 259 SetAuthToken(auth_token);
257 em::DeviceManagementRequest request_wrapper; 260 em::DeviceManagementRequest request_wrapper;
258 request_wrapper.mutable_register_request()->CopyFrom(request); 261 request_wrapper.mutable_register_request()->CopyFrom(request);
259 SetPayload(request_wrapper); 262 SetPayload(request_wrapper);
260 } 263 }
261 264
262 // Handles device unregistration jobs. 265 // Handles device unregistration jobs.
263 class DeviceManagementUnregisterJob : public DeviceManagementJobBase { 266 class DeviceManagementUnregisterJob : public DeviceManagementJobBase {
264 public: 267 public:
265 DeviceManagementUnregisterJob( 268 DeviceManagementUnregisterJob(
266 DeviceManagementBackendImpl* backend_impl, 269 DeviceManagementBackendImpl* backend_impl,
270 const std::string& device_id,
267 const std::string& device_management_token, 271 const std::string& device_management_token,
268 const em::DeviceUnregisterRequest& request, 272 const em::DeviceUnregisterRequest& request,
269 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate); 273 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate);
270 virtual ~DeviceManagementUnregisterJob() {} 274 virtual ~DeviceManagementUnregisterJob() {}
271 275
272 private: 276 private:
273 // DeviceManagementJobBase overrides. 277 // DeviceManagementJobBase overrides.
274 virtual void OnError(DeviceManagementBackend::ErrorCode error) { 278 virtual void OnError(DeviceManagementBackend::ErrorCode error) {
275 delegate_->OnError(error); 279 delegate_->OnError(error);
276 } 280 }
277 virtual void OnResponse(const em::DeviceManagementResponse& response) { 281 virtual void OnResponse(const em::DeviceManagementResponse& response) {
278 delegate_->HandleUnregisterResponse(response.unregister_response()); 282 delegate_->HandleUnregisterResponse(response.unregister_response());
279 } 283 }
280 284
281 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate_; 285 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate_;
282 286
283 DISALLOW_COPY_AND_ASSIGN(DeviceManagementUnregisterJob); 287 DISALLOW_COPY_AND_ASSIGN(DeviceManagementUnregisterJob);
284 }; 288 };
285 289
286 DeviceManagementUnregisterJob::DeviceManagementUnregisterJob( 290 DeviceManagementUnregisterJob::DeviceManagementUnregisterJob(
287 DeviceManagementBackendImpl* backend_impl, 291 DeviceManagementBackendImpl* backend_impl,
288 const std::string& device_management_token, 292 const std::string& device_management_token,
293 const std::string& device_id,
289 const em::DeviceUnregisterRequest& request, 294 const em::DeviceUnregisterRequest& request,
290 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate) 295 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate)
291 : DeviceManagementJobBase(backend_impl, "unregister"), 296 : DeviceManagementJobBase(
297 backend_impl,
298 DeviceManagementBackendImpl::kValueRequestUnregister,
299 device_id),
292 delegate_(delegate) { 300 delegate_(delegate) {
293 SetDeviceManagementToken(device_management_token); 301 SetDeviceManagementToken(device_management_token);
294 em::DeviceManagementRequest request_wrapper; 302 em::DeviceManagementRequest request_wrapper;
295 request_wrapper.mutable_unregister_request()->CopyFrom(request); 303 request_wrapper.mutable_unregister_request()->CopyFrom(request);
296 SetPayload(request_wrapper); 304 SetPayload(request_wrapper);
297 } 305 }
298 306
299 // Handles policy request jobs. 307 // Handles policy request jobs.
300 class DeviceManagementPolicyJob : public DeviceManagementJobBase { 308 class DeviceManagementPolicyJob : public DeviceManagementJobBase {
301 public: 309 public:
302 DeviceManagementPolicyJob( 310 DeviceManagementPolicyJob(
303 DeviceManagementBackendImpl* backend_impl, 311 DeviceManagementBackendImpl* backend_impl,
304 const std::string& device_management_token, 312 const std::string& device_management_token,
313 const std::string& device_id,
305 const em::DevicePolicyRequest& request, 314 const em::DevicePolicyRequest& request,
306 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate); 315 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate);
307 virtual ~DeviceManagementPolicyJob() {} 316 virtual ~DeviceManagementPolicyJob() {}
308 317
309 private: 318 private:
310 // DeviceManagementJobBase overrides. 319 // DeviceManagementJobBase overrides.
311 virtual void OnError(DeviceManagementBackend::ErrorCode error) { 320 virtual void OnError(DeviceManagementBackend::ErrorCode error) {
312 delegate_->OnError(error); 321 delegate_->OnError(error);
313 } 322 }
314 virtual void OnResponse(const em::DeviceManagementResponse& response) { 323 virtual void OnResponse(const em::DeviceManagementResponse& response) {
315 delegate_->HandlePolicyResponse(response.policy_response()); 324 delegate_->HandlePolicyResponse(response.policy_response());
316 } 325 }
317 326
318 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate_; 327 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate_;
319 328
320 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyJob); 329 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyJob);
321 }; 330 };
322 331
323 DeviceManagementPolicyJob::DeviceManagementPolicyJob( 332 DeviceManagementPolicyJob::DeviceManagementPolicyJob(
324 DeviceManagementBackendImpl* backend_impl, 333 DeviceManagementBackendImpl* backend_impl,
325 const std::string& device_management_token, 334 const std::string& device_management_token,
335 const std::string& device_id,
326 const em::DevicePolicyRequest& request, 336 const em::DevicePolicyRequest& request,
327 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate) 337 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate)
328 : DeviceManagementJobBase(backend_impl, "policy"), 338 : DeviceManagementJobBase(
339 backend_impl,
340 DeviceManagementBackendImpl::kValueRequestPolicy,
341 device_id),
329 delegate_(delegate) { 342 delegate_(delegate) {
330 SetDeviceManagementToken(device_management_token); 343 SetDeviceManagementToken(device_management_token);
331 em::DeviceManagementRequest request_wrapper; 344 em::DeviceManagementRequest request_wrapper;
332 request_wrapper.mutable_policy_request()->CopyFrom(request); 345 request_wrapper.mutable_policy_request()->CopyFrom(request);
333 SetPayload(request_wrapper); 346 SetPayload(request_wrapper);
334 } 347 }
335 348
336 DeviceManagementBackendImpl::DeviceManagementBackendImpl( 349 DeviceManagementBackendImpl::DeviceManagementBackendImpl(
337 DeviceManagementService* service) 350 DeviceManagementService* service)
338 : service_(service) { 351 : service_(service) {
339 } 352 }
340 353
341 DeviceManagementBackendImpl::~DeviceManagementBackendImpl() { 354 DeviceManagementBackendImpl::~DeviceManagementBackendImpl() {
342 // Swap to a helper, so we don't interfere with the unregistration on delete. 355 // Swap to a helper, so we don't interfere with the unregistration on delete.
343 JobSet to_be_deleted; 356 JobSet to_be_deleted;
344 to_be_deleted.swap(pending_jobs_); 357 to_be_deleted.swap(pending_jobs_);
345 for (JobSet::iterator job(to_be_deleted.begin()); 358 for (JobSet::iterator job(to_be_deleted.begin());
346 job != to_be_deleted.end(); 359 job != to_be_deleted.end();
347 ++job) { 360 ++job) {
348 service_->RemoveJob(*job); 361 service_->RemoveJob(*job);
349 delete *job; 362 delete *job;
350 } 363 }
351 } 364 }
352 365
366 std::string DeviceManagementBackendImpl::GetAgentString() {
367 chrome::VersionInfo version_info;
368 return base::StringPrintf(kValueAgent,
369 version_info.Name().c_str(),
370 version_info.Version().c_str(),
371 version_info.LastChange().c_str());
372 }
373
353 void DeviceManagementBackendImpl::JobDone(DeviceManagementJobBase* job) { 374 void DeviceManagementBackendImpl::JobDone(DeviceManagementJobBase* job) {
354 pending_jobs_.erase(job); 375 pending_jobs_.erase(job);
355 } 376 }
356 377
357 void DeviceManagementBackendImpl::AddJob(DeviceManagementJobBase* job) { 378 void DeviceManagementBackendImpl::AddJob(DeviceManagementJobBase* job) {
358 pending_jobs_.insert(job); 379 pending_jobs_.insert(job);
359 service_->AddJob(job); 380 service_->AddJob(job);
360 } 381 }
361 382
362 void DeviceManagementBackendImpl::ProcessRegisterRequest( 383 void DeviceManagementBackendImpl::ProcessRegisterRequest(
363 const std::string& auth_token, 384 const std::string& auth_token,
364 const std::string& device_id, 385 const std::string& device_id,
365 const em::DeviceRegisterRequest& request, 386 const em::DeviceRegisterRequest& request,
366 DeviceRegisterResponseDelegate* delegate) { 387 DeviceRegisterResponseDelegate* delegate) {
367 AddJob(new DeviceManagementRegisterJob(this, auth_token, device_id, request, 388 AddJob(new DeviceManagementRegisterJob(this, auth_token, device_id, request,
368 delegate)); 389 delegate));
369 } 390 }
370 391
371 void DeviceManagementBackendImpl::ProcessUnregisterRequest( 392 void DeviceManagementBackendImpl::ProcessUnregisterRequest(
372 const std::string& device_management_token, 393 const std::string& device_management_token,
394 const std::string& device_id,
373 const em::DeviceUnregisterRequest& request, 395 const em::DeviceUnregisterRequest& request,
374 DeviceUnregisterResponseDelegate* delegate) { 396 DeviceUnregisterResponseDelegate* delegate) {
375 AddJob(new DeviceManagementUnregisterJob(this, device_management_token, 397 AddJob(new DeviceManagementUnregisterJob(this, device_management_token,
376 request, delegate)); 398 device_id, request, delegate));
377 } 399 }
378 400
379 void DeviceManagementBackendImpl::ProcessPolicyRequest( 401 void DeviceManagementBackendImpl::ProcessPolicyRequest(
380 const std::string& device_management_token, 402 const std::string& device_management_token,
403 const std::string& device_id,
381 const em::DevicePolicyRequest& request, 404 const em::DevicePolicyRequest& request,
382 DevicePolicyResponseDelegate* delegate) { 405 DevicePolicyResponseDelegate* delegate) {
383 AddJob(new DeviceManagementPolicyJob(this, device_management_token, request, 406 AddJob(new DeviceManagementPolicyJob(this, device_management_token, device_id,
384 delegate)); 407 request, delegate));
385 } 408 }
386 409
387 } // namespace policy 410 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/device_management_backend_impl.h ('k') | chrome/browser/policy/device_management_policy_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698