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

Side by Side Diff: chrome/browser/policy/cloud_policy_refresh_scheduler.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) 2012 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_CLOUD_POLICY_REFRESH_SCHEDULER_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_REFRESH_SCHEDULER_H_
7
8 #include "base/basictypes.h"
9 #include "base/cancelable_callback.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/time.h"
12 #include "chrome/browser/policy/cloud_policy_client.h"
13 #include "chrome/browser/policy/cloud_policy_store.h"
14 #include "chrome/browser/policy/rate_limiter.h"
15 #include "net/base/network_change_notifier.h"
16
17 namespace base {
18 class SequencedTaskRunner;
19 }
20
21 namespace policy {
22
23 // Observes CloudPolicyClient and CloudPolicyStore to trigger periodic policy
24 // fetches and issue retries on error conditions.
25 class CloudPolicyRefreshScheduler
26 : public CloudPolicyClient::Observer,
27 public CloudPolicyStore::Observer,
28 public net::NetworkChangeNotifier::IPAddressObserver {
29 public:
30 // Refresh constants.
31 static const int64 kDefaultRefreshDelayMs;
32 static const int64 kUnmanagedRefreshDelayMs;
33 static const int64 kInitialErrorRetryDelayMs;
34
35 // Refresh delay bounds.
36 static const int64 kRefreshDelayMinMs;
37 static const int64 kRefreshDelayMaxMs;
38
39 // |client|, |store| and |prefs| pointers must stay valid throughout the
40 // lifetime of CloudPolicyRefreshScheduler.
41 CloudPolicyRefreshScheduler(
42 CloudPolicyClient* client,
43 CloudPolicyStore* store,
44 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
45 virtual ~CloudPolicyRefreshScheduler();
46
47 base::Time last_refresh() const { return last_refresh_; }
48 int64 refresh_delay() const { return refresh_delay_ms_; }
49
50 // Sets the refresh delay to |refresh_delay| (subject to min/max clamping).
51 void SetRefreshDelay(int64 refresh_delay);
52
53 // Requests a policy refresh to be performed soon. This may apply throttling,
54 // and the request may not be immediately sent.
55 void RefreshSoon();
56
57 // CloudPolicyClient::Observer:
58 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE;
59 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE;
60 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE;
61
62 // CloudPolicyStore::Observer:
63 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE;
64 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE;
65
66 // net::NetworkChangeNotifier::IPAddressObserver:
67 virtual void OnIPAddressChanged() OVERRIDE;
68
69 private:
70 // Initializes |last_refresh_| to the policy timestamp from |store_| in case
71 // there is policy present that indicates this client is not managed. This
72 // results in policy fetches only to occur after the entire unmanaged refresh
73 // delay expires, even over restarts. For managed clients, we want to trigger
74 // a refresh on every restart.
75 void UpdateLastRefreshFromPolicy();
76
77 // Schedules a refresh to be performed immediately.
78 void RefreshNow();
79
80 // Evaluates when the next refresh is pending and updates the callback to
81 // execute that refresh at the appropriate time.
82 void ScheduleRefresh();
83
84 // Triggers a policy refresh.
85 void PerformRefresh();
86
87 // Schedules a policy refresh to happen after |delta_ms| milliseconds,
88 // relative to |last_refresh_|.
89 void RefreshAfter(int delta_ms);
90
91 CloudPolicyClient* client_;
92 CloudPolicyStore* store_;
93
94 // For scheduling delayed tasks.
95 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
96
97 // The delayed refresh callback.
98 base::CancelableClosure refresh_callback_;
99
100 // The last time a refresh callback completed.
101 base::Time last_refresh_;
102
103 // Error retry delay in milliseconds.
104 int64 error_retry_delay_ms_;
105
106 // The refresh delay.
107 int64 refresh_delay_ms_;
108
109 // Used to limit the rate at which refreshes are scheduled.
110 RateLimiter rate_limiter_;
111
112 DISALLOW_COPY_AND_ASSIGN(CloudPolicyRefreshScheduler);
113 };
114
115 } // namespace policy
116
117 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_REFRESH_SCHEDULER_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_manager_unittest.cc ('k') | chrome/browser/policy/cloud_policy_refresh_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698