| 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 #include "components/policy/core/common/cloud/device_management_service.h" | 5 #include "components/policy/core/common/cloud/device_management_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
| 13 #include "net/base/escape.h" | 13 #include "net/base/escape.h" |
| 14 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 16 #include "net/http/http_response_headers.h" | 16 #include "net/http/http_response_headers.h" |
| 17 #include "net/url_request/url_fetcher.h" | 17 #include "net/url_request/url_fetcher.h" |
| 18 #include "net/url_request/url_request_context_getter.h" |
| 18 #include "net/url_request/url_request_status.h" | 19 #include "net/url_request/url_request_status.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 namespace em = enterprise_management; | 22 namespace em = enterprise_management; |
| 22 | 23 |
| 23 namespace policy { | 24 namespace policy { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 const char kPostContentType[] = "application/protobuf"; | 28 const char kPostContentType[] = "application/protobuf"; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } // namespace | 133 } // namespace |
| 133 | 134 |
| 134 // Request job implementation used with DeviceManagementService. | 135 // Request job implementation used with DeviceManagementService. |
| 135 class DeviceManagementRequestJobImpl : public DeviceManagementRequestJob { | 136 class DeviceManagementRequestJobImpl : public DeviceManagementRequestJob { |
| 136 public: | 137 public: |
| 137 DeviceManagementRequestJobImpl( | 138 DeviceManagementRequestJobImpl( |
| 138 JobType type, | 139 JobType type, |
| 139 const std::string& agent_parameter, | 140 const std::string& agent_parameter, |
| 140 const std::string& platform_parameter, | 141 const std::string& platform_parameter, |
| 141 DeviceManagementService* service, | 142 DeviceManagementService* service, |
| 142 net::URLRequestContextGetter* request_context); | 143 const scoped_refptr<net::URLRequestContextGetter>& request_context); |
| 143 virtual ~DeviceManagementRequestJobImpl(); | 144 virtual ~DeviceManagementRequestJobImpl(); |
| 144 | 145 |
| 145 // Handles the URL request response. | 146 // Handles the URL request response. |
| 146 void HandleResponse(const net::URLRequestStatus& status, | 147 void HandleResponse(const net::URLRequestStatus& status, |
| 147 int response_code, | 148 int response_code, |
| 148 const net::ResponseCookies& cookies, | 149 const net::ResponseCookies& cookies, |
| 149 const std::string& data); | 150 const std::string& data); |
| 150 | 151 |
| 151 // Gets the URL to contact. | 152 // Gets the URL to contact. |
| 152 GURL GetURL(const std::string& server_url); | 153 GURL GetURL(const std::string& server_url); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 173 // Pointer to the service this job is associated with. | 174 // Pointer to the service this job is associated with. |
| 174 DeviceManagementService* service_; | 175 DeviceManagementService* service_; |
| 175 | 176 |
| 176 // Whether the BYPASS_PROXY flag should be set by ConfigureRequest(). | 177 // Whether the BYPASS_PROXY flag should be set by ConfigureRequest(). |
| 177 bool bypass_proxy_; | 178 bool bypass_proxy_; |
| 178 | 179 |
| 179 // Number of times that this job has been retried due to ERR_NETWORK_CHANGED. | 180 // Number of times that this job has been retried due to ERR_NETWORK_CHANGED. |
| 180 int retries_count_; | 181 int retries_count_; |
| 181 | 182 |
| 182 // The request context to use for this job. | 183 // The request context to use for this job. |
| 183 net::URLRequestContextGetter* request_context_; | 184 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 184 | 185 |
| 185 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRequestJobImpl); | 186 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRequestJobImpl); |
| 186 }; | 187 }; |
| 187 | 188 |
| 188 DeviceManagementRequestJobImpl::DeviceManagementRequestJobImpl( | 189 DeviceManagementRequestJobImpl::DeviceManagementRequestJobImpl( |
| 189 JobType type, | 190 JobType type, |
| 190 const std::string& agent_parameter, | 191 const std::string& agent_parameter, |
| 191 const std::string& platform_parameter, | 192 const std::string& platform_parameter, |
| 192 DeviceManagementService* service, | 193 DeviceManagementService* service, |
| 193 net::URLRequestContextGetter* request_context) | 194 const scoped_refptr<net::URLRequestContextGetter>& request_context) |
| 194 : DeviceManagementRequestJob(type, agent_parameter, platform_parameter), | 195 : DeviceManagementRequestJob(type, agent_parameter, platform_parameter), |
| 195 service_(service), | 196 service_(service), |
| 196 bypass_proxy_(false), | 197 bypass_proxy_(false), |
| 197 retries_count_(0), | 198 retries_count_(0), |
| 198 request_context_(request_context) {} | 199 request_context_(request_context) { |
| 200 } |
| 199 | 201 |
| 200 DeviceManagementRequestJobImpl::~DeviceManagementRequestJobImpl() { | 202 DeviceManagementRequestJobImpl::~DeviceManagementRequestJobImpl() { |
| 201 service_->RemoveJob(this); | 203 service_->RemoveJob(this); |
| 202 } | 204 } |
| 203 | 205 |
| 204 void DeviceManagementRequestJobImpl::Run() { | 206 void DeviceManagementRequestJobImpl::Run() { |
| 205 service_->AddJob(this); | 207 service_->AddJob(this); |
| 206 } | 208 } |
| 207 | 209 |
| 208 void DeviceManagementRequestJobImpl::HandleResponse( | 210 void DeviceManagementRequestJobImpl::HandleResponse( |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 result += '&'; | 293 result += '&'; |
| 292 result += net::EscapeQueryParamValue(entry->first, true); | 294 result += net::EscapeQueryParamValue(entry->first, true); |
| 293 result += '='; | 295 result += '='; |
| 294 result += net::EscapeQueryParamValue(entry->second, true); | 296 result += net::EscapeQueryParamValue(entry->second, true); |
| 295 } | 297 } |
| 296 return GURL(result); | 298 return GURL(result); |
| 297 } | 299 } |
| 298 | 300 |
| 299 void DeviceManagementRequestJobImpl::ConfigureRequest( | 301 void DeviceManagementRequestJobImpl::ConfigureRequest( |
| 300 net::URLFetcher* fetcher) { | 302 net::URLFetcher* fetcher) { |
| 301 fetcher->SetRequestContext(request_context_); | 303 // TODO(dcheng): It might make sense to make this take a const |
| 304 // scoped_refptr<T>& too eventually. |
| 305 fetcher->SetRequestContext(request_context_.get()); |
| 302 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 306 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 303 net::LOAD_DO_NOT_SAVE_COOKIES | | 307 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 304 net::LOAD_DISABLE_CACHE | | 308 net::LOAD_DISABLE_CACHE | |
| 305 (bypass_proxy_ ? net::LOAD_BYPASS_PROXY : 0)); | 309 (bypass_proxy_ ? net::LOAD_BYPASS_PROXY : 0)); |
| 306 std::string payload; | 310 std::string payload; |
| 307 CHECK(request_.SerializeToString(&payload)); | 311 CHECK(request_.SerializeToString(&payload)); |
| 308 fetcher->SetUploadData(kPostContentType, payload); | 312 fetcher->SetUploadData(kPostContentType, payload); |
| 309 std::string extra_headers; | 313 std::string extra_headers; |
| 310 if (!gaia_token_.empty()) | 314 if (!gaia_token_.empty()) |
| 311 extra_headers += kServiceTokenAuthHeader + gaia_token_ + "\n"; | 315 extra_headers += kServiceTokenAuthHeader + gaia_token_ + "\n"; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 const int DeviceManagementService::kURLFetcherID = 0xde71ce1d; | 410 const int DeviceManagementService::kURLFetcherID = 0xde71ce1d; |
| 407 | 411 |
| 408 DeviceManagementService::~DeviceManagementService() { | 412 DeviceManagementService::~DeviceManagementService() { |
| 409 // All running jobs should have been cancelled by now. | 413 // All running jobs should have been cancelled by now. |
| 410 DCHECK(pending_jobs_.empty()); | 414 DCHECK(pending_jobs_.empty()); |
| 411 DCHECK(queued_jobs_.empty()); | 415 DCHECK(queued_jobs_.empty()); |
| 412 } | 416 } |
| 413 | 417 |
| 414 DeviceManagementRequestJob* DeviceManagementService::CreateJob( | 418 DeviceManagementRequestJob* DeviceManagementService::CreateJob( |
| 415 DeviceManagementRequestJob::JobType type, | 419 DeviceManagementRequestJob::JobType type, |
| 416 net::URLRequestContextGetter* request_context) { | 420 const scoped_refptr<net::URLRequestContextGetter>& request_context) { |
| 417 return new DeviceManagementRequestJobImpl( | 421 return new DeviceManagementRequestJobImpl( |
| 418 type, | 422 type, |
| 419 configuration_->GetAgentParameter(), | 423 configuration_->GetAgentParameter(), |
| 420 configuration_->GetPlatformParameter(), | 424 configuration_->GetPlatformParameter(), |
| 421 this, | 425 this, |
| 422 request_context); | 426 request_context); |
| 423 } | 427 } |
| 424 | 428 |
| 425 void DeviceManagementService::ScheduleInitialization(int64 delay_milliseconds) { | 429 void DeviceManagementService::ScheduleInitialization(int64 delay_milliseconds) { |
| 426 if (initialized_) | 430 if (initialized_) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 } | 520 } |
| 517 } | 521 } |
| 518 | 522 |
| 519 const JobQueue::iterator elem = | 523 const JobQueue::iterator elem = |
| 520 std::find(queued_jobs_.begin(), queued_jobs_.end(), job); | 524 std::find(queued_jobs_.begin(), queued_jobs_.end(), job); |
| 521 if (elem != queued_jobs_.end()) | 525 if (elem != queued_jobs_.end()) |
| 522 queued_jobs_.erase(elem); | 526 queued_jobs_.erase(elem); |
| 523 } | 527 } |
| 524 | 528 |
| 525 } // namespace policy | 529 } // namespace policy |
| OLD | NEW |