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