Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_POLICY_CLOUD_COMPONENT_CLOUD_POLICY_UPDATER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_COMPONENT_CLOUD_POLICY_UPDATER_H_ |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_COMPONENT_CLOUD_POLICY_UPDATER_H_ | 6 #define CHROME_BROWSER_POLICY_CLOUD_COMPONENT_CLOUD_POLICY_UPDATER_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 9 #include <queue> | |
| 10 | |
| 11 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 12 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 11 #include "chrome/browser/policy/cloud/external_policy_data_updater.h" |
| 15 #include "base/threading/non_thread_safe.h" | |
| 16 #include "chrome/browser/policy/policy_service.h" | |
| 17 | 12 |
| 18 namespace base { | 13 namespace base { |
| 19 class SequencedTaskRunner; | 14 class SequencedTaskRunner; |
| 20 } | 15 } |
| 21 | 16 |
| 22 namespace enterprise_management { | 17 namespace enterprise_management { |
| 23 class PolicyFetchResponse; | 18 class PolicyFetchResponse; |
| 24 } | 19 } |
| 25 | 20 |
| 26 namespace net { | 21 namespace net { |
| 27 class URLRequestContextGetter; | 22 class URLRequestContextGetter; |
| 28 } | 23 } |
| 29 | 24 |
| 30 namespace policy { | 25 namespace policy { |
| 31 | 26 |
| 32 class ComponentCloudPolicyStore; | 27 class ComponentCloudPolicyStore; |
| 33 | 28 |
| 34 // This class downloads external policy data, given PolicyFetchResponses. | 29 // This class downloads external policy data, given PolicyFetchResponses. |
| 35 // It validates the PolicyFetchResponse and its corresponding data, and caches | 30 // It validates the PolicyFetchResponse and its corresponding data, and caches |
| 36 // them in a ComponentCloudPolicyStore. It also enforces size limits on what's | 31 // them in a ComponentCloudPolicyStore. It also enforces size limits on what's |
| 37 // cached. | 32 // cached. |
| 38 // It retries to download the policy data periodically when a download fails. | 33 // It retries to download the policy data periodically when a download fails. |
| 39 class ComponentCloudPolicyUpdater : public base::NonThreadSafe { | 34 class ComponentCloudPolicyUpdater { |
| 40 public: | 35 public: |
| 41 // |task_runner| must support file I/O, and is used to post delayed retry | 36 // |task_runner| must support file I/O, and is used to post delayed retry |
| 42 // tasks. | 37 // tasks. |
| 43 // |request_context| will be used for the download fetchers. | 38 // |request_context| will be used for the download fetchers. |
| 44 // |store| must outlive the updater, and is where the downloaded data will | 39 // |store| must outlive the updater, and is where the downloaded data will |
| 45 // be cached. | 40 // be cached. |
| 46 ComponentCloudPolicyUpdater( | 41 ComponentCloudPolicyUpdater( |
| 47 scoped_refptr<base::SequencedTaskRunner> task_runner, | 42 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 48 scoped_refptr<net::URLRequestContextGetter> request_context, | 43 scoped_refptr<net::URLRequestContextGetter> request_context, |
| 49 ComponentCloudPolicyStore* store); | 44 ComponentCloudPolicyStore* store); |
| 50 ~ComponentCloudPolicyUpdater(); | |
|
Joao da Silva
2013/04/08 14:49:40
Please leave this, even if the impl is empty.
bartfab (slow)
2013/04/08 15:32:12
Done.
| |
| 51 | 45 |
| 52 // |response| is the latest policy information fetched for some component. | 46 // |response| is the latest policy information fetched for some component. |
| 53 // This method schedules the download of the policy data, if |response| is | 47 // This method schedules the download of the policy data, if |response| is |
| 54 // validated. If the downloaded data also passes validation then that data | 48 // validated. If the downloaded data also passes validation then that data |
| 55 // will be passed to the |store_|. | 49 // will be passed to the |store_|. |
| 56 void UpdateExternalPolicy( | 50 void UpdateExternalPolicy( |
| 57 scoped_ptr<enterprise_management::PolicyFetchResponse> response); | 51 scoped_ptr<enterprise_management::PolicyFetchResponse> response); |
| 58 | 52 |
| 59 private: | 53 private: |
| 60 class FetchJob; | |
| 61 typedef std::map<PolicyNamespace, FetchJob*> FetchJobMap; | |
| 62 | |
| 63 // Starts |job| if the job queue is empty, otherwise schedules it. | |
| 64 void ScheduleJob(FetchJob* job); | |
| 65 | |
| 66 // Appends |job| to the |job_queue_|, and starts it immediately if it's the | |
| 67 // only scheduled job. | |
| 68 void StartNextJob(); | |
| 69 | |
| 70 // Callback for jobs that succeeded. | |
| 71 void OnJobSucceeded(FetchJob* job); | |
| 72 | |
| 73 // Callback for jobs that failed. | |
| 74 void OnJobFailed(FetchJob* job); | |
| 75 | |
| 76 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
| 77 scoped_refptr<net::URLRequestContextGetter> request_context_; | |
| 78 ComponentCloudPolicyStore* store_; | 54 ComponentCloudPolicyStore* store_; |
| 79 | 55 ExternalPolicyDataUpdater external_policy_data_updater_; |
| 80 // Map of jobs that have been scheduled and haven't succeeded yet. Failing | |
| 81 // jobs stay in |fetch_jobs_|, and may have retries scheduled in the future. | |
| 82 // This map owns all the currently existing jobs. | |
| 83 FetchJobMap fetch_jobs_; | |
| 84 | |
| 85 // Queue of jobs to start as soon as possible. Each job starts once the | |
| 86 // previous job completes, to avoid starting too many downloads in parallel | |
| 87 // at once. The job at the front of the queue is the currently executing | |
| 88 // job, and will call OnJobSucceeded or OnJobFailed. | |
| 89 std::queue<base::WeakPtr<FetchJob> > job_queue_; | |
| 90 | |
| 91 // True once the destructor enters. Prevents jobs from being scheduled during | |
| 92 // shutdown. | |
| 93 bool shutting_down_; | |
| 94 | 56 |
| 95 DISALLOW_COPY_AND_ASSIGN(ComponentCloudPolicyUpdater); | 57 DISALLOW_COPY_AND_ASSIGN(ComponentCloudPolicyUpdater); |
| 96 }; | 58 }; |
| 97 | 59 |
| 98 } // namespace policy | 60 } // namespace policy |
| 99 | 61 |
| 100 #endif // CHROME_BROWSER_POLICY_CLOUD_COMPONENT_CLOUD_POLICY_UPDATER_H_ | 62 #endif // CHROME_BROWSER_POLICY_CLOUD_COMPONENT_CLOUD_POLICY_UPDATER_H_ |
| OLD | NEW |