OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/browser/policy/cloud/external_policy_data_updater.h" | 5 #include "chrome/browser/policy/cloud/external_policy_data_updater.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 size_t max_parallel_fetches) | 297 size_t max_parallel_fetches) |
298 : task_runner_(task_runner), | 298 : task_runner_(task_runner), |
299 external_policy_data_fetcher_(external_policy_data_fetcher.release()), | 299 external_policy_data_fetcher_(external_policy_data_fetcher.release()), |
300 max_parallel_jobs_(max_parallel_fetches), | 300 max_parallel_jobs_(max_parallel_fetches), |
301 running_jobs_(0), | 301 running_jobs_(0), |
302 shutting_down_(false) { | 302 shutting_down_(false) { |
303 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 303 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
304 } | 304 } |
305 | 305 |
306 ExternalPolicyDataUpdater::~ExternalPolicyDataUpdater() { | 306 ExternalPolicyDataUpdater::~ExternalPolicyDataUpdater() { |
307 DCHECK(CalledOnValidThread()); | 307 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
308 shutting_down_ = true; | 308 shutting_down_ = true; |
309 STLDeleteValues(&job_map_); | 309 STLDeleteValues(&job_map_); |
310 } | 310 } |
311 | 311 |
312 void ExternalPolicyDataUpdater::FetchExternalData( | 312 void ExternalPolicyDataUpdater::FetchExternalData( |
313 const std::string key, | 313 const std::string key, |
314 const Request& request, | 314 const Request& request, |
315 const FetchSuccessCallback& callback) { | 315 const FetchSuccessCallback& callback) { |
316 DCHECK(CalledOnValidThread()); | 316 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
317 | 317 |
318 // Check whether a job exists for this |key| already. | 318 // Check whether a job exists for this |key| already. |
319 FetchJob* job = job_map_[key]; | 319 FetchJob* job = job_map_[key]; |
320 if (job) { | 320 if (job) { |
321 // If the current |job| is handling the given |request| already, nothing | 321 // If the current |job| is handling the given |request| already, nothing |
322 // needs to be done. | 322 // needs to be done. |
323 if (job->request() == request) | 323 if (job->request() == request) |
324 return; | 324 return; |
325 | 325 |
326 // Otherwise, the current |job| is obsolete. If the |job| is on the queue, | 326 // Otherwise, the current |job| is obsolete. If the |job| is on the queue, |
327 // its WeakPtr will be invalidated and skipped by StartNextJobs(). If |job| | 327 // its WeakPtr will be invalidated and skipped by StartNextJobs(). If |job| |
328 // is currently running, it will call OnJobFailed() immediately. | 328 // is currently running, it will call OnJobFailed() immediately. |
329 delete job; | 329 delete job; |
330 job_map_.erase(key); | 330 job_map_.erase(key); |
331 } | 331 } |
332 | 332 |
333 // Start a new job to handle |request|. | 333 // Start a new job to handle |request|. |
334 job = new FetchJob(this, key, request, callback); | 334 job = new FetchJob(this, key, request, callback); |
335 job_map_[key] = job; | 335 job_map_[key] = job; |
336 ScheduleJob(job); | 336 ScheduleJob(job); |
337 } | 337 } |
338 | 338 |
339 void ExternalPolicyDataUpdater::CancelExternalDataFetch( | 339 void ExternalPolicyDataUpdater::CancelExternalDataFetch( |
340 const std::string& key) { | 340 const std::string& key) { |
341 DCHECK(CalledOnValidThread()); | 341 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
342 | 342 |
343 // If a |job| exists for this |key|, delete it. If the |job| is on the queue, | 343 // If a |job| exists for this |key|, delete it. If the |job| is on the queue, |
344 // its WeakPtr will be invalidated and skipped by StartNextJobs(). If |job| is | 344 // its WeakPtr will be invalidated and skipped by StartNextJobs(). If |job| is |
345 // currently running, it will call OnJobFailed() immediately. | 345 // currently running, it will call OnJobFailed() immediately. |
346 std::map<std::string, FetchJob*>::iterator job = job_map_.find(key); | 346 std::map<std::string, FetchJob*>::iterator job = job_map_.find(key); |
347 if (job != job_map_.end()) { | 347 if (job != job_map_.end()) { |
348 delete job->second; | 348 delete job->second; |
349 job_map_.erase(job); | 349 job_map_.erase(job); |
350 } | 350 } |
351 } | 351 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 DCHECK_EQ(job_map_[job->key()], job); | 391 DCHECK_EQ(job_map_[job->key()], job); |
392 | 392 |
393 --running_jobs_; | 393 --running_jobs_; |
394 | 394 |
395 // The job is not deleted when it fails because a retry attempt may have been | 395 // The job is not deleted when it fails because a retry attempt may have been |
396 // scheduled. | 396 // scheduled. |
397 StartNextJobs(); | 397 StartNextJobs(); |
398 } | 398 } |
399 | 399 |
400 } // namespace policy | 400 } // namespace policy |
OLD | NEW |