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 #include "chrome/browser/policy/device_management_policy_provider.h" | 5 #include "chrome/browser/policy/device_management_policy_provider.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| 11 #include "base/task.h" | 11 #include "base/task.h" |
| 12 #include "chrome/browser/browser_thread.h" | 12 #include "chrome/browser/browser_thread.h" |
| 13 #include "chrome/browser/policy/cloud_policy_cache.h" | |
| 13 #include "chrome/browser/policy/device_management_backend.h" | 14 #include "chrome/browser/policy/device_management_backend.h" |
| 14 #include "chrome/browser/policy/device_management_policy_cache.h" | 15 #include "chrome/browser/policy/device_management_policy_cache.h" |
| 15 #include "chrome/browser/policy/profile_policy_context.h" | 16 #include "chrome/browser/policy/profile_policy_context.h" |
| 16 #include "chrome/browser/policy/proto/device_management_constants.h" | 17 #include "chrome/browser/policy/proto/device_management_constants.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/notification_service.h" | 21 #include "chrome/common/notification_service.h" |
| 21 #include "chrome/common/notification_type.h" | 22 #include "chrome/common/notification_type.h" |
| 22 | 23 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 33 | 34 |
| 34 // These are the base values for delays before retrying after an error. They | 35 // These are the base values for delays before retrying after an error. They |
| 35 // will be doubled each time they are used. | 36 // will be doubled each time they are used. |
| 36 const int64 kPolicyRefreshErrorDelayInMilliseconds = 3 * 1000; // 3 seconds | 37 const int64 kPolicyRefreshErrorDelayInMilliseconds = 3 * 1000; // 3 seconds |
| 37 const int64 kDeviceTokenRefreshErrorDelayInMilliseconds = 3 * 1000; | 38 const int64 kDeviceTokenRefreshErrorDelayInMilliseconds = 3 * 1000; |
| 38 // For unmanaged devices, check once per day whether they're still unmanaged. | 39 // For unmanaged devices, check once per day whether they're still unmanaged. |
| 39 const int64 kPolicyRefreshUnmanagedDeviceInMilliseconds = 24 * 60 * 60 * 1000; | 40 const int64 kPolicyRefreshUnmanagedDeviceInMilliseconds = 24 * 60 * 60 * 1000; |
| 40 | 41 |
| 41 const FilePath::StringType kDeviceTokenFilename = FILE_PATH_LITERAL("Token"); | 42 const FilePath::StringType kDeviceTokenFilename = FILE_PATH_LITERAL("Token"); |
| 42 const FilePath::StringType kPolicyFilename = FILE_PATH_LITERAL("Policy"); | 43 const FilePath::StringType kPolicyFilename = FILE_PATH_LITERAL("Policy"); |
| 44 const FilePath::StringType kCloudPolicyFilename = | |
| 45 FILE_PATH_LITERAL("CloudPolicy"); | |
|
Mattias Nissler (ping if slow)
2011/02/02 12:27:55
See my other comment about having only one cache.
Jakob Kummerow
2011/02/03 14:36:52
Done.
| |
| 43 | 46 |
| 44 // Calls back into the provider to refresh policy. | 47 // Calls back into the provider to refresh policy. |
| 45 class DeviceManagementPolicyProvider::RefreshTask : public CancelableTask { | 48 class DeviceManagementPolicyProvider::RefreshTask : public CancelableTask { |
| 46 public: | 49 public: |
| 47 explicit RefreshTask(DeviceManagementPolicyProvider* provider) | 50 explicit RefreshTask(DeviceManagementPolicyProvider* provider) |
| 48 : provider_(provider) {} | 51 : provider_(provider) {} |
| 49 | 52 |
| 50 // Task implementation: | 53 // Task implementation: |
| 51 virtual void Run() { | 54 virtual void Run() { |
| 52 if (provider_) | 55 if (provider_) |
| 53 provider_->RefreshTaskExecute(); | 56 provider_->RefreshTaskExecute(); |
| 54 } | 57 } |
| 55 | 58 |
| 56 // CancelableTask implementation: | 59 // CancelableTask implementation: |
| 57 virtual void Cancel() { | 60 virtual void Cancel() { |
| 58 provider_ = NULL; | 61 provider_ = NULL; |
| 59 } | 62 } |
| 60 | 63 |
| 61 private: | 64 private: |
| 62 DeviceManagementPolicyProvider* provider_; | 65 DeviceManagementPolicyProvider* provider_; |
| 63 }; | 66 }; |
| 64 | 67 |
| 65 DeviceManagementPolicyProvider::DeviceManagementPolicyProvider( | 68 DeviceManagementPolicyProvider::DeviceManagementPolicyProvider( |
| 66 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list, | 69 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list, |
| 67 DeviceManagementBackend* backend, | 70 DeviceManagementBackend* backend, |
| 68 Profile* profile) | 71 Profile* profile, |
| 72 bool cloud_policy_enabled) | |
| 69 : ConfigurationPolicyProvider(policy_list) { | 73 : ConfigurationPolicyProvider(policy_list) { |
| 70 Initialize(backend, | 74 Initialize(backend, |
| 71 profile, | 75 profile, |
| 76 cloud_policy_enabled, | |
| 72 ProfilePolicyContext::kDefaultPolicyRefreshRateInMilliseconds, | 77 ProfilePolicyContext::kDefaultPolicyRefreshRateInMilliseconds, |
| 73 kPolicyRefreshDeviationFactorPercent, | 78 kPolicyRefreshDeviationFactorPercent, |
| 74 kPolicyRefreshDeviationMaxInMilliseconds, | 79 kPolicyRefreshDeviationMaxInMilliseconds, |
| 75 kPolicyRefreshErrorDelayInMilliseconds, | 80 kPolicyRefreshErrorDelayInMilliseconds, |
| 76 kDeviceTokenRefreshErrorDelayInMilliseconds, | 81 kDeviceTokenRefreshErrorDelayInMilliseconds, |
| 77 kPolicyRefreshUnmanagedDeviceInMilliseconds); | 82 kPolicyRefreshUnmanagedDeviceInMilliseconds); |
| 78 } | 83 } |
| 79 | 84 |
| 80 DeviceManagementPolicyProvider::~DeviceManagementPolicyProvider() { | 85 DeviceManagementPolicyProvider::~DeviceManagementPolicyProvider() { |
| 81 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, | 86 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, |
| 82 observer_list_, | 87 observer_list_, |
| 83 OnProviderGoingAway()); | 88 OnProviderGoingAway()); |
| 84 CancelRefreshTask(); | 89 CancelRefreshTask(); |
| 85 } | 90 } |
| 86 | 91 |
| 87 bool DeviceManagementPolicyProvider::Provide( | 92 bool DeviceManagementPolicyProvider::Provide( |
| 88 ConfigurationPolicyStoreInterface* policy_store) { | 93 ConfigurationPolicyStoreInterface* policy_store) { |
| 89 scoped_ptr<DictionaryValue> policies(cache_->GetPolicy()); | 94 if (cloud_policy_enabled_) { |
| 90 DecodePolicyValueTree(policies.get(), policy_store); | 95 scoped_ptr<PolicyMapType> policies(cache2_->GetPolicy()); |
| 96 ApplyPolicyMap(policies.get(), policy_store); | |
| 97 } else { | |
| 98 scoped_ptr<DictionaryValue> policies(cache_->GetPolicy()); | |
| 99 DecodePolicyValueTree(policies.get(), policy_store); | |
| 100 } | |
| 91 return true; | 101 return true; |
| 92 } | 102 } |
| 93 | 103 |
| 94 bool DeviceManagementPolicyProvider::IsInitializationComplete() const { | 104 bool DeviceManagementPolicyProvider::IsInitializationComplete() const { |
| 95 return !cache_->last_policy_refresh_time().is_null(); | 105 if (cloud_policy_enabled_) |
| 106 return !cache2_->last_policy_refresh_time().is_null(); | |
| 107 else | |
| 108 return !cache_->last_policy_refresh_time().is_null(); | |
| 96 } | 109 } |
| 97 | 110 |
| 98 void DeviceManagementPolicyProvider::HandlePolicyResponse( | 111 void DeviceManagementPolicyProvider::HandlePolicyResponse( |
| 99 const em::DevicePolicyResponse& response) { | 112 const em::DevicePolicyResponse& response) { |
| 100 DCHECK(TokenAvailable()); | 113 DCHECK(TokenAvailable()); |
| 101 if (cache_->SetPolicy(response)) { | 114 if (cache_->SetPolicy(response)) { |
| 102 initial_fetch_done_ = true; | 115 initial_fetch_done_ = true; |
| 103 NotifyCloudPolicyUpdate(); | 116 NotifyCloudPolicyUpdate(); |
| 104 } | 117 } |
| 105 SetState(STATE_POLICY_VALID); | 118 SetState(STATE_POLICY_VALID); |
| 106 } | 119 } |
| 107 | 120 |
| 121 void DeviceManagementPolicyProvider::HandleCloudPolicyResponse( | |
| 122 const em::CloudPolicyResponse& response) { | |
| 123 DCHECK(TokenAvailable()); | |
| 124 if (cache2_->SetPolicy(response)) { | |
| 125 initial_fetch_done_ = true; | |
| 126 NotifyCloudPolicyUpdate(); | |
| 127 } | |
| 128 SetState(STATE_POLICY_VALID); | |
| 129 } | |
| 130 | |
| 108 void DeviceManagementPolicyProvider::OnError( | 131 void DeviceManagementPolicyProvider::OnError( |
| 109 DeviceManagementBackend::ErrorCode code) { | 132 DeviceManagementBackend::ErrorCode code) { |
| 110 DCHECK(TokenAvailable()); | 133 DCHECK(TokenAvailable()); |
| 111 if (code == DeviceManagementBackend::kErrorServiceDeviceNotFound || | 134 if (code == DeviceManagementBackend::kErrorServiceDeviceNotFound || |
| 112 code == DeviceManagementBackend::kErrorServiceManagementTokenInvalid) { | 135 code == DeviceManagementBackend::kErrorServiceManagementTokenInvalid) { |
| 113 LOG(WARNING) << "The device token was either invalid or unknown to the " | 136 LOG(WARNING) << "The device token was either invalid or unknown to the " |
| 114 << "device manager, re-registering device."; | 137 << "device manager, re-registering device."; |
| 115 SetState(STATE_TOKEN_RESET); | 138 SetState(STATE_TOKEN_RESET); |
| 116 } else if (code == | 139 } else if (code == |
| 117 DeviceManagementBackend::kErrorServiceManagementNotSupported) { | 140 DeviceManagementBackend::kErrorServiceManagementNotSupported) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 133 | 156 |
| 134 void DeviceManagementPolicyProvider::OnTokenError() { | 157 void DeviceManagementPolicyProvider::OnTokenError() { |
| 135 DCHECK(!TokenAvailable()); | 158 DCHECK(!TokenAvailable()); |
| 136 LOG(WARNING) << "Could not retrieve device token."; | 159 LOG(WARNING) << "Could not retrieve device token."; |
| 137 SetState(STATE_TOKEN_ERROR); | 160 SetState(STATE_TOKEN_ERROR); |
| 138 } | 161 } |
| 139 | 162 |
| 140 void DeviceManagementPolicyProvider::OnNotManaged() { | 163 void DeviceManagementPolicyProvider::OnNotManaged() { |
| 141 DCHECK(!TokenAvailable()); | 164 DCHECK(!TokenAvailable()); |
| 142 VLOG(1) << "This device is not managed."; | 165 VLOG(1) << "This device is not managed."; |
| 143 cache_->SetDeviceUnmanaged(); | 166 if (cloud_policy_enabled_) |
| 167 cache2_->SetUnmanaged(); | |
| 168 else | |
| 169 cache_->SetDeviceUnmanaged(); | |
| 144 SetState(STATE_UNMANAGED); | 170 SetState(STATE_UNMANAGED); |
| 145 } | 171 } |
| 146 | 172 |
| 147 void DeviceManagementPolicyProvider::SetRefreshRate( | 173 void DeviceManagementPolicyProvider::SetRefreshRate( |
| 148 int64 refresh_rate_milliseconds) { | 174 int64 refresh_rate_milliseconds) { |
| 149 policy_refresh_rate_ms_ = refresh_rate_milliseconds; | 175 policy_refresh_rate_ms_ = refresh_rate_milliseconds; |
| 150 | 176 |
| 151 // Reschedule the refresh task if necessary. | 177 // Reschedule the refresh task if necessary. |
| 152 if (state_ == STATE_POLICY_VALID) | 178 if (state_ == STATE_POLICY_VALID) |
| 153 SetState(STATE_POLICY_VALID); | 179 SetState(STATE_POLICY_VALID); |
| 154 } | 180 } |
| 155 | 181 |
| 156 DeviceManagementPolicyProvider::DeviceManagementPolicyProvider( | 182 DeviceManagementPolicyProvider::DeviceManagementPolicyProvider( |
| 157 const PolicyDefinitionList* policy_list, | 183 const PolicyDefinitionList* policy_list, |
| 158 DeviceManagementBackend* backend, | 184 DeviceManagementBackend* backend, |
| 159 Profile* profile, | 185 Profile* profile, |
| 186 bool cloud_policy_enabled, | |
| 160 int64 policy_refresh_rate_ms, | 187 int64 policy_refresh_rate_ms, |
| 161 int policy_refresh_deviation_factor_percent, | 188 int policy_refresh_deviation_factor_percent, |
| 162 int64 policy_refresh_deviation_max_ms, | 189 int64 policy_refresh_deviation_max_ms, |
| 163 int64 policy_refresh_error_delay_ms, | 190 int64 policy_refresh_error_delay_ms, |
| 164 int64 token_fetch_error_delay_ms, | 191 int64 token_fetch_error_delay_ms, |
| 165 int64 unmanaged_device_refresh_rate_ms) | 192 int64 unmanaged_device_refresh_rate_ms) |
| 166 : ConfigurationPolicyProvider(policy_list) { | 193 : ConfigurationPolicyProvider(policy_list) { |
| 167 Initialize(backend, | 194 Initialize(backend, |
| 168 profile, | 195 profile, |
| 196 cloud_policy_enabled, | |
| 169 policy_refresh_rate_ms, | 197 policy_refresh_rate_ms, |
| 170 policy_refresh_deviation_factor_percent, | 198 policy_refresh_deviation_factor_percent, |
| 171 policy_refresh_deviation_max_ms, | 199 policy_refresh_deviation_max_ms, |
| 172 policy_refresh_error_delay_ms, | 200 policy_refresh_error_delay_ms, |
| 173 token_fetch_error_delay_ms, | 201 token_fetch_error_delay_ms, |
| 174 unmanaged_device_refresh_rate_ms); | 202 unmanaged_device_refresh_rate_ms); |
| 175 } | 203 } |
| 176 | 204 |
| 177 void DeviceManagementPolicyProvider::Initialize( | 205 void DeviceManagementPolicyProvider::Initialize( |
| 178 DeviceManagementBackend* backend, | 206 DeviceManagementBackend* backend, |
| 179 Profile* profile, | 207 Profile* profile, |
| 208 bool cloud_policy_enabled, | |
| 180 int64 policy_refresh_rate_ms, | 209 int64 policy_refresh_rate_ms, |
| 181 int policy_refresh_deviation_factor_percent, | 210 int policy_refresh_deviation_factor_percent, |
| 182 int64 policy_refresh_deviation_max_ms, | 211 int64 policy_refresh_deviation_max_ms, |
| 183 int64 policy_refresh_error_delay_ms, | 212 int64 policy_refresh_error_delay_ms, |
| 184 int64 token_fetch_error_delay_ms, | 213 int64 token_fetch_error_delay_ms, |
| 185 int64 unmanaged_device_refresh_rate_ms) { | 214 int64 unmanaged_device_refresh_rate_ms) { |
| 186 DCHECK(profile); | 215 DCHECK(profile); |
| 187 backend_.reset(backend); | 216 backend_.reset(backend); |
| 188 profile_ = profile; | 217 profile_ = profile; |
| 189 storage_dir_ = GetOrCreateDeviceManagementDir(profile_->GetPath()); | 218 storage_dir_ = GetOrCreateDeviceManagementDir(profile_->GetPath()); |
| 190 state_ = STATE_INITIALIZING; | 219 state_ = STATE_INITIALIZING; |
| 191 initial_fetch_done_ = false; | 220 initial_fetch_done_ = false; |
| 192 refresh_task_ = NULL; | 221 refresh_task_ = NULL; |
| 193 policy_refresh_rate_ms_ = policy_refresh_rate_ms; | 222 policy_refresh_rate_ms_ = policy_refresh_rate_ms; |
| 194 policy_refresh_deviation_factor_percent_ = | 223 policy_refresh_deviation_factor_percent_ = |
| 195 policy_refresh_deviation_factor_percent; | 224 policy_refresh_deviation_factor_percent; |
| 196 policy_refresh_deviation_max_ms_ = policy_refresh_deviation_max_ms; | 225 policy_refresh_deviation_max_ms_ = policy_refresh_deviation_max_ms; |
| 197 policy_refresh_error_delay_ms_ = policy_refresh_error_delay_ms; | 226 policy_refresh_error_delay_ms_ = policy_refresh_error_delay_ms; |
| 198 effective_policy_refresh_error_delay_ms_ = policy_refresh_error_delay_ms; | 227 effective_policy_refresh_error_delay_ms_ = policy_refresh_error_delay_ms; |
| 199 token_fetch_error_delay_ms_ = token_fetch_error_delay_ms; | 228 token_fetch_error_delay_ms_ = token_fetch_error_delay_ms; |
| 200 effective_token_fetch_error_delay_ms_ = token_fetch_error_delay_ms; | 229 effective_token_fetch_error_delay_ms_ = token_fetch_error_delay_ms; |
| 201 unmanaged_device_refresh_rate_ms_ = unmanaged_device_refresh_rate_ms; | 230 unmanaged_device_refresh_rate_ms_ = unmanaged_device_refresh_rate_ms; |
| 202 | 231 |
| 203 const FilePath policy_path = storage_dir_.Append(kPolicyFilename); | 232 cloud_policy_enabled_ = cloud_policy_enabled; |
| 204 cache_.reset(new DeviceManagementPolicyCache(policy_path)); | 233 if (cloud_policy_enabled_) { |
| 205 cache_->LoadPolicyFromFile(); | 234 const FilePath policy_path = storage_dir_.Append(kCloudPolicyFilename); |
| 235 cache2_.reset(new CloudPolicyCache(policy_path)); | |
| 236 cache2_->LoadPolicyFromFile(); | |
| 237 } else { | |
| 238 const FilePath policy_path = storage_dir_.Append(kPolicyFilename); | |
| 239 cache_.reset(new DeviceManagementPolicyCache(policy_path)); | |
| 240 cache_->LoadPolicyFromFile(); | |
| 241 } | |
| 206 | 242 |
| 207 SetDeviceTokenFetcher(new DeviceTokenFetcher(backend_.get(), profile, | 243 SetDeviceTokenFetcher(new DeviceTokenFetcher(backend_.get(), profile, |
| 208 GetTokenPath())); | 244 GetTokenPath())); |
| 209 | 245 |
| 210 if (cache_->is_device_unmanaged()) { | 246 if ((cloud_policy_enabled_ && cache2_->is_unmanaged()) || |
| 247 (!cloud_policy_enabled_ && cache_->is_device_unmanaged())) { | |
| 211 // This is a non-first login on an unmanaged device. | 248 // This is a non-first login on an unmanaged device. |
| 212 SetState(STATE_UNMANAGED); | 249 SetState(STATE_UNMANAGED); |
| 213 } else { | 250 } else { |
| 214 SetState(STATE_INITIALIZING); | 251 SetState(STATE_INITIALIZING); |
| 215 } | 252 } |
| 216 } | 253 } |
| 217 | 254 |
| 218 void DeviceManagementPolicyProvider::AddObserver( | 255 void DeviceManagementPolicyProvider::AddObserver( |
| 219 ConfigurationPolicyProvider::Observer* observer) { | 256 ConfigurationPolicyProvider::Observer* observer) { |
| 220 observer_list_.AddObserver(observer); | 257 observer_list_.AddObserver(observer); |
| 221 } | 258 } |
| 222 | 259 |
| 223 void DeviceManagementPolicyProvider::RemoveObserver( | 260 void DeviceManagementPolicyProvider::RemoveObserver( |
| 224 ConfigurationPolicyProvider::Observer* observer) { | 261 ConfigurationPolicyProvider::Observer* observer) { |
| 225 observer_list_.RemoveObserver(observer); | 262 observer_list_.RemoveObserver(observer); |
| 226 } | 263 } |
| 227 | 264 |
| 228 void DeviceManagementPolicyProvider::SendPolicyRequest() { | 265 void DeviceManagementPolicyProvider::SendPolicyRequest() { |
| 229 em::DevicePolicyRequest policy_request; | 266 if (cloud_policy_enabled_) { |
| 230 policy_request.set_policy_scope(kChromePolicyScope); | 267 em::CloudPolicyRequest policy_request; |
| 231 em::DevicePolicySettingRequest* setting = | 268 policy_request.set_policy_scope(kChromePolicyScope); |
| 232 policy_request.add_setting_request(); | 269 backend_->ProcessCloudPolicyRequest(token_fetcher_->GetDeviceToken(), |
| 233 setting->set_key(kChromeDevicePolicySettingKey); | 270 token_fetcher_->GetDeviceID(), |
| 234 setting->set_watermark(""); | 271 policy_request, this); |
| 235 backend_->ProcessPolicyRequest(token_fetcher_->GetDeviceToken(), | 272 } else { |
| 236 token_fetcher_->GetDeviceID(), | 273 em::DevicePolicyRequest policy_request; |
| 237 policy_request, this); | 274 policy_request.set_policy_scope(kChromePolicyScope); |
| 275 em::DevicePolicySettingRequest* setting = | |
| 276 policy_request.add_setting_request(); | |
| 277 setting->set_key(kChromeDevicePolicySettingKey); | |
| 278 setting->set_watermark(""); | |
| 279 backend_->ProcessPolicyRequest(token_fetcher_->GetDeviceToken(), | |
| 280 token_fetcher_->GetDeviceID(), | |
| 281 policy_request, this); | |
| 282 } | |
| 238 } | 283 } |
| 239 | 284 |
| 240 void DeviceManagementPolicyProvider::RefreshTaskExecute() { | 285 void DeviceManagementPolicyProvider::RefreshTaskExecute() { |
| 241 DCHECK(refresh_task_); | 286 DCHECK(refresh_task_); |
| 242 refresh_task_ = NULL; | 287 refresh_task_ = NULL; |
| 243 | 288 |
| 244 switch (state_) { | 289 switch (state_) { |
| 245 case STATE_INITIALIZING: | 290 case STATE_INITIALIZING: |
| 246 token_fetcher_->StartFetching(); | 291 token_fetcher_->StartFetching(); |
| 247 return; | 292 return; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 // observers now. | 337 // observers now. |
| 293 if (!initial_fetch_done_ && | 338 if (!initial_fetch_done_ && |
| 294 new_state != STATE_INITIALIZING && | 339 new_state != STATE_INITIALIZING && |
| 295 new_state != STATE_TOKEN_VALID) { | 340 new_state != STATE_TOKEN_VALID) { |
| 296 initial_fetch_done_ = true; | 341 initial_fetch_done_ = true; |
| 297 NotifyCloudPolicyUpdate(); | 342 NotifyCloudPolicyUpdate(); |
| 298 } | 343 } |
| 299 | 344 |
| 300 base::Time now(base::Time::NowFromSystemTime()); | 345 base::Time now(base::Time::NowFromSystemTime()); |
| 301 base::Time refresh_at; | 346 base::Time refresh_at; |
| 302 base::Time last_refresh(cache_->last_policy_refresh_time()); | 347 base::Time last_refresh(cloud_policy_enabled_ ? |
| 348 cache2_->last_policy_refresh_time() : | |
| 349 cache_->last_policy_refresh_time()); | |
| 303 if (last_refresh.is_null()) | 350 if (last_refresh.is_null()) |
| 304 last_refresh = now; | 351 last_refresh = now; |
| 305 | 352 |
| 306 // Determine when to take the next step. | 353 // Determine when to take the next step. |
| 307 switch (state_) { | 354 switch (state_) { |
| 308 case STATE_INITIALIZING: | 355 case STATE_INITIALIZING: |
| 309 refresh_at = now; | 356 refresh_at = now; |
| 310 break; | 357 break; |
| 311 case STATE_TOKEN_VALID: | 358 case STATE_TOKEN_VALID: |
| 312 effective_token_fetch_error_delay_ms_ = token_fetch_error_delay_ms_; | 359 effective_token_fetch_error_delay_ms_ = token_fetch_error_delay_ms_; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 const FilePath device_management_dir = user_data_dir.Append( | 422 const FilePath device_management_dir = user_data_dir.Append( |
| 376 FILE_PATH_LITERAL("Device Management")); | 423 FILE_PATH_LITERAL("Device Management")); |
| 377 if (!file_util::DirectoryExists(device_management_dir)) { | 424 if (!file_util::DirectoryExists(device_management_dir)) { |
| 378 if (!file_util::CreateDirectory(device_management_dir)) | 425 if (!file_util::CreateDirectory(device_management_dir)) |
| 379 NOTREACHED(); | 426 NOTREACHED(); |
| 380 } | 427 } |
| 381 return device_management_dir; | 428 return device_management_dir; |
| 382 } | 429 } |
| 383 | 430 |
| 384 } // namespace policy | 431 } // namespace policy |
| OLD | NEW |