| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/cloud_policy_controller.h" | 5 #include "chrome/browser/policy/cloud_policy_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 // Will retry last operation but gracefully backing off. | 239 // Will retry last operation but gracefully backing off. |
| 240 SetState(STATE_POLICY_ERROR); | 240 SetState(STATE_POLICY_ERROR); |
| 241 return; | 241 return; |
| 242 } | 242 } |
| 243 | 243 |
| 244 NOTREACHED(); | 244 NOTREACHED(); |
| 245 SetState(STATE_POLICY_ERROR); | 245 SetState(STATE_POLICY_ERROR); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void CloudPolicyController::OnDeviceTokenChanged() { | 248 void CloudPolicyController::OnDeviceTokenChanged() { |
| 249 if (data_store_->device_token().empty()) | 249 if (data_store_->device_token().empty()) { |
| 250 // Additionally clear the generated device id to ensure we don't reuse old |
| 251 // ids which could be potentially used for user tracking. |
| 252 data_store_->set_device_id(std::string()); |
| 250 SetState(STATE_TOKEN_UNAVAILABLE); | 253 SetState(STATE_TOKEN_UNAVAILABLE); |
| 251 else | 254 } else { |
| 252 SetState(STATE_TOKEN_VALID); | 255 SetState(STATE_TOKEN_VALID); |
| 256 } |
| 253 } | 257 } |
| 254 | 258 |
| 255 void CloudPolicyController::OnCredentialsChanged() { | 259 void CloudPolicyController::OnCredentialsChanged() { |
| 256 // This notification is only interesting if we don't have a device token. | 260 // This notification is only interesting if we don't have a device token. |
| 257 // If we already have a device token, that must be matching the current | 261 // If we already have a device token, that must be matching the current |
| 258 // user, because (1) we always recreate the policy subsystem after user | 262 // user, because (1) we always recreate the policy subsystem after user |
| 259 // login (2) tokens are cached per user. | 263 // login (2) tokens are cached per user. |
| 260 if (data_store_->device_token().empty()) { | 264 if (data_store_->device_token().empty()) { |
| 261 notifier_->Inform(CloudPolicySubsystem::UNENROLLED, | 265 notifier_->Inform(CloudPolicySubsystem::UNENROLLED, |
| 262 CloudPolicySubsystem::NO_DETAILS, | 266 CloudPolicySubsystem::NO_DETAILS, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 314 |
| 311 bool CloudPolicyController::ReadyToFetchToken() { | 315 bool CloudPolicyController::ReadyToFetchToken() { |
| 312 return data_store_->token_cache_loaded() && | 316 return data_store_->token_cache_loaded() && |
| 313 !data_store_->user_name().empty() && | 317 !data_store_->user_name().empty() && |
| 314 data_store_->has_auth_token(); | 318 data_store_->has_auth_token(); |
| 315 } | 319 } |
| 316 | 320 |
| 317 void CloudPolicyController::FetchToken() { | 321 void CloudPolicyController::FetchToken() { |
| 318 if (ReadyToFetchToken()) { | 322 if (ReadyToFetchToken()) { |
| 319 if (CanBeInManagedDomain(data_store_->user_name())) { | 323 if (CanBeInManagedDomain(data_store_->user_name())) { |
| 320 // Generate a new random device id. (It'll only be kept if registration | 324 // Either use an already prepopulated id or generate a new random device |
| 321 // succeeds.) | 325 // id. (It'll only be kept if registration succeeds.) |
| 322 data_store_->set_device_id(base::GenerateGUID()); | 326 if (data_store_->device_id().empty()) |
| 327 data_store_->set_device_id(base::GenerateGUID()); |
| 323 token_fetcher_->FetchToken(); | 328 token_fetcher_->FetchToken(); |
| 324 } else { | 329 } else { |
| 325 SetState(STATE_TOKEN_UNMANAGED); | 330 SetState(STATE_TOKEN_UNMANAGED); |
| 326 } | 331 } |
| 327 } else { | 332 } else { |
| 328 VLOG(1) << "Not ready to fetch DMToken yet, will try again later."; | 333 VLOG(1) << "Not ready to fetch DMToken yet, will try again later."; |
| 329 } | 334 } |
| 330 } | 335 } |
| 331 | 336 |
| 332 void CloudPolicyController::SendPolicyRequest() { | 337 void CloudPolicyController::SendPolicyRequest() { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 | 490 |
| 486 base::Time CloudPolicyController::GetLastRefreshTime(const base::Time& now) { | 491 base::Time CloudPolicyController::GetLastRefreshTime(const base::Time& now) { |
| 487 base::Time last_refresh(cache_->last_policy_refresh_time()); | 492 base::Time last_refresh(cache_->last_policy_refresh_time()); |
| 488 if (last_refresh.is_null()) | 493 if (last_refresh.is_null()) |
| 489 last_refresh = now; | 494 last_refresh = now; |
| 490 | 495 |
| 491 return last_refresh; | 496 return last_refresh; |
| 492 } | 497 } |
| 493 | 498 |
| 494 } // namespace policy | 499 } // namespace policy |
| OLD | NEW |