Chromium Code Reviews| 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 TokenService* token_service, | |
| 77 const FilePath& storage_dir, | |
| 78 int64 policy_refresh_rate_ms, | |
| 79 int64 policy_refresh_max_earlier_ms, | |
| 80 int64 policy_refresh_error_delay_ms, | |
| 81 int64 token_fetch_error_delay_ms, | |
| 82 int64 unmanaged_device_refresh_rate_ms); | |
|
Mattias Nissler (ping if slow)
2010/11/26 10:37:45
9 parameters are 5 too many IMHO :) What was wrong
danno
2010/11/26 10:48:36
I disagree, this is testing-specific code that cen
Jakob Kummerow
2010/11/26 11:07:42
(Discussed offline.)
One concrete problem with the
| |
| 83 | |
| 75 // Called by constructors to perform shared initialization. Initialization | 84 // Called by constructors to perform shared initialization. Initialization |
| 76 // requiring the IOThread must not be performed directly in this method, | 85 // requiring the IOThread must not be performed directly in this method, |
| 77 // rather must be deferred until the IOThread is fully initialized. This is | 86 // rather must be deferred until the IOThread is fully initialized. This is |
| 78 // the case in InitializeAfterIOThreadExists. | 87 // the case in InitializeAfterIOThreadExists. |
| 79 void Initialize(); | 88 void Initialize(DeviceManagementBackend* backend, |
| 89 TokenService* token_service, | |
| 90 const FilePath& storage_dir, | |
| 91 int64 policy_refresh_rate_ms, | |
| 92 int64 policy_refresh_max_earlier_ms, | |
| 93 int64 policy_refresh_error_delay_ms, | |
| 94 int64 token_fetch_error_delay_ms, | |
| 95 int64 unmanaged_device_refresh_rate_ms); | |
| 80 | 96 |
| 81 // Called by a deferred task posted to the UI thread to complete the portion | 97 // Called by a deferred task posted to the UI thread to complete the portion |
| 82 // of initialization that requires the IOThread. | 98 // of initialization that requires the IOThread. |
| 83 void InitializeAfterIOThreadExists(); | 99 void InitializeAfterIOThreadExists(); |
| 84 | 100 |
| 85 // Sends a request to the device manager backend to fetch policy if one isn't | 101 // Sends a request to the device manager backend to fetch policy if one isn't |
| 86 // already outstanding. | 102 // already outstanding. |
| 87 void SendPolicyRequest(); | 103 void SendPolicyRequest(); |
| 88 | 104 |
| 89 // Triggers policy refresh, re-requesting device token and policy information | 105 // Triggers policy refresh, re-requesting device token and policy information |
| 90 // as necessary. | 106 // as necessary. |
| 91 void RefreshTaskExecute(); | 107 void RefreshTaskExecute(); |
| 92 | 108 |
| 93 // Schedules a new RefreshTask. | 109 // Schedules a new RefreshTask. |
| 94 void ScheduleRefreshTask(int64 delay_in_milliseconds); | 110 void ScheduleRefreshTask(int64 delay_in_milliseconds); |
| 95 | 111 |
| 96 // Calculates when the next RefreshTask shall be executed. | 112 // Calculates when the next RefreshTask shall be executed. |
| 97 int64 GetRefreshTaskDelay(); | 113 int64 GetRefreshTaskDelay(); |
| 98 | 114 |
| 99 // Returns true if the policy cache is empty and hence no policies are | 115 void StopWaitingForInitialPolicies(); |
| 100 // available. | |
| 101 bool IsPolicyCacheEmpty() const; | |
| 102 | 116 |
| 103 #if defined(OS_CHROMEOS) | 117 #if defined(OS_CHROMEOS) |
| 104 // Send a CLOUD_POLICY_UPDATE notification. | 118 // Send a CLOUD_POLICY_UPDATE notification. |
| 105 void NotifyCloudPolicyUpdate() const; | 119 void NotifyCloudPolicyUpdate() const; |
| 106 #endif | 120 #endif |
| 107 | 121 |
| 108 // Provides the URL at which requests are sent to from the device management | 122 // Provides the URL at which requests are sent to from the device management |
| 109 // backend. | 123 // backend. |
| 110 static std::string GetDeviceManagementURL(); | 124 static std::string GetDeviceManagementURL(); |
| 111 | 125 |
| 112 // Returns the path to the sub-directory in the user data directory | 126 // Returns the path to the sub-directory in the user data directory |
| 113 // in which device management persistent state is stored. | 127 // in which device management persistent state is stored. |
| 114 static FilePath GetOrCreateDeviceManagementDir( | 128 static FilePath GetOrCreateDeviceManagementDir( |
| 115 const FilePath& user_data_dir); | 129 const FilePath& user_data_dir); |
| 116 | 130 |
| 117 // Give unit tests the ability to override timeout settings. | |
| 118 void set_policy_refresh_rate_ms(int64 policy_refresh_rate_ms) { | |
| 119 policy_refresh_rate_ms_ = policy_refresh_rate_ms; | |
| 120 } | |
| 121 void set_policy_refresh_max_earlier_ms(int64 policy_refresh_max_earlier_ms) { | |
| 122 policy_refresh_max_earlier_ms_ = policy_refresh_max_earlier_ms; | |
| 123 } | |
| 124 void set_policy_refresh_error_delay_ms(int64 policy_refresh_error_delay_ms) { | |
| 125 policy_refresh_error_delay_ms_ = policy_refresh_error_delay_ms; | |
| 126 } | |
| 127 void set_token_fetch_error_delay_ms(int64 token_fetch_error_delay_ms) { | |
| 128 token_fetch_error_delay_ms_ = token_fetch_error_delay_ms; | |
| 129 } | |
| 130 | |
| 131 scoped_ptr<DeviceManagementBackend> backend_; | 131 scoped_ptr<DeviceManagementBackend> backend_; |
| 132 TokenService* token_service_; // weak | 132 TokenService* token_service_; // weak |
| 133 scoped_ptr<DeviceManagementPolicyCache> cache_; | 133 scoped_ptr<DeviceManagementPolicyCache> cache_; |
| 134 scoped_refptr<DeviceTokenFetcher> token_fetcher_; | 134 scoped_refptr<DeviceTokenFetcher> token_fetcher_; |
| 135 DeviceTokenFetcher::ObserverRegistrar registrar_; | 135 DeviceTokenFetcher::ObserverRegistrar registrar_; |
| 136 FilePath storage_dir_; | 136 FilePath storage_dir_; |
| 137 bool policy_request_pending_; | 137 bool policy_request_pending_; |
| 138 bool refresh_task_pending_; | 138 bool refresh_task_pending_; |
| 139 bool waiting_for_initial_policies_; | |
| 139 int64 policy_refresh_rate_ms_; | 140 int64 policy_refresh_rate_ms_; |
| 140 int64 policy_refresh_max_earlier_ms_; | 141 int64 policy_refresh_max_earlier_ms_; |
| 141 int64 policy_refresh_error_delay_ms_; | 142 int64 policy_refresh_error_delay_ms_; |
| 142 int64 token_fetch_error_delay_ms_; | 143 int64 token_fetch_error_delay_ms_; |
| 144 int64 unmanaged_device_refresh_rate_ms_; | |
| 143 | 145 |
| 144 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider); | 146 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider); |
| 145 }; | 147 }; |
| 146 | 148 |
| 147 } // namespace policy | 149 } // namespace policy |
| 148 | 150 |
| 149 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ | 151 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ |
| OLD | NEW |