| 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 fd18bc30f858e4f521986e0c1f146fd24e0f01d2..592df9b9c709795b35cb78596ef0ecd087d2a7d7 100644
|
| --- a/chrome/browser/policy/device_management_policy_provider.h
|
| +++ b/chrome/browser/policy/device_management_policy_provider.h
|
| @@ -12,7 +12,6 @@
|
| #include "base/observer_list.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/browser/policy/device_token_fetcher.h"
|
| @@ -31,7 +30,6 @@ class DeviceManagementPolicyCache;
|
| class DeviceManagementPolicyProvider
|
| : public ConfigurationPolicyProvider,
|
| public DeviceManagementBackend::DevicePolicyResponseDelegate,
|
| - public base::SupportsWeakPtr<DeviceManagementPolicyProvider>,
|
| public DeviceTokenFetcher::Observer {
|
| public:
|
| DeviceManagementPolicyProvider(const PolicyDefinitionList* policy_list,
|
| @@ -54,8 +52,28 @@ class DeviceManagementPolicyProvider
|
| virtual void OnTokenError();
|
| virtual void OnNotManaged();
|
|
|
| + // Sets the refresh rate at which to re-fetch policy information.
|
| + void SetRefreshRate(int64 refresh_rate_milliseconds);
|
| +
|
| private:
|
| - class InitializeAfterIOThreadExistsTask;
|
| + // Indicates the current state the provider is in.
|
| + enum ProviderState {
|
| + // The provider is initializing, policy information not yet available.
|
| + STATE_INITIALIZING,
|
| + // This device is not managed through policy.
|
| + STATE_UNMANAGED,
|
| + // The token is valid, but policy is yet to be fetched.
|
| + STATE_TOKEN_VALID,
|
| + // Policy information is available and valid.
|
| + STATE_POLICY_VALID,
|
| + // The token was found to be invalid and needs to be obtained again.
|
| + STATE_TOKEN_RESET,
|
| + // There has been an error fetching the token, retry later.
|
| + STATE_TOKEN_ERROR,
|
| + // The service returned an error when requesting policy, ask again later.
|
| + STATE_POLICY_ERROR,
|
| + };
|
| +
|
| class RefreshTask;
|
|
|
| friend class DeviceManagementPolicyProviderTest;
|
| @@ -65,7 +83,8 @@ class DeviceManagementPolicyProvider
|
| DeviceManagementBackend* backend,
|
| Profile* profile,
|
| int64 policy_refresh_rate_ms,
|
| - int64 policy_refresh_max_earlier_ms,
|
| + int policy_refresh_deviation_factor_percent,
|
| + int64 policy_refresh_deviation_max_ms,
|
| int64 policy_refresh_error_delay_ms,
|
| int64 token_fetch_error_delay_ms,
|
| int64 unmanaged_device_refresh_rate_ms);
|
| @@ -77,15 +96,12 @@ class DeviceManagementPolicyProvider
|
| void Initialize(DeviceManagementBackend* backend,
|
| Profile* profile,
|
| int64 policy_refresh_rate_ms,
|
| - int64 policy_refresh_max_earlier_ms,
|
| + int policy_refresh_deviation_factor_percent,
|
| + int64 policy_refresh_deviation_max_ms,
|
| int64 policy_refresh_error_delay_ms,
|
| int64 token_fetch_error_delay_ms,
|
| int64 unmanaged_device_refresh_rate_ms);
|
|
|
| - // Called by a deferred task posted to the UI thread to complete the portion
|
| - // of initialization that requires the IOThread.
|
| - void InitializeAfterIOThreadExists();
|
| -
|
| // ConfigurationPolicyProvider overrides:
|
| virtual void AddObserver(ConfigurationPolicyProvider::Observer* observer);
|
| virtual void RemoveObserver(ConfigurationPolicyProvider::Observer* observer);
|
| @@ -98,13 +114,8 @@ class DeviceManagementPolicyProvider
|
| // as necessary.
|
| void RefreshTaskExecute();
|
|
|
| - // Schedules a new RefreshTask.
|
| - void ScheduleRefreshTask(int64 delay_in_milliseconds);
|
| -
|
| - // Calculates when the next RefreshTask shall be executed.
|
| - int64 GetRefreshTaskDelay();
|
| -
|
| - void StopWaitingForInitialPolicies();
|
| + // Cancels the refresh task.
|
| + void CancelRefreshTask();
|
|
|
| // Notify observers about a policy update.
|
| void NotifyCloudPolicyUpdate();
|
| @@ -115,6 +126,15 @@ class DeviceManagementPolicyProvider
|
| // Used only by tests.
|
| void SetDeviceTokenFetcher(DeviceTokenFetcher* token_fetcher);
|
|
|
| + // Switches to a new state and triggers any appropriate actions.
|
| + void SetState(ProviderState new_state);
|
| +
|
| + // Check whether the current state is one in which the token is available.
|
| + bool TokenAvailable() const;
|
| +
|
| + // Computes the refresh delay to use.
|
| + int64 GetRefreshDelay();
|
| +
|
| // Provides the URL at which requests are sent to from the device management
|
| // backend.
|
| static std::string GetDeviceManagementURL();
|
| @@ -131,13 +151,16 @@ class DeviceManagementPolicyProvider
|
| DeviceTokenFetcher::ObserverRegistrar registrar_;
|
| ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_;
|
| FilePath storage_dir_;
|
| - bool policy_request_pending_;
|
| - bool refresh_task_pending_;
|
| - bool waiting_for_initial_policies_;
|
| + ProviderState state_;
|
| + bool initial_fetch_done_;
|
| + RefreshTask* refresh_task_;
|
| int64 policy_refresh_rate_ms_;
|
| - int64 policy_refresh_max_earlier_ms_;
|
| + int policy_refresh_deviation_factor_percent_;
|
| + int64 policy_refresh_deviation_max_ms_;
|
| int64 policy_refresh_error_delay_ms_;
|
| + int64 effective_policy_refresh_error_delay_ms_;
|
| int64 token_fetch_error_delay_ms_;
|
| + int64 effective_token_fetch_error_delay_ms_;
|
| int64 unmanaged_device_refresh_rate_ms_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider);
|
|
|