Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ | 6 #define CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "base/weak_ptr.h" | |
| 16 #include "chrome/browser/policy/configuration_policy_provider.h" | 15 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 17 #include "chrome/browser/policy/device_management_backend.h" | 16 #include "chrome/browser/policy/device_management_backend.h" |
| 18 #include "chrome/browser/policy/device_token_fetcher.h" | 17 #include "chrome/browser/policy/device_token_fetcher.h" |
| 19 | 18 |
| 20 class Profile; | 19 class Profile; |
| 21 class TokenService; | 20 class TokenService; |
| 22 | 21 |
| 23 namespace policy { | 22 namespace policy { |
| 24 | 23 |
| 25 class DeviceManagementBackend; | 24 class DeviceManagementBackend; |
| 26 class DeviceManagementPolicyCache; | 25 class DeviceManagementPolicyCache; |
| 27 | 26 |
| 28 // Provides policy fetched from the device management server. With the exception | 27 // Provides policy fetched from the device management server. With the exception |
| 29 // of the Provide method, which can be called on the FILE thread, all public | 28 // of the Provide method, which can be called on the FILE thread, all public |
| 30 // methods must be called on the UI thread. | 29 // methods must be called on the UI thread. |
| 31 class DeviceManagementPolicyProvider | 30 class DeviceManagementPolicyProvider |
| 32 : public ConfigurationPolicyProvider, | 31 : public ConfigurationPolicyProvider, |
| 33 public DeviceManagementBackend::DevicePolicyResponseDelegate, | 32 public DeviceManagementBackend::DevicePolicyResponseDelegate, |
| 34 public base::SupportsWeakPtr<DeviceManagementPolicyProvider>, | |
| 35 public DeviceTokenFetcher::Observer { | 33 public DeviceTokenFetcher::Observer { |
| 36 public: | 34 public: |
| 37 DeviceManagementPolicyProvider(const PolicyDefinitionList* policy_list, | 35 DeviceManagementPolicyProvider(const PolicyDefinitionList* policy_list, |
| 38 DeviceManagementBackend* backend, | 36 DeviceManagementBackend* backend, |
| 39 Profile* profile); | 37 Profile* profile); |
| 40 | 38 |
| 41 virtual ~DeviceManagementPolicyProvider(); | 39 virtual ~DeviceManagementPolicyProvider(); |
| 42 | 40 |
| 43 // ConfigurationPolicyProvider implementation: | 41 // ConfigurationPolicyProvider implementation: |
| 44 virtual bool Provide(ConfigurationPolicyStoreInterface* store); | 42 virtual bool Provide(ConfigurationPolicyStoreInterface* store); |
| 45 virtual bool IsInitializationComplete() const; | 43 virtual bool IsInitializationComplete() const; |
| 46 | 44 |
| 47 // DevicePolicyResponseDelegate implementation: | 45 // DevicePolicyResponseDelegate implementation: |
| 48 virtual void HandlePolicyResponse( | 46 virtual void HandlePolicyResponse( |
| 49 const em::DevicePolicyResponse& response); | 47 const em::DevicePolicyResponse& response); |
| 50 virtual void OnError(DeviceManagementBackend::ErrorCode code); | 48 virtual void OnError(DeviceManagementBackend::ErrorCode code); |
| 51 | 49 |
| 52 // DeviceTokenFetcher::Observer implementation: | 50 // DeviceTokenFetcher::Observer implementation: |
| 53 virtual void OnTokenSuccess(); | 51 virtual void OnTokenSuccess(); |
| 54 virtual void OnTokenError(); | 52 virtual void OnTokenError(); |
| 55 virtual void OnNotManaged(); | 53 virtual void OnNotManaged(); |
| 56 | 54 |
| 55 // Sets the refresh rate at which to re-fetch policy information. | |
| 56 void SetRefreshRate(int64 refresh_rate_milliseconds); | |
| 57 | |
| 57 private: | 58 private: |
| 58 class InitializeAfterIOThreadExistsTask; | 59 // Indicates the current state the provider is in. |
| 60 enum ProviderState { | |
| 61 // The provider is initializing, policy information not yet available. | |
| 62 STATE_INITIALIZING, | |
| 63 // This device is not managed through policy. | |
| 64 STATE_UNMANAGED, | |
| 65 // The token is valid, but policy is yet to be fetched. | |
| 66 STATE_TOKEN_VALID, | |
| 67 // Policy information is available and valid. | |
| 68 STATE_POLICY_VALID, | |
| 69 // The token was found to be invalid and needs to be obtained again. | |
| 70 STATE_TOKEN_RESET, | |
| 71 // There has been an error fetching the token, retry later. | |
| 72 STATE_TOKEN_ERROR, | |
| 73 // The service returned an error when requesting policy, ask again later. | |
| 74 STATE_POLICY_ERROR, | |
| 75 }; | |
| 76 | |
| 59 class RefreshTask; | 77 class RefreshTask; |
| 60 | 78 |
| 61 friend class DeviceManagementPolicyProviderTest; | 79 friend class DeviceManagementPolicyProviderTest; |
| 62 | 80 |
| 63 // More configurable constructor for use by test cases. | 81 // More configurable constructor for use by test cases. |
| 64 DeviceManagementPolicyProvider(const PolicyDefinitionList* policy_list, | 82 DeviceManagementPolicyProvider(const PolicyDefinitionList* policy_list, |
| 65 DeviceManagementBackend* backend, | 83 DeviceManagementBackend* backend, |
| 66 Profile* profile, | 84 Profile* profile, |
| 67 int64 policy_refresh_rate_ms, | 85 int64 policy_refresh_rate_ms, |
| 68 int64 policy_refresh_max_earlier_ms, | 86 int policy_refresh_fuzz_factor_percent, |
|
danno
2011/01/06 19:16:26
how about "deviation" or "random_deviation" instea
Mattias Nissler (ping if slow)
2011/01/07 11:15:33
Done.
| |
| 87 int64 policy_refresh_fuzz_max_ms, | |
| 69 int64 policy_refresh_error_delay_ms, | 88 int64 policy_refresh_error_delay_ms, |
| 70 int64 token_fetch_error_delay_ms, | 89 int64 token_fetch_error_delay_ms, |
| 71 int64 unmanaged_device_refresh_rate_ms); | 90 int64 unmanaged_device_refresh_rate_ms); |
| 72 | 91 |
| 73 // Called by constructors to perform shared initialization. Initialization | 92 // Called by constructors to perform shared initialization. Initialization |
| 74 // requiring the IOThread must not be performed directly in this method, | 93 // requiring the IOThread must not be performed directly in this method, |
| 75 // rather must be deferred until the IOThread is fully initialized. This is | 94 // rather must be deferred until the IOThread is fully initialized. This is |
| 76 // the case in InitializeAfterIOThreadExists. | 95 // the case in InitializeAfterIOThreadExists. |
| 77 void Initialize(DeviceManagementBackend* backend, | 96 void Initialize(DeviceManagementBackend* backend, |
| 78 Profile* profile, | 97 Profile* profile, |
| 79 int64 policy_refresh_rate_ms, | 98 int64 policy_refresh_rate_ms, |
| 80 int64 policy_refresh_max_earlier_ms, | 99 int policy_refresh_fuzz_factor_percent, |
| 100 int64 policy_refresh_fuzz_max_ms, | |
| 81 int64 policy_refresh_error_delay_ms, | 101 int64 policy_refresh_error_delay_ms, |
| 82 int64 token_fetch_error_delay_ms, | 102 int64 token_fetch_error_delay_ms, |
| 83 int64 unmanaged_device_refresh_rate_ms); | 103 int64 unmanaged_device_refresh_rate_ms); |
| 84 | 104 |
| 85 // Called by a deferred task posted to the UI thread to complete the portion | |
| 86 // of initialization that requires the IOThread. | |
| 87 void InitializeAfterIOThreadExists(); | |
| 88 | |
| 89 // ConfigurationPolicyProvider overrides: | 105 // ConfigurationPolicyProvider overrides: |
| 90 virtual void AddObserver(ConfigurationPolicyProvider::Observer* observer); | 106 virtual void AddObserver(ConfigurationPolicyProvider::Observer* observer); |
| 91 virtual void RemoveObserver(ConfigurationPolicyProvider::Observer* observer); | 107 virtual void RemoveObserver(ConfigurationPolicyProvider::Observer* observer); |
| 92 | 108 |
| 93 // Sends a request to the device manager backend to fetch policy if one isn't | 109 // Sends a request to the device manager backend to fetch policy if one isn't |
| 94 // already outstanding. | 110 // already outstanding. |
| 95 void SendPolicyRequest(); | 111 void SendPolicyRequest(); |
| 96 | 112 |
| 97 // Triggers policy refresh, re-requesting device token and policy information | 113 // Triggers policy refresh, re-requesting device token and policy information |
| 98 // as necessary. | 114 // as necessary. |
| 99 void RefreshTaskExecute(); | 115 void RefreshTaskExecute(); |
| 100 | 116 |
| 101 // Schedules a new RefreshTask. | 117 // Cancels the refresh task. |
| 102 void ScheduleRefreshTask(int64 delay_in_milliseconds); | 118 void CancelRefreshTask(); |
| 103 | |
| 104 // Calculates when the next RefreshTask shall be executed. | |
| 105 int64 GetRefreshTaskDelay(); | |
| 106 | |
| 107 void StopWaitingForInitialPolicies(); | |
| 108 | 119 |
| 109 // Notify observers about a policy update. | 120 // Notify observers about a policy update. |
| 110 void NotifyCloudPolicyUpdate(); | 121 void NotifyCloudPolicyUpdate(); |
| 111 | 122 |
| 112 // The path of the device token file. | 123 // The path of the device token file. |
| 113 FilePath GetTokenPath(); | 124 FilePath GetTokenPath(); |
| 114 | 125 |
| 115 // Used only by tests. | 126 // Used only by tests. |
| 116 void SetDeviceTokenFetcher(DeviceTokenFetcher* token_fetcher); | 127 void SetDeviceTokenFetcher(DeviceTokenFetcher* token_fetcher); |
| 117 | 128 |
| 129 // Switches to a new state and triggers any appropriate actions. | |
| 130 void SetState(ProviderState new_state); | |
| 131 | |
| 132 // Check whether the current state is one in which the token is available. | |
| 133 bool TokenAvailable() const; | |
| 134 | |
| 135 // Computes the refresh delay to use. | |
| 136 int64 GetRefreshDelay(); | |
| 137 | |
| 118 // Provides the URL at which requests are sent to from the device management | 138 // Provides the URL at which requests are sent to from the device management |
| 119 // backend. | 139 // backend. |
| 120 static std::string GetDeviceManagementURL(); | 140 static std::string GetDeviceManagementURL(); |
| 121 | 141 |
| 122 // Returns the path to the sub-directory in the user data directory | 142 // Returns the path to the sub-directory in the user data directory |
| 123 // in which device management persistent state is stored. | 143 // in which device management persistent state is stored. |
| 124 static FilePath GetOrCreateDeviceManagementDir( | 144 static FilePath GetOrCreateDeviceManagementDir( |
| 125 const FilePath& user_data_dir); | 145 const FilePath& user_data_dir); |
| 126 | 146 |
| 127 scoped_ptr<DeviceManagementBackend> backend_; | 147 scoped_ptr<DeviceManagementBackend> backend_; |
| 128 Profile* profile_; // weak | 148 Profile* profile_; // weak |
| 129 scoped_ptr<DeviceManagementPolicyCache> cache_; | 149 scoped_ptr<DeviceManagementPolicyCache> cache_; |
| 130 scoped_refptr<DeviceTokenFetcher> token_fetcher_; | 150 scoped_refptr<DeviceTokenFetcher> token_fetcher_; |
| 131 DeviceTokenFetcher::ObserverRegistrar registrar_; | 151 DeviceTokenFetcher::ObserverRegistrar registrar_; |
| 132 ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_; | 152 ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_; |
| 133 FilePath storage_dir_; | 153 FilePath storage_dir_; |
| 134 bool policy_request_pending_; | 154 ProviderState state_; |
| 135 bool refresh_task_pending_; | 155 RefreshTask* refresh_task_; |
| 136 bool waiting_for_initial_policies_; | |
| 137 int64 policy_refresh_rate_ms_; | 156 int64 policy_refresh_rate_ms_; |
| 138 int64 policy_refresh_max_earlier_ms_; | 157 int policy_refresh_fuzz_factor_percent_; |
| 158 int64 policy_refresh_fuzz_max_ms_; | |
| 139 int64 policy_refresh_error_delay_ms_; | 159 int64 policy_refresh_error_delay_ms_; |
| 160 int64 effective_policy_refresh_error_delay_ms_; | |
| 140 int64 token_fetch_error_delay_ms_; | 161 int64 token_fetch_error_delay_ms_; |
| 162 int64 effective_token_fetch_error_delay_ms_; | |
| 141 int64 unmanaged_device_refresh_rate_ms_; | 163 int64 unmanaged_device_refresh_rate_ms_; |
| 142 | 164 |
| 143 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider); | 165 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider); |
| 144 }; | 166 }; |
| 145 | 167 |
| 146 } // namespace policy | 168 } // namespace policy |
| 147 | 169 |
| 148 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ | 170 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ |
| OLD | NEW |