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

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

Issue 12189011: Split up chrome/browser/policy subdirectory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, add chrome/browser/chromeos/policy/OWNERS Created 7 years, 9 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_POLICY_COMPONENT_CLOUD_POLICY_UPDATER_H_
6 #define CHROME_BROWSER_POLICY_COMPONENT_CLOUD_POLICY_UPDATER_H_
7
8 #include <map>
9 #include <queue>
10
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/threading/non_thread_safe.h"
16 #include "chrome/browser/policy/policy_service.h"
17
18 namespace base {
19 class SequencedTaskRunner;
20 }
21
22 namespace enterprise_management {
23 class PolicyFetchResponse;
24 }
25
26 namespace net {
27 class URLRequestContextGetter;
28 }
29
30 namespace policy {
31
32 class ComponentCloudPolicyStore;
33
34 // This class downloads external policy data, given PolicyFetchResponses.
35 // It validates the PolicyFetchResponse and its corresponding data, and caches
36 // them in a ComponentCloudPolicyStore. It also enforces size limits on what's
37 // cached.
38 // It retries to download the policy data periodically when a download fails.
39 class ComponentCloudPolicyUpdater : public base::NonThreadSafe {
40 public:
41 // |task_runner| must support file I/O, and is used to post delayed retry
42 // tasks.
43 // |request_context| will be used for the download fetchers.
44 // |store| must outlive the updater, and is where the downloaded data will
45 // be cached.
46 ComponentCloudPolicyUpdater(
47 scoped_refptr<base::SequencedTaskRunner> task_runner,
48 scoped_refptr<net::URLRequestContextGetter> request_context,
49 ComponentCloudPolicyStore* store);
50 ~ComponentCloudPolicyUpdater();
51
52 // |response| is the latest policy information fetched for some component.
53 // This method schedules the download of the policy data, if |response| is
54 // validated. If the downloaded data also passes validation then that data
55 // will be passed to the |store_|.
56 void UpdateExternalPolicy(
57 scoped_ptr<enterprise_management::PolicyFetchResponse> response);
58
59 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_;
79
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
95 DISALLOW_COPY_AND_ASSIGN(ComponentCloudPolicyUpdater);
96 };
97
98 } // namespace policy
99
100 #endif // CHROME_BROWSER_POLICY_COMPONENT_CLOUD_POLICY_UPDATER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698