OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/external_policy_data_fetcher.h" | 5 #include "components/policy/core/common/cloud/external_policy_data_fetcher.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
9 #include "base/location.h" | 11 #include "base/location.h" |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
11 #include "base/macros.h" | 13 #include "base/macros.h" |
12 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
13 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
14 #include "components/data_use_measurement/core/data_use_user_data.h" | 16 #include "components/data_use_measurement/core/data_use_user_data.h" |
15 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
16 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 Result result, | 135 Result result, |
134 scoped_ptr<std::string> data) { | 136 scoped_ptr<std::string> data) { |
135 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 137 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
136 JobSet::iterator it = jobs_.find(job); | 138 JobSet::iterator it = jobs_.find(job); |
137 if (it == jobs_.end()) { | 139 if (it == jobs_.end()) { |
138 // The |job| has been canceled and removed from |jobs_| already. This can | 140 // The |job| has been canceled and removed from |jobs_| already. This can |
139 // happen because the |backend_| runs on a different thread and a |job| may | 141 // happen because the |backend_| runs on a different thread and a |job| may |
140 // finish before the cancellation has reached that thread. | 142 // finish before the cancellation has reached that thread. |
141 return; | 143 return; |
142 } | 144 } |
143 callback.Run(result, data.Pass()); | 145 callback.Run(result, std::move(data)); |
144 jobs_.erase(it); | 146 jobs_.erase(it); |
145 delete job; | 147 delete job; |
146 } | 148 } |
147 | 149 |
148 ExternalPolicyDataFetcherBackend::ExternalPolicyDataFetcherBackend( | 150 ExternalPolicyDataFetcherBackend::ExternalPolicyDataFetcherBackend( |
149 scoped_refptr<base::SequencedTaskRunner> io_task_runner, | 151 scoped_refptr<base::SequencedTaskRunner> io_task_runner, |
150 scoped_refptr<net::URLRequestContextGetter> request_context) | 152 scoped_refptr<net::URLRequestContextGetter> request_context) |
151 : io_task_runner_(io_task_runner), | 153 : io_task_runner_(io_task_runner), |
152 request_context_(request_context), | 154 request_context_(request_context), |
153 last_fetch_id_(-1), | 155 last_fetch_id_(-1), |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 if (static_cast<int64_t>(data->size()) > it->second->max_size) { | 236 if (static_cast<int64_t>(data->size()) > it->second->max_size) { |
235 // Received |data| exceeds maximum allowed size. | 237 // Received |data| exceeds maximum allowed size. |
236 data.reset(); | 238 data.reset(); |
237 result = ExternalPolicyDataFetcher::MAX_SIZE_EXCEEDED; | 239 result = ExternalPolicyDataFetcher::MAX_SIZE_EXCEEDED; |
238 } | 240 } |
239 } | 241 } |
240 | 242 |
241 ExternalPolicyDataFetcher::Job* job = it->second; | 243 ExternalPolicyDataFetcher::Job* job = it->second; |
242 delete it->first; | 244 delete it->first; |
243 job_map_.erase(it); | 245 job_map_.erase(it); |
244 job->callback.Run(job, result, data.Pass()); | 246 job->callback.Run(job, result, std::move(data)); |
245 } | 247 } |
246 | 248 |
247 void ExternalPolicyDataFetcherBackend::OnURLFetchDownloadProgress( | 249 void ExternalPolicyDataFetcherBackend::OnURLFetchDownloadProgress( |
248 const net::URLFetcher* source, | 250 const net::URLFetcher* source, |
249 int64_t current, | 251 int64_t current, |
250 int64_t total) { | 252 int64_t total) { |
251 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 253 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
252 JobMap::iterator it = job_map_.find(const_cast<net::URLFetcher*>(source)); | 254 JobMap::iterator it = job_map_.find(const_cast<net::URLFetcher*>(source)); |
253 DCHECK(it != job_map_.end()); | 255 DCHECK(it != job_map_.end()); |
254 if (it == job_map_.end()) | 256 if (it == job_map_.end()) |
255 return; | 257 return; |
256 | 258 |
257 // Reject the data if it exceeds the size limit. The content length is in | 259 // Reject the data if it exceeds the size limit. The content length is in |
258 // |total|, and it may be -1 when not known. | 260 // |total|, and it may be -1 when not known. |
259 if (current > it->second->max_size || total > it->second->max_size) { | 261 if (current > it->second->max_size || total > it->second->max_size) { |
260 ExternalPolicyDataFetcher::Job* job = it->second; | 262 ExternalPolicyDataFetcher::Job* job = it->second; |
261 delete it->first; | 263 delete it->first; |
262 job_map_.erase(it); | 264 job_map_.erase(it); |
263 job->callback.Run(job, | 265 job->callback.Run(job, |
264 ExternalPolicyDataFetcher::MAX_SIZE_EXCEEDED, | 266 ExternalPolicyDataFetcher::MAX_SIZE_EXCEEDED, |
265 scoped_ptr<std::string>()); | 267 scoped_ptr<std::string>()); |
266 } | 268 } |
267 } | 269 } |
268 | 270 |
269 } // namespace policy | 271 } // namespace policy |
OLD | NEW |