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

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

Issue 11299305: Break CloudPolicyRefreshScheduler's dependency on PrefService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review feedback Created 8 years 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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_POLICY_REFRESH_SCHEDULER_H_ 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_REFRESH_SCHEDULER_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_REFRESH_SCHEDULER_H_ 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_REFRESH_SCHEDULER_H_
7 7
8 #include <string>
9
10 #include "base/basictypes.h" 8 #include "base/basictypes.h"
11 #include "base/cancelable_callback.h" 9 #include "base/cancelable_callback.h"
12 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
13 #include "base/time.h" 11 #include "base/time.h"
14 #include "chrome/browser/api/prefs/pref_member.h"
15 #include "chrome/browser/policy/cloud_policy_client.h" 12 #include "chrome/browser/policy/cloud_policy_client.h"
16 #include "chrome/browser/policy/cloud_policy_store.h" 13 #include "chrome/browser/policy/cloud_policy_store.h"
17 #include "net/base/network_change_notifier.h" 14 #include "net/base/network_change_notifier.h"
18 15
19 class PrefService;
20
21 namespace base { 16 namespace base {
22 class TaskRunner; 17 class TaskRunner;
23 } 18 }
24 19
25 namespace policy { 20 namespace policy {
26 21
27 // Observes CloudPolicyClient and CloudPolicyStore to trigger periodic policy 22 // Observes CloudPolicyClient and CloudPolicyStore to trigger periodic policy
28 // fetches and issue retries on error conditions. 23 // fetches and issue retries on error conditions.
29 class CloudPolicyRefreshScheduler 24 class CloudPolicyRefreshScheduler
30 : public CloudPolicyClient::Observer, 25 : public CloudPolicyClient::Observer,
31 public CloudPolicyStore::Observer, 26 public CloudPolicyStore::Observer,
32 public net::NetworkChangeNotifier::IPAddressObserver { 27 public net::NetworkChangeNotifier::IPAddressObserver {
33 public: 28 public:
34 // Refresh constants. 29 // Refresh constants.
30 static const int64 kDefaultRefreshDelayMs;
35 static const int64 kUnmanagedRefreshDelayMs; 31 static const int64 kUnmanagedRefreshDelayMs;
36 static const int64 kInitialErrorRetryDelayMs; 32 static const int64 kInitialErrorRetryDelayMs;
37 33
38 // Refresh delay bounds. 34 // Refresh delay bounds.
39 static const int64 kRefreshDelayMinMs; 35 static const int64 kRefreshDelayMinMs;
40 static const int64 kRefreshDelayMaxMs; 36 static const int64 kRefreshDelayMaxMs;
41 37
42 // |client|, |store| and |prefs| pointers must stay valid throughout the 38 // |client|, |store| and |prefs| pointers must stay valid throughout the
43 // lifetime of CloudPolicyRefreshScheduler. 39 // lifetime of CloudPolicyRefreshScheduler.
44 CloudPolicyRefreshScheduler( 40 CloudPolicyRefreshScheduler(
45 CloudPolicyClient* client, 41 CloudPolicyClient* client,
46 CloudPolicyStore* store, 42 CloudPolicyStore* store,
47 PrefService* prefs,
48 const std::string& refresh_pref,
49 const scoped_refptr<base::TaskRunner>& task_runner); 43 const scoped_refptr<base::TaskRunner>& task_runner);
50 virtual ~CloudPolicyRefreshScheduler(); 44 virtual ~CloudPolicyRefreshScheduler();
51 45
46 // Sets the refresh delay to |refresh_delay| (subject to min/max clamping).
47 void SetRefreshDelay(int64 refresh_delay);
48
52 // CloudPolicyClient::Observer: 49 // CloudPolicyClient::Observer:
53 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; 50 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE;
54 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; 51 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE;
55 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; 52 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE;
56 53
57 // CloudPolicyStore::Observer: 54 // CloudPolicyStore::Observer:
58 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; 55 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE;
59 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; 56 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE;
60 57
61 // net::NetworkChangeNotifier::IPAddressObserver: 58 // net::NetworkChangeNotifier::IPAddressObserver:
(...skipping 11 matching lines...) Expand all
73 // execute that refresh at the appropriate time. 70 // execute that refresh at the appropriate time.
74 void ScheduleRefresh(); 71 void ScheduleRefresh();
75 72
76 // Triggers a policy refresh. 73 // Triggers a policy refresh.
77 void PerformRefresh(); 74 void PerformRefresh();
78 75
79 // Schedules a policy refresh to happen after |delta_ms| milliseconds, 76 // Schedules a policy refresh to happen after |delta_ms| milliseconds,
80 // relative to |last_refresh_|. 77 // relative to |last_refresh_|.
81 void RefreshAfter(int delta_ms); 78 void RefreshAfter(int delta_ms);
82 79
83 // Gets the refresh delay in milliseconds, clamped to the allowed bounds.
84 int64 GetRefreshDelay();
85
86 CloudPolicyClient* client_; 80 CloudPolicyClient* client_;
87 CloudPolicyStore* store_; 81 CloudPolicyStore* store_;
88 82
89 // For scheduling delayed tasks. 83 // For scheduling delayed tasks.
90 const scoped_refptr<base::TaskRunner> task_runner_; 84 const scoped_refptr<base::TaskRunner> task_runner_;
91 85
92 // The delayed refresh callback. 86 // The delayed refresh callback.
93 base::CancelableClosure refresh_callback_; 87 base::CancelableClosure refresh_callback_;
94 88
95 // The last time a refresh callback completed. 89 // The last time a refresh callback completed.
96 base::Time last_refresh_; 90 base::Time last_refresh_;
97 91
98 // Error retry delay in milliseconds. 92 // Error retry delay in milliseconds.
99 int64 error_retry_delay_ms_; 93 int64 error_retry_delay_ms_;
100 94
101 IntegerPrefMember refresh_delay_; 95 // The refresh delay.
96 int64 refresh_delay_ms_;
102 97
103 DISALLOW_COPY_AND_ASSIGN(CloudPolicyRefreshScheduler); 98 DISALLOW_COPY_AND_ASSIGN(CloudPolicyRefreshScheduler);
104 }; 99 };
105 100
106 } // namespace policy 101 } // namespace policy
107 102
108 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_REFRESH_SCHEDULER_H_ 103 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_REFRESH_SCHEDULER_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_manager.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