Index: chrome/browser/policy/device_management_policy_provider.h |
diff --git a/chrome/browser/policy/device_management_policy_provider.h b/chrome/browser/policy/device_management_policy_provider.h |
index d73afc52ee1823a8e2779eb14ad91f1cf2b31bb9..d3b2b7b64f4e3d20a5910aa5c1b84cb322d39da5 100644 |
--- a/chrome/browser/policy/device_management_policy_provider.h |
+++ b/chrome/browser/policy/device_management_policy_provider.h |
@@ -10,13 +10,11 @@ |
#include "base/file_path.h" |
#include "base/scoped_ptr.h" |
+#include "base/time.h" |
#include "base/weak_ptr.h" |
#include "chrome/browser/policy/configuration_policy_provider.h" |
#include "chrome/browser/policy/device_management_backend.h" |
-#include "chrome/common/notification_details.h" |
-#include "chrome/common/notification_observer.h" |
-#include "chrome/common/notification_registrar.h" |
-#include "chrome/common/notification_source.h" |
+#include "chrome/browser/policy/device_token_fetcher.h" |
class TokenService; |
@@ -24,16 +22,15 @@ namespace policy { |
class DeviceManagementBackend; |
class DeviceManagementPolicyCache; |
-class DeviceTokenFetcher; |
// Provides policy fetched from the device management server. With the exception |
// of the Provide method, which can be called on the FILE thread, all public |
// methods must be called on the UI thread. |
class DeviceManagementPolicyProvider |
: public ConfigurationPolicyProvider, |
- public NotificationObserver, |
public DeviceManagementBackend::DevicePolicyResponseDelegate, |
- public base::SupportsWeakPtr<DeviceManagementPolicyProvider> { |
+ public base::SupportsWeakPtr<DeviceManagementPolicyProvider>, |
+ public DeviceTokenFetcher::Observer { |
public: |
DeviceManagementPolicyProvider(const PolicyDefinitionList* policy_list, |
DeviceManagementBackend* backend, |
@@ -45,16 +42,15 @@ class DeviceManagementPolicyProvider |
// ConfigurationPolicyProvider implementation: |
virtual bool Provide(ConfigurationPolicyStoreInterface* store); |
- // NotificationObserver implementation: |
- virtual void Observe(NotificationType type, |
- const NotificationSource& source, |
- const NotificationDetails& details); |
- |
// DevicePolicyResponseDelegate implementation: |
virtual void HandlePolicyResponse( |
const em::DevicePolicyResponse& response); |
virtual void OnError(DeviceManagementBackend::ErrorCode code); |
+ // DeviceTokenFetcher::Observer implementation: |
+ void OnTokenSuccess(); |
+ void OnTokenError(); |
+ |
// True if a policy request has been sent to the device management backend |
// server and no response or error has yet been received. |
bool IsPolicyRequestPending() const { return policy_request_pending_; } |
@@ -63,8 +59,23 @@ class DeviceManagementPolicyProvider |
// become invalid. |
void Shutdown(); |
+ // Give unit tests the ability to override timeout settings. |
danno
2010/11/22 13:47:50
All of these should definitely be private/protecte
Jakob Kummerow (corp)
2010/11/22 16:56:08
Done.
|
+ void set_policy_refresh_rate_ms(int64 policy_refresh_rate_ms) { |
+ policy_refresh_rate_ms_ = policy_refresh_rate_ms; |
+ } |
+ void set_policy_refresh_max_earlier_ms(int64 policy_refresh_max_earlier_ms) { |
+ policy_refresh_max_earlier_ms_ = policy_refresh_max_earlier_ms; |
+ } |
+ void set_policy_refresh_error_delay_ms(int64 policy_refresh_error_delay_ms) { |
+ policy_refresh_error_delay_ms_ = policy_refresh_error_delay_ms; |
+ } |
+ void set_token_fetch_error_delay_ms(int64 token_fetch_error_delay_ms) { |
+ token_fetch_error_delay_ms_ = token_fetch_error_delay_ms; |
+ } |
+ |
private: |
class InitializeAfterIOThreadExistsTask; |
+ class RefreshTask; |
// Returns the device management backend to use for backend requests, lazily |
// creating a new one if one doesn't already exist. |
@@ -84,9 +95,17 @@ class DeviceManagementPolicyProvider |
// already outstanding. |
void SendPolicyRequest(); |
- // True if policy must be re-fetched because the cached policy is too old or |
- // its time stamp is invalid. |
- bool IsPolicyStale() const; |
+ // Triggers policy refresh, re-requesting device token and policy information |
+ // as necessary. |
+ void RefreshTaskExecute(); |
+ |
+ // Schedules a new RefreshTask. |
+ void ScheduleRefreshTask(int64 delay_in_milliseconds); |
+ |
+ // Calculates when the next RefreshTask shall be executed. |
+ static int64 GetRefreshTaskDelay( |
+ int64 policy_refresh_rate_ms, |
+ int64 policy_refresh_max_random_earlier_ms); |
danno
2010/11/22 13:47:50
Why pass these in? You only pass in the values of
Jakob Kummerow (corp)
2010/11/22 16:56:08
Done.
|
// Provides the URL at which requests are sent to from the device management |
// backend. |
@@ -98,12 +117,16 @@ class DeviceManagementPolicyProvider |
const FilePath& user_data_dir); |
scoped_ptr<DeviceManagementBackend> backend_; |
- TokenService* token_service_; // weak |
+ TokenService* token_service_; // weak |
scoped_ptr<DeviceManagementPolicyCache> cache_; |
scoped_refptr<DeviceTokenFetcher> token_fetcher_; |
- NotificationRegistrar registrar_; |
FilePath storage_dir_; |
bool policy_request_pending_; |
+ bool refresh_task_pending_; |
+ int64 policy_refresh_rate_ms_; |
+ int64 policy_refresh_max_earlier_ms_; |
+ int64 policy_refresh_error_delay_ms_; |
+ int64 token_fetch_error_delay_ms_; |
DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider); |
}; |