Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/browser/policy/cloud/component_cloud_policy_updater.h

Issue 13792003: Switch ComponentCloudPolicyUpdater to ExternalPolicyDataUpdater backend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed copy&paste mistake that tripped up clang. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/policy/cloud/component_cloud_policy_updater.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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(); 45 ~ComponentCloudPolicyUpdater();
51 46
52 // |response| is the latest policy information fetched for some component. 47 // |response| is the latest policy information fetched for some component.
53 // This method schedules the download of the policy data, if |response| is 48 // This method schedules the download of the policy data, if |response| is
54 // validated. If the downloaded data also passes validation then that data 49 // validated. If the downloaded data also passes validation then that data
55 // will be passed to the |store_|. 50 // will be passed to the |store_|.
56 void UpdateExternalPolicy( 51 void UpdateExternalPolicy(
57 scoped_ptr<enterprise_management::PolicyFetchResponse> response); 52 scoped_ptr<enterprise_management::PolicyFetchResponse> response);
58 53
59 private: 54 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_; 55 ComponentCloudPolicyStore* store_;
79 56 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 57
95 DISALLOW_COPY_AND_ASSIGN(ComponentCloudPolicyUpdater); 58 DISALLOW_COPY_AND_ASSIGN(ComponentCloudPolicyUpdater);
96 }; 59 };
97 60
98 } // namespace policy 61 } // namespace policy
99 62
100 #endif // CHROME_BROWSER_POLICY_CLOUD_COMPONENT_CLOUD_POLICY_UPDATER_H_ 63 #endif // CHROME_BROWSER_POLICY_CLOUD_COMPONENT_CLOUD_POLICY_UPDATER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/policy/cloud/component_cloud_policy_updater.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698