| 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 "components/policy/core/common/cloud/external_policy_data_updater.h" | 5 #include "components/policy/core/common/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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 | 293 |
| 294 ExternalPolicyDataUpdater::ExternalPolicyDataUpdater( | 294 ExternalPolicyDataUpdater::ExternalPolicyDataUpdater( |
| 295 scoped_refptr<base::SequencedTaskRunner> task_runner, | 295 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 296 std::unique_ptr<ExternalPolicyDataFetcher> external_policy_data_fetcher, | 296 std::unique_ptr<ExternalPolicyDataFetcher> external_policy_data_fetcher, |
| 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_->RunsTasksInCurrentSequence()); |
| 304 } | 304 } |
| 305 | 305 |
| 306 ExternalPolicyDataUpdater::~ExternalPolicyDataUpdater() { | 306 ExternalPolicyDataUpdater::~ExternalPolicyDataUpdater() { |
| 307 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 307 DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
| 308 shutting_down_ = true; | 308 shutting_down_ = true; |
| 309 } | 309 } |
| 310 | 310 |
| 311 void ExternalPolicyDataUpdater::FetchExternalData( | 311 void ExternalPolicyDataUpdater::FetchExternalData( |
| 312 const std::string key, | 312 const std::string key, |
| 313 const Request& request, | 313 const Request& request, |
| 314 const FetchSuccessCallback& callback) { | 314 const FetchSuccessCallback& callback) { |
| 315 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 315 DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
| 316 | 316 |
| 317 // Check whether a job exists for this |key| already. | 317 // Check whether a job exists for this |key| already. |
| 318 FetchJob* job = job_map_[key].get(); | 318 FetchJob* job = job_map_[key].get(); |
| 319 if (job) { | 319 if (job) { |
| 320 // If the current |job| is handling the given |request| already, nothing | 320 // If the current |job| is handling the given |request| already, nothing |
| 321 // needs to be done. | 321 // needs to be done. |
| 322 if (job->request() == request) | 322 if (job->request() == request) |
| 323 return; | 323 return; |
| 324 | 324 |
| 325 // Otherwise, the current |job| is obsolete. If the |job| is on the queue, | 325 // Otherwise, the current |job| is obsolete. If the |job| is on the queue, |
| 326 // its WeakPtr will be invalidated and skipped by StartNextJobs(). If |job| | 326 // its WeakPtr will be invalidated and skipped by StartNextJobs(). If |job| |
| 327 // is currently running, it will call OnJobFailed() immediately. | 327 // is currently running, it will call OnJobFailed() immediately. |
| 328 job_map_.erase(key); | 328 job_map_.erase(key); |
| 329 } | 329 } |
| 330 | 330 |
| 331 // Start a new job to handle |request|. | 331 // Start a new job to handle |request|. |
| 332 job = new FetchJob(this, key, request, callback); | 332 job = new FetchJob(this, key, request, callback); |
| 333 job_map_[key] = base::WrapUnique(job); | 333 job_map_[key] = base::WrapUnique(job); |
| 334 ScheduleJob(job); | 334 ScheduleJob(job); |
| 335 } | 335 } |
| 336 | 336 |
| 337 void ExternalPolicyDataUpdater::CancelExternalDataFetch( | 337 void ExternalPolicyDataUpdater::CancelExternalDataFetch( |
| 338 const std::string& key) { | 338 const std::string& key) { |
| 339 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 339 DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
| 340 | 340 |
| 341 // If a |job| exists for this |key|, delete it. If the |job| is on the queue, | 341 // If a |job| exists for this |key|, delete it. If the |job| is on the queue, |
| 342 // its WeakPtr will be invalidated and skipped by StartNextJobs(). If |job| is | 342 // its WeakPtr will be invalidated and skipped by StartNextJobs(). If |job| is |
| 343 // currently running, it will call OnJobFailed() immediately. | 343 // currently running, it will call OnJobFailed() immediately. |
| 344 auto job = job_map_.find(key); | 344 auto job = job_map_.find(key); |
| 345 if (job != job_map_.end()) | 345 if (job != job_map_.end()) |
| 346 job_map_.erase(job); | 346 job_map_.erase(job); |
| 347 } | 347 } |
| 348 | 348 |
| 349 void ExternalPolicyDataUpdater::StartNextJobs() { | 349 void ExternalPolicyDataUpdater::StartNextJobs() { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 387 |
| 388 // Don't touch job_map_; deletion of FetchJobs cause a call to this method, so | 388 // Don't touch job_map_; deletion of FetchJobs cause a call to this method, so |
| 389 // job_map_ is possibly in an inconsistent state. | 389 // job_map_ is possibly in an inconsistent state. |
| 390 | 390 |
| 391 // The job is not deleted when it fails because a retry attempt may have been | 391 // The job is not deleted when it fails because a retry attempt may have been |
| 392 // scheduled. | 392 // scheduled. |
| 393 StartNextJobs(); | 393 StartNextJobs(); |
| 394 } | 394 } |
| 395 | 395 |
| 396 } // namespace policy | 396 } // namespace policy |
| OLD | NEW |