| 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 d91e22bbd8fcf98d130dfc01dbd88b15db42fa7e..89ef850caa4c77a518db2cc600dcf049a8387440 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,16 @@ 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();
|
| + void OnNotManaged();
|
| +
|
| // 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_; }
|
| @@ -65,6 +62,9 @@ class DeviceManagementPolicyProvider
|
|
|
| private:
|
| class InitializeAfterIOThreadExistsTask;
|
| + class RefreshTask;
|
| +
|
| + friend class DeviceManagementPolicyProviderTest;
|
|
|
| // Called by constructors to perform shared initialization. Initialization
|
| // requiring the IOThread must not be performed directly in this method,
|
| @@ -80,9 +80,15 @@ 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.
|
| + int64 GetRefreshTaskDelay();
|
|
|
| // Provides the URL at which requests are sent to from the device management
|
| // backend.
|
| @@ -93,13 +99,32 @@ class DeviceManagementPolicyProvider
|
| static FilePath GetOrCreateDeviceManagementDir(
|
| const FilePath& user_data_dir);
|
|
|
| + // Give unit tests the ability to override timeout settings.
|
| + 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;
|
| + }
|
| +
|
| scoped_ptr<DeviceManagementBackend> backend_;
|
| - TokenService* token_service_; // weak
|
| + TokenService* token_service_; // weak
|
| scoped_ptr<DeviceManagementPolicyCache> cache_;
|
| scoped_refptr<DeviceTokenFetcher> token_fetcher_;
|
| - NotificationRegistrar registrar_;
|
| + DeviceTokenFetcher::ObserverRegistrar 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);
|
| };
|
|
|