| 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 // Returns true if the device management policy provider has an empty policy | 59 // Returns true if the device management policy provider is currently waiting |
| 60 // cache and is waiting for a pending policy request to retrive the inital | 60 // for the first attempt to fetch policies to complete. |
| 61 // set of policies. If cached policies are available false is returned even in | |
| 62 // the case of a pending policy request. | |
| 63 bool WaitingForInitialPolicies() const; | 61 bool WaitingForInitialPolicies() const; |
| 64 | 62 |
| 65 // Tells the provider that the passed in token service reference is about to | 63 // Tells the provider that the passed in token service reference is about to |
| 66 // become invalid. | 64 // become invalid. |
| 67 void Shutdown(); | 65 void Shutdown(); |
| 68 | 66 |
| 69 private: | 67 private: |
| 70 class InitializeAfterIOThreadExistsTask; | 68 class InitializeAfterIOThreadExistsTask; |
| 71 class RefreshTask; | 69 class RefreshTask; |
| 72 | 70 |
| 73 friend class DeviceManagementPolicyProviderTest; | 71 friend class DeviceManagementPolicyProviderTest; |
| 74 | 72 |
| 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 |
| 75 // Called by constructors to perform shared initialization. Initialization | 83 // Called by constructors to perform shared initialization. Initialization |
| 76 // requiring the IOThread must not be performed directly in this method, | 84 // requiring the IOThread must not be performed directly in this method, |
| 77 // rather must be deferred until the IOThread is fully initialized. This is | 85 // rather must be deferred until the IOThread is fully initialized. This is |
| 78 // the case in InitializeAfterIOThreadExists. | 86 // the case in InitializeAfterIOThreadExists. |
| 79 void Initialize(); | 87 void Initialize(DeviceManagementBackend* backend, |
| 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); |
| 80 | 94 |
| 81 // Called by a deferred task posted to the UI thread to complete the portion | 95 // Called by a deferred task posted to the UI thread to complete the portion |
| 82 // of initialization that requires the IOThread. | 96 // of initialization that requires the IOThread. |
| 83 void InitializeAfterIOThreadExists(); | 97 void InitializeAfterIOThreadExists(); |
| 84 | 98 |
| 85 // Sends a request to the device manager backend to fetch policy if one isn't | 99 // Sends a request to the device manager backend to fetch policy if one isn't |
| 86 // already outstanding. | 100 // already outstanding. |
| 87 void SendPolicyRequest(); | 101 void SendPolicyRequest(); |
| 88 | 102 |
| 89 // Triggers policy refresh, re-requesting device token and policy information | 103 // Triggers policy refresh, re-requesting device token and policy information |
| 90 // as necessary. | 104 // as necessary. |
| 91 void RefreshTaskExecute(); | 105 void RefreshTaskExecute(); |
| 92 | 106 |
| 93 // Schedules a new RefreshTask. | 107 // Schedules a new RefreshTask. |
| 94 void ScheduleRefreshTask(int64 delay_in_milliseconds); | 108 void ScheduleRefreshTask(int64 delay_in_milliseconds); |
| 95 | 109 |
| 96 // Calculates when the next RefreshTask shall be executed. | 110 // Calculates when the next RefreshTask shall be executed. |
| 97 int64 GetRefreshTaskDelay(); | 111 int64 GetRefreshTaskDelay(); |
| 98 | 112 |
| 99 // Returns true if the policy cache is empty and hence no policies are | 113 void StopWaitingForInitialPolicies(); |
| 100 // available. | |
| 101 bool IsPolicyCacheEmpty() const; | |
| 102 | 114 |
| 103 #if defined(OS_CHROMEOS) | 115 #if defined(OS_CHROMEOS) |
| 104 // Send a CLOUD_POLICY_UPDATE notification. | 116 // Send a CLOUD_POLICY_UPDATE notification. |
| 105 void NotifyCloudPolicyUpdate() const; | 117 void NotifyCloudPolicyUpdate() const; |
| 106 #endif | 118 #endif |
| 107 | 119 |
| 108 // The path of the device token file. | 120 // The path of the device token file. |
| 109 FilePath GetTokenPath(); | 121 FilePath GetTokenPath(); |
| 110 | 122 |
| 111 // Used only by tests. | 123 // Used only by tests. |
| 112 void SetDeviceTokenFetcher(DeviceTokenFetcher* token_fetcher); | 124 void SetDeviceTokenFetcher(DeviceTokenFetcher* token_fetcher); |
| 113 | 125 |
| 114 // Provides the URL at which requests are sent to from the device management | 126 // Provides the URL at which requests are sent to from the device management |
| 115 // backend. | 127 // backend. |
| 116 static std::string GetDeviceManagementURL(); | 128 static std::string GetDeviceManagementURL(); |
| 117 | 129 |
| 118 // Returns the path to the sub-directory in the user data directory | 130 // Returns the path to the sub-directory in the user data directory |
| 119 // in which device management persistent state is stored. | 131 // in which device management persistent state is stored. |
| 120 static FilePath GetOrCreateDeviceManagementDir( | 132 static FilePath GetOrCreateDeviceManagementDir( |
| 121 const FilePath& user_data_dir); | 133 const FilePath& user_data_dir); |
| 122 | 134 |
| 123 // Give unit tests the ability to override timeout settings. | |
| 124 void set_policy_refresh_rate_ms(int64 policy_refresh_rate_ms) { | |
| 125 policy_refresh_rate_ms_ = policy_refresh_rate_ms; | |
| 126 } | |
| 127 void set_policy_refresh_max_earlier_ms(int64 policy_refresh_max_earlier_ms) { | |
| 128 policy_refresh_max_earlier_ms_ = policy_refresh_max_earlier_ms; | |
| 129 } | |
| 130 void set_policy_refresh_error_delay_ms(int64 policy_refresh_error_delay_ms) { | |
| 131 policy_refresh_error_delay_ms_ = policy_refresh_error_delay_ms; | |
| 132 } | |
| 133 void set_token_fetch_error_delay_ms(int64 token_fetch_error_delay_ms) { | |
| 134 token_fetch_error_delay_ms_ = token_fetch_error_delay_ms; | |
| 135 } | |
| 136 | |
| 137 scoped_ptr<DeviceManagementBackend> backend_; | 135 scoped_ptr<DeviceManagementBackend> backend_; |
| 138 Profile* profile_; // weak | 136 Profile* profile_; // weak |
| 139 scoped_ptr<DeviceManagementPolicyCache> cache_; | 137 scoped_ptr<DeviceManagementPolicyCache> cache_; |
| 140 scoped_refptr<DeviceTokenFetcher> token_fetcher_; | 138 scoped_refptr<DeviceTokenFetcher> token_fetcher_; |
| 141 DeviceTokenFetcher::ObserverRegistrar registrar_; | 139 DeviceTokenFetcher::ObserverRegistrar registrar_; |
| 142 FilePath storage_dir_; | 140 FilePath storage_dir_; |
| 143 bool policy_request_pending_; | 141 bool policy_request_pending_; |
| 144 bool refresh_task_pending_; | 142 bool refresh_task_pending_; |
| 143 bool waiting_for_initial_policies_; |
| 145 int64 policy_refresh_rate_ms_; | 144 int64 policy_refresh_rate_ms_; |
| 146 int64 policy_refresh_max_earlier_ms_; | 145 int64 policy_refresh_max_earlier_ms_; |
| 147 int64 policy_refresh_error_delay_ms_; | 146 int64 policy_refresh_error_delay_ms_; |
| 148 int64 token_fetch_error_delay_ms_; | 147 int64 token_fetch_error_delay_ms_; |
| 148 int64 unmanaged_device_refresh_rate_ms_; |
| 149 | 149 |
| 150 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider); | 150 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider); |
| 151 }; | 151 }; |
| 152 | 152 |
| 153 } // namespace policy | 153 } // namespace policy |
| 154 | 154 |
| 155 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ | 155 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ |
| OLD | NEW |