Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/cryptauth/cryptauth_device_manager.h" | 5 #include "components/cryptauth/cryptauth_device_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdexcept> | 8 #include <stdexcept> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 bool CryptAuthDeviceManager::IsSyncInProgress() const { | 360 bool CryptAuthDeviceManager::IsSyncInProgress() const { |
| 361 return scheduler_->GetSyncState() == | 361 return scheduler_->GetSyncState() == |
| 362 SyncScheduler::SyncState::SYNC_IN_PROGRESS; | 362 SyncScheduler::SyncState::SYNC_IN_PROGRESS; |
| 363 } | 363 } |
| 364 | 364 |
| 365 bool CryptAuthDeviceManager::IsRecoveringFromFailure() const { | 365 bool CryptAuthDeviceManager::IsRecoveringFromFailure() const { |
| 366 return scheduler_->GetStrategy() == | 366 return scheduler_->GetStrategy() == |
| 367 SyncScheduler::Strategy::AGGRESSIVE_RECOVERY; | 367 SyncScheduler::Strategy::AGGRESSIVE_RECOVERY; |
| 368 } | 368 } |
| 369 | 369 |
| 370 const std::vector<ExternalDeviceInfo> | |
| 371 CryptAuthDeviceManager::unlock_keys() const { | |
| 372 std::vector<ExternalDeviceInfo> unlock_keys; | |
| 373 for (const auto& device : synced_devices_) { | |
| 374 if (device.unlock_key()) { | |
| 375 unlock_keys.push_back(device); | |
| 376 } | |
| 377 } | |
| 378 return unlock_keys; | |
| 379 } | |
| 380 | |
| 381 const std::vector<ExternalDeviceInfo> | |
| 382 CryptAuthDeviceManager::tether_hosts() const { | |
| 383 std::vector<ExternalDeviceInfo> tether_hosts; | |
| 384 for (const auto& device : synced_devices_) { | |
| 385 if (device.mobile_hotspot_supported()) { | |
| 386 tether_hosts.push_back(device); | |
| 387 } | |
| 388 } | |
| 389 return tether_hosts; | |
| 390 } | |
| 391 | |
| 370 void CryptAuthDeviceManager::OnGetMyDevicesSuccess( | 392 void CryptAuthDeviceManager::OnGetMyDevicesSuccess( |
| 371 const cryptauth::GetMyDevicesResponse& response) { | 393 const cryptauth::GetMyDevicesResponse& response) { |
| 372 // Update the unlock keys stored in the user's prefs. | 394 // Update the unlock keys stored in the user's prefs. |
| 373 std::unique_ptr<base::ListValue> unlock_keys_pref(new base::ListValue()); | 395 std::unique_ptr<base::ListValue> unlock_keys_pref(new base::ListValue()); |
| 374 std::unique_ptr<base::ListValue> devices_as_list(new base::ListValue()); | 396 std::unique_ptr<base::ListValue> devices_as_list(new base::ListValue()); |
| 375 for (const auto& device : response.devices()) { | 397 for (const auto& device : response.devices()) { |
| 376 devices_as_list->Append(UnlockKeyToDictionary(device)); | 398 devices_as_list->Append(UnlockKeyToDictionary(device)); |
| 377 if (device.unlock_key()) | 399 unlock_keys_pref->Append(UnlockKeyToDictionary(device)); |
|
Jeremy Klein
2016/12/07 22:19:54
Any reason not to just use devices_as_list and rem
Kyle Horimoto
2016/12/07 22:25:35
Done.
| |
| 378 unlock_keys_pref->Append(UnlockKeyToDictionary(device)); | |
| 379 } | 400 } |
| 380 PA_LOG(INFO) << "Devices Synced:\n" << *devices_as_list; | 401 PA_LOG(INFO) << "Devices Synced:\n" << *devices_as_list; |
| 381 | 402 |
| 382 bool unlock_keys_changed = !unlock_keys_pref->Equals( | 403 bool unlock_keys_changed = !unlock_keys_pref->Equals( |
| 383 pref_service_->GetList(prefs::kCryptAuthDeviceSyncUnlockKeys)); | 404 pref_service_->GetList(prefs::kCryptAuthDeviceSyncUnlockKeys)); |
| 384 { | 405 { |
| 385 ListPrefUpdate update(pref_service_, prefs::kCryptAuthDeviceSyncUnlockKeys); | 406 ListPrefUpdate update(pref_service_, prefs::kCryptAuthDeviceSyncUnlockKeys); |
| 386 update.Get()->Swap(unlock_keys_pref.get()); | 407 update.Get()->Swap(unlock_keys_pref.get()); |
| 387 } | 408 } |
| 388 UpdateUnlockKeysFromPrefs(); | 409 UpdateUnlockKeysFromPrefs(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 kDeviceSyncMaxJitterRatio, "CryptAuth DeviceSync"); | 445 kDeviceSyncMaxJitterRatio, "CryptAuth DeviceSync"); |
| 425 } | 446 } |
| 426 | 447 |
| 427 void CryptAuthDeviceManager::OnResyncMessage() { | 448 void CryptAuthDeviceManager::OnResyncMessage() { |
| 428 ForceSyncNow(cryptauth::INVOCATION_REASON_SERVER_INITIATED); | 449 ForceSyncNow(cryptauth::INVOCATION_REASON_SERVER_INITIATED); |
| 429 } | 450 } |
| 430 | 451 |
| 431 void CryptAuthDeviceManager::UpdateUnlockKeysFromPrefs() { | 452 void CryptAuthDeviceManager::UpdateUnlockKeysFromPrefs() { |
| 432 const base::ListValue* unlock_key_list = | 453 const base::ListValue* unlock_key_list = |
| 433 pref_service_->GetList(prefs::kCryptAuthDeviceSyncUnlockKeys); | 454 pref_service_->GetList(prefs::kCryptAuthDeviceSyncUnlockKeys); |
| 434 unlock_keys_.clear(); | 455 synced_devices_.clear(); |
| 435 for (size_t i = 0; i < unlock_key_list->GetSize(); ++i) { | 456 for (size_t i = 0; i < unlock_key_list->GetSize(); ++i) { |
| 436 const base::DictionaryValue* unlock_key_dictionary; | 457 const base::DictionaryValue* unlock_key_dictionary; |
| 437 if (unlock_key_list->GetDictionary(i, &unlock_key_dictionary)) { | 458 if (unlock_key_list->GetDictionary(i, &unlock_key_dictionary)) { |
| 438 cryptauth::ExternalDeviceInfo unlock_key; | 459 cryptauth::ExternalDeviceInfo unlock_key; |
| 439 if (DictionaryToUnlockKey(*unlock_key_dictionary, &unlock_key)) { | 460 if (DictionaryToUnlockKey(*unlock_key_dictionary, &unlock_key)) { |
| 440 unlock_keys_.push_back(unlock_key); | 461 synced_devices_.push_back(unlock_key); |
| 441 } else { | 462 } else { |
| 442 PA_LOG(ERROR) << "Unable to deserialize unlock key dictionary " | 463 PA_LOG(ERROR) << "Unable to deserialize unlock key dictionary " |
| 443 << "(index=" << i << "):\n" << *unlock_key_dictionary; | 464 << "(index=" << i << "):\n" << *unlock_key_dictionary; |
| 444 } | 465 } |
| 445 } else { | 466 } else { |
| 446 PA_LOG(ERROR) << "Can not get dictionary in list of unlock keys " | 467 PA_LOG(ERROR) << "Can not get dictionary in list of unlock keys " |
| 447 << "(index=" << i << "):\n" << *unlock_key_list; | 468 << "(index=" << i << "):\n" << *unlock_key_list; |
| 448 } | 469 } |
| 449 } | 470 } |
| 450 } | 471 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 request.set_invocation_reason(invocation_reason); | 506 request.set_invocation_reason(invocation_reason); |
| 486 request.set_allow_stale_read(is_sync_speculative); | 507 request.set_allow_stale_read(is_sync_speculative); |
| 487 cryptauth_client_->GetMyDevices( | 508 cryptauth_client_->GetMyDevices( |
| 488 request, base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesSuccess, | 509 request, base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesSuccess, |
| 489 weak_ptr_factory_.GetWeakPtr()), | 510 weak_ptr_factory_.GetWeakPtr()), |
| 490 base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesFailure, | 511 base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesFailure, |
| 491 weak_ptr_factory_.GetWeakPtr())); | 512 weak_ptr_factory_.GetWeakPtr())); |
| 492 } | 513 } |
| 493 | 514 |
| 494 } // namespace cryptauth | 515 } // namespace cryptauth |
| OLD | NEW |