| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 // DeviceTokenFetcher::Observer implementation: | 50 // DeviceTokenFetcher::Observer implementation: |
| 51 void OnTokenSuccess(); | 51 void OnTokenSuccess(); |
| 52 void OnTokenError(); | 52 void OnTokenError(); |
| 53 void OnNotManaged(); | 53 void OnNotManaged(); |
| 54 | 54 |
| 55 // True if a policy request has been sent to the device management backend | 55 // True if a policy request has been sent to the device management backend |
| 56 // server and no response or error has yet been received. | 56 // server and no response or error has yet been received. |
| 57 bool IsPolicyRequestPending() const { return policy_request_pending_; } | 57 bool IsPolicyRequestPending() const { return policy_request_pending_; } |
| 58 | 58 |
| 59 bool waiting_for_initial_policies() const { | |
| 60 return waiting_for_initial_policies_; | |
| 61 } | |
| 62 | |
| 63 // Tells the provider that the passed in token service reference is about to | 59 // Tells the provider that the passed in token service reference is about to |
| 64 // become invalid. | 60 // become invalid. |
| 65 void Shutdown(); | 61 void Shutdown(); |
| 66 | 62 |
| 67 private: | 63 private: |
| 68 class InitializeAfterIOThreadExistsTask; | 64 class InitializeAfterIOThreadExistsTask; |
| 69 class RefreshTask; | 65 class RefreshTask; |
| 70 | 66 |
| 71 friend class DeviceManagementPolicyProviderTest; | 67 friend class DeviceManagementPolicyProviderTest; |
| 72 | 68 |
| 73 // More configurable constructor for use by test cases. | |
| 74 DeviceManagementPolicyProvider(const PolicyDefinitionList* policy_list, | |
| 75 DeviceManagementBackend* backend, | |
| 76 Profile* profile, | |
| 77 int64 policy_refresh_rate_ms, | |
| 78 int64 policy_refresh_max_earlier_ms, | |
| 79 int64 policy_refresh_error_delay_ms, | |
| 80 int64 token_fetch_error_delay_ms, | |
| 81 int64 unmanaged_device_refresh_rate_ms); | |
| 82 | |
| 83 // Called by constructors to perform shared initialization. Initialization | 69 // Called by constructors to perform shared initialization. Initialization |
| 84 // requiring the IOThread must not be performed directly in this method, | 70 // requiring the IOThread must not be performed directly in this method, |
| 85 // rather must be deferred until the IOThread is fully initialized. This is | 71 // rather must be deferred until the IOThread is fully initialized. This is |
| 86 // the case in InitializeAfterIOThreadExists. | 72 // the case in InitializeAfterIOThreadExists. |
| 87 void Initialize(DeviceManagementBackend* backend, | 73 void Initialize(); |
| 88 Profile* profile, | |
| 89 int64 policy_refresh_rate_ms, | |
| 90 int64 policy_refresh_max_earlier_ms, | |
| 91 int64 policy_refresh_error_delay_ms, | |
| 92 int64 token_fetch_error_delay_ms, | |
| 93 int64 unmanaged_device_refresh_rate_ms); | |
| 94 | 74 |
| 95 // Called by a deferred task posted to the UI thread to complete the portion | 75 // Called by a deferred task posted to the UI thread to complete the portion |
| 96 // of initialization that requires the IOThread. | 76 // of initialization that requires the IOThread. |
| 97 void InitializeAfterIOThreadExists(); | 77 void InitializeAfterIOThreadExists(); |
| 98 | 78 |
| 99 // Sends a request to the device manager backend to fetch policy if one isn't | 79 // Sends a request to the device manager backend to fetch policy if one isn't |
| 100 // already outstanding. | 80 // already outstanding. |
| 101 void SendPolicyRequest(); | 81 void SendPolicyRequest(); |
| 102 | 82 |
| 103 // Triggers policy refresh, re-requesting device token and policy information | 83 // Triggers policy refresh, re-requesting device token and policy information |
| 104 // as necessary. | 84 // as necessary. |
| 105 void RefreshTaskExecute(); | 85 void RefreshTaskExecute(); |
| 106 | 86 |
| 107 // Schedules a new RefreshTask. | 87 // Schedules a new RefreshTask. |
| 108 void ScheduleRefreshTask(int64 delay_in_milliseconds); | 88 void ScheduleRefreshTask(int64 delay_in_milliseconds); |
| 109 | 89 |
| 110 // Calculates when the next RefreshTask shall be executed. | 90 // Calculates when the next RefreshTask shall be executed. |
| 111 int64 GetRefreshTaskDelay(); | 91 int64 GetRefreshTaskDelay(); |
| 112 | 92 |
| 113 void StopWaitingForInitialPolicies(); | |
| 114 | |
| 115 // Send a CLOUD_POLICY_UPDATE notification. | |
| 116 void NotifyCloudPolicyUpdate() const; | |
| 117 | |
| 118 // The path of the device token file. | 93 // The path of the device token file. |
| 119 FilePath GetTokenPath(); | 94 FilePath GetTokenPath(); |
| 120 | 95 |
| 121 // Used only by tests. | 96 // Used only by tests. |
| 122 void SetDeviceTokenFetcher(DeviceTokenFetcher* token_fetcher); | 97 void SetDeviceTokenFetcher(DeviceTokenFetcher* token_fetcher); |
| 123 | 98 |
| 124 // Provides the URL at which requests are sent to from the device management | 99 // Provides the URL at which requests are sent to from the device management |
| 125 // backend. | 100 // backend. |
| 126 static std::string GetDeviceManagementURL(); | 101 static std::string GetDeviceManagementURL(); |
| 127 | 102 |
| 128 // Returns the path to the sub-directory in the user data directory | 103 // Returns the path to the sub-directory in the user data directory |
| 129 // in which device management persistent state is stored. | 104 // in which device management persistent state is stored. |
| 130 static FilePath GetOrCreateDeviceManagementDir( | 105 static FilePath GetOrCreateDeviceManagementDir( |
| 131 const FilePath& user_data_dir); | 106 const FilePath& user_data_dir); |
| 132 | 107 |
| 108 // Give unit tests the ability to override timeout settings. |
| 109 void set_policy_refresh_rate_ms(int64 policy_refresh_rate_ms) { |
| 110 policy_refresh_rate_ms_ = policy_refresh_rate_ms; |
| 111 } |
| 112 void set_policy_refresh_max_earlier_ms(int64 policy_refresh_max_earlier_ms) { |
| 113 policy_refresh_max_earlier_ms_ = policy_refresh_max_earlier_ms; |
| 114 } |
| 115 void set_policy_refresh_error_delay_ms(int64 policy_refresh_error_delay_ms) { |
| 116 policy_refresh_error_delay_ms_ = policy_refresh_error_delay_ms; |
| 117 } |
| 118 void set_token_fetch_error_delay_ms(int64 token_fetch_error_delay_ms) { |
| 119 token_fetch_error_delay_ms_ = token_fetch_error_delay_ms; |
| 120 } |
| 121 |
| 133 scoped_ptr<DeviceManagementBackend> backend_; | 122 scoped_ptr<DeviceManagementBackend> backend_; |
| 134 Profile* profile_; // weak | 123 Profile* profile_; // weak |
| 135 scoped_ptr<DeviceManagementPolicyCache> cache_; | 124 scoped_ptr<DeviceManagementPolicyCache> cache_; |
| 136 scoped_refptr<DeviceTokenFetcher> token_fetcher_; | 125 scoped_refptr<DeviceTokenFetcher> token_fetcher_; |
| 137 DeviceTokenFetcher::ObserverRegistrar registrar_; | 126 DeviceTokenFetcher::ObserverRegistrar registrar_; |
| 138 FilePath storage_dir_; | 127 FilePath storage_dir_; |
| 139 bool policy_request_pending_; | 128 bool policy_request_pending_; |
| 140 bool refresh_task_pending_; | 129 bool refresh_task_pending_; |
| 141 bool waiting_for_initial_policies_; | |
| 142 int64 policy_refresh_rate_ms_; | 130 int64 policy_refresh_rate_ms_; |
| 143 int64 policy_refresh_max_earlier_ms_; | 131 int64 policy_refresh_max_earlier_ms_; |
| 144 int64 policy_refresh_error_delay_ms_; | 132 int64 policy_refresh_error_delay_ms_; |
| 145 int64 token_fetch_error_delay_ms_; | 133 int64 token_fetch_error_delay_ms_; |
| 146 int64 unmanaged_device_refresh_rate_ms_; | |
| 147 | 134 |
| 148 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider); | 135 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider); |
| 149 }; | 136 }; |
| 150 | 137 |
| 151 } // namespace policy | 138 } // namespace policy |
| 152 | 139 |
| 153 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ | 140 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ |
| OLD | NEW |