| 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" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 JobType type, | 161 JobType type, |
| 162 const std::string& agent_parameter, | 162 const std::string& agent_parameter, |
| 163 const std::string& platform_parameter, | 163 const std::string& platform_parameter, |
| 164 DeviceManagementService* service, | 164 DeviceManagementService* service, |
| 165 const scoped_refptr<net::URLRequestContextGetter>& request_context); | 165 const scoped_refptr<net::URLRequestContextGetter>& request_context); |
| 166 ~DeviceManagementRequestJobImpl() override; | 166 ~DeviceManagementRequestJobImpl() override; |
| 167 | 167 |
| 168 // Handles the URL request response. | 168 // Handles the URL request response. |
| 169 void HandleResponse(const net::URLRequestStatus& status, | 169 void HandleResponse(const net::URLRequestStatus& status, |
| 170 int response_code, | 170 int response_code, |
| 171 const net::ResponseCookies& cookies, | |
| 172 const std::string& data); | 171 const std::string& data); |
| 173 | 172 |
| 174 // Gets the URL to contact. | 173 // Gets the URL to contact. |
| 175 GURL GetURL(const std::string& server_url); | 174 GURL GetURL(const std::string& server_url); |
| 176 | 175 |
| 177 // Configures the fetcher, setting up payload and headers. | 176 // Configures the fetcher, setting up payload and headers. |
| 178 void ConfigureRequest(net::URLFetcher* fetcher); | 177 void ConfigureRequest(net::URLFetcher* fetcher); |
| 179 | 178 |
| 180 // Returns true if this job should be retried. |fetcher| has just completed, | 179 // Returns true if this job should be retried. |fetcher| has just completed, |
| 181 // and can be inspected to determine if the request failed and should be | 180 // and can be inspected to determine if the request failed and should be |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 service_->RemoveJob(this); | 235 service_->RemoveJob(this); |
| 237 } | 236 } |
| 238 | 237 |
| 239 void DeviceManagementRequestJobImpl::Run() { | 238 void DeviceManagementRequestJobImpl::Run() { |
| 240 service_->AddJob(this); | 239 service_->AddJob(this); |
| 241 } | 240 } |
| 242 | 241 |
| 243 void DeviceManagementRequestJobImpl::HandleResponse( | 242 void DeviceManagementRequestJobImpl::HandleResponse( |
| 244 const net::URLRequestStatus& status, | 243 const net::URLRequestStatus& status, |
| 245 int response_code, | 244 int response_code, |
| 246 const net::ResponseCookies& cookies, | |
| 247 const std::string& data) { | 245 const std::string& data) { |
| 248 if (status.status() != net::URLRequestStatus::SUCCESS) { | 246 if (status.status() != net::URLRequestStatus::SUCCESS) { |
| 249 LOG(WARNING) << "DMServer request failed, status: " << status.status() | 247 LOG(WARNING) << "DMServer request failed, status: " << status.status() |
| 250 << ", error: " << status.error(); | 248 << ", error: " << status.error(); |
| 251 em::DeviceManagementResponse dummy_response; | 249 em::DeviceManagementResponse dummy_response; |
| 252 callback_.Run(DM_STATUS_REQUEST_FAILED, status.error(), dummy_response); | 250 callback_.Run(DM_STATUS_REQUEST_FAILED, status.error(), dummy_response); |
| 253 return; | 251 return; |
| 254 } | 252 } |
| 255 | 253 |
| 256 if (response_code != kSuccess) | 254 if (response_code != kSuccess) |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 LOG(WARNING) << "Dmserver request failed, retrying in " << delay / 1000 | 548 LOG(WARNING) << "Dmserver request failed, retrying in " << delay / 1000 |
| 551 << "s."; | 549 << "s."; |
| 552 task_runner_->PostDelayedTask( | 550 task_runner_->PostDelayedTask( |
| 553 FROM_HERE, | 551 FROM_HERE, |
| 554 base::Bind(&DeviceManagementService::StartJobAfterDelay, | 552 base::Bind(&DeviceManagementService::StartJobAfterDelay, |
| 555 weak_ptr_factory_.GetWeakPtr(), job->GetWeakPtr()), | 553 weak_ptr_factory_.GetWeakPtr(), job->GetWeakPtr()), |
| 556 base::TimeDelta::FromMilliseconds(delay)); | 554 base::TimeDelta::FromMilliseconds(delay)); |
| 557 } else { | 555 } else { |
| 558 std::string data; | 556 std::string data; |
| 559 source->GetResponseAsString(&data); | 557 source->GetResponseAsString(&data); |
| 560 job->HandleResponse(source->GetStatus(), source->GetResponseCode(), | 558 job->HandleResponse(source->GetStatus(), source->GetResponseCode(), data); |
| 561 source->GetCookies(), data); | |
| 562 } | 559 } |
| 563 delete source; | 560 delete source; |
| 564 } | 561 } |
| 565 | 562 |
| 566 void DeviceManagementService::AddJob(DeviceManagementRequestJobImpl* job) { | 563 void DeviceManagementService::AddJob(DeviceManagementRequestJobImpl* job) { |
| 567 if (initialized_) | 564 if (initialized_) |
| 568 StartJob(job); | 565 StartJob(job); |
| 569 else | 566 else |
| 570 queued_jobs_.push_back(job); | 567 queued_jobs_.push_back(job); |
| 571 } | 568 } |
| 572 | 569 |
| 573 void DeviceManagementService::RemoveJob(DeviceManagementRequestJobImpl* job) { | 570 void DeviceManagementService::RemoveJob(DeviceManagementRequestJobImpl* job) { |
| 574 for (JobFetcherMap::iterator entry(pending_jobs_.begin()); | 571 for (JobFetcherMap::iterator entry(pending_jobs_.begin()); |
| 575 entry != pending_jobs_.end(); | 572 entry != pending_jobs_.end(); |
| 576 ++entry) { | 573 ++entry) { |
| 577 if (entry->second == job) { | 574 if (entry->second == job) { |
| 578 delete entry->first; | 575 delete entry->first; |
| 579 pending_jobs_.erase(entry); | 576 pending_jobs_.erase(entry); |
| 580 return; | 577 return; |
| 581 } | 578 } |
| 582 } | 579 } |
| 583 | 580 |
| 584 const JobQueue::iterator elem = | 581 const JobQueue::iterator elem = |
| 585 std::find(queued_jobs_.begin(), queued_jobs_.end(), job); | 582 std::find(queued_jobs_.begin(), queued_jobs_.end(), job); |
| 586 if (elem != queued_jobs_.end()) | 583 if (elem != queued_jobs_.end()) |
| 587 queued_jobs_.erase(elem); | 584 queued_jobs_.erase(elem); |
| 588 } | 585 } |
| 589 | 586 |
| 590 } // namespace policy | 587 } // namespace policy |
| OLD | NEW |