OLD | NEW |
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> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/cancelable_callback.h" | 11 #include "base/cancelable_callback.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/prefs/public/pref_observer.h" |
13 #include "base/time.h" | 14 #include "base/time.h" |
14 #include "chrome/browser/api/prefs/pref_member.h" | 15 #include "chrome/browser/api/prefs/pref_member.h" |
15 #include "chrome/browser/policy/cloud_policy_client.h" | 16 #include "chrome/browser/policy/cloud_policy_client.h" |
16 #include "chrome/browser/policy/cloud_policy_store.h" | 17 #include "chrome/browser/policy/cloud_policy_store.h" |
17 #include "content/public/browser/notification_observer.h" | |
18 #include "net/base/network_change_notifier.h" | 18 #include "net/base/network_change_notifier.h" |
19 | 19 |
20 class PrefService; | 20 class PrefService; |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 class TaskRunner; | 23 class TaskRunner; |
24 } | 24 } |
25 | 25 |
26 namespace policy { | 26 namespace policy { |
27 | 27 |
28 // Observes CloudPolicyClient and CloudPolicyStore to trigger periodic policy | 28 // Observes CloudPolicyClient and CloudPolicyStore to trigger periodic policy |
29 // fetches and issue retries on error conditions. | 29 // fetches and issue retries on error conditions. |
30 class CloudPolicyRefreshScheduler | 30 class CloudPolicyRefreshScheduler |
31 : public CloudPolicyClient::Observer, | 31 : public CloudPolicyClient::Observer, |
32 public CloudPolicyStore::Observer, | 32 public CloudPolicyStore::Observer, |
33 public content::NotificationObserver, | 33 public PrefObserver, |
34 public net::NetworkChangeNotifier::IPAddressObserver { | 34 public net::NetworkChangeNotifier::IPAddressObserver { |
35 public: | 35 public: |
36 // Refresh constants. | 36 // Refresh constants. |
37 static const int64 kUnmanagedRefreshDelayMs; | 37 static const int64 kUnmanagedRefreshDelayMs; |
38 static const int64 kInitialErrorRetryDelayMs; | 38 static const int64 kInitialErrorRetryDelayMs; |
39 | 39 |
40 // Refresh delay bounds. | 40 // Refresh delay bounds. |
41 static const int64 kRefreshDelayMinMs; | 41 static const int64 kRefreshDelayMinMs; |
42 static const int64 kRefreshDelayMaxMs; | 42 static const int64 kRefreshDelayMaxMs; |
43 | 43 |
44 // |client|, |store| and |prefs| pointers must stay valid throughout the | 44 // |client|, |store| and |prefs| pointers must stay valid throughout the |
45 // lifetime of CloudPolicyRefreshScheduler. | 45 // lifetime of CloudPolicyRefreshScheduler. |
46 CloudPolicyRefreshScheduler( | 46 CloudPolicyRefreshScheduler( |
47 CloudPolicyClient* client, | 47 CloudPolicyClient* client, |
48 CloudPolicyStore* store, | 48 CloudPolicyStore* store, |
49 PrefService* prefs, | 49 PrefService* prefs, |
50 const std::string& refresh_pref, | 50 const std::string& refresh_pref, |
51 const scoped_refptr<base::TaskRunner>& task_runner); | 51 const scoped_refptr<base::TaskRunner>& task_runner); |
52 virtual ~CloudPolicyRefreshScheduler(); | 52 virtual ~CloudPolicyRefreshScheduler(); |
53 | 53 |
54 // CloudPolicyClient::Observer: | 54 // CloudPolicyClient::Observer: |
55 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; | 55 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; |
56 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; | 56 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; |
57 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; | 57 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; |
58 | 58 |
59 // CloudPolicyStore::Observer: | 59 // CloudPolicyStore::Observer: |
60 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; | 60 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; |
61 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; | 61 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; |
62 | 62 |
63 // content::NotificationObserver: | 63 // PrefObserver: |
64 virtual void Observe(int type, | 64 virtual void OnPreferenceChanged(PrefServiceBase* service, |
65 const content::NotificationSource& source, | 65 const std::string& pref_name) OVERRIDE; |
66 const content::NotificationDetails& details) OVERRIDE; | |
67 | 66 |
68 // net::NetworkChangeNotifier::IPAddressObserver: | 67 // net::NetworkChangeNotifier::IPAddressObserver: |
69 virtual void OnIPAddressChanged() OVERRIDE; | 68 virtual void OnIPAddressChanged() OVERRIDE; |
70 | 69 |
71 private: | 70 private: |
72 // Initializes |last_refresh_| to the policy timestamp from |store_| in case | 71 // Initializes |last_refresh_| to the policy timestamp from |store_| in case |
73 // there is policy present that indicates this client is not managed. This | 72 // there is policy present that indicates this client is not managed. This |
74 // results in policy fetches only to occur after the entire unmanaged refresh | 73 // results in policy fetches only to occur after the entire unmanaged refresh |
75 // delay expires, even over restarts. For managed clients, we want to trigger | 74 // delay expires, even over restarts. For managed clients, we want to trigger |
76 // a refresh on every restart. | 75 // a refresh on every restart. |
(...skipping 29 matching lines...) Expand all Loading... |
106 int64 error_retry_delay_ms_; | 105 int64 error_retry_delay_ms_; |
107 | 106 |
108 IntegerPrefMember refresh_delay_; | 107 IntegerPrefMember refresh_delay_; |
109 | 108 |
110 DISALLOW_COPY_AND_ASSIGN(CloudPolicyRefreshScheduler); | 109 DISALLOW_COPY_AND_ASSIGN(CloudPolicyRefreshScheduler); |
111 }; | 110 }; |
112 | 111 |
113 } // namespace policy | 112 } // namespace policy |
114 | 113 |
115 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_REFRESH_SCHEDULER_H_ | 114 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_REFRESH_SCHEDULER_H_ |
OLD | NEW |