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::synced_devices() const { | |
372 return synced_devices_; | |
373 } | |
374 | |
375 const std::vector<ExternalDeviceInfo> | |
376 CryptAuthDeviceManager::unlock_keys() const { | |
Tim Song
2016/12/08 00:26:39
I believe the convention in Chrome is to only use
Kyle Horimoto
2016/12/08 00:35:03
Done.
| |
377 std::vector<ExternalDeviceInfo> unlock_keys; | |
378 for (const auto& device : synced_devices_) { | |
379 if (device.unlock_key()) { | |
380 unlock_keys.push_back(device); | |
381 } | |
382 } | |
383 return unlock_keys; | |
384 } | |
385 | |
386 const std::vector<ExternalDeviceInfo> | |
387 CryptAuthDeviceManager::tether_hosts() const { | |
388 std::vector<ExternalDeviceInfo> tether_hosts; | |
389 for (const auto& device : synced_devices_) { | |
390 if (device.mobile_hotspot_supported()) { | |
391 tether_hosts.push_back(device); | |
392 } | |
393 } | |
394 return tether_hosts; | |
395 } | |
396 | |
370 void CryptAuthDeviceManager::OnGetMyDevicesSuccess( | 397 void CryptAuthDeviceManager::OnGetMyDevicesSuccess( |
371 const cryptauth::GetMyDevicesResponse& response) { | 398 const cryptauth::GetMyDevicesResponse& response) { |
372 // Update the unlock keys stored in the user's prefs. | 399 // Update the synced devices stored in the user's prefs. |
373 std::unique_ptr<base::ListValue> unlock_keys_pref(new base::ListValue()); | |
374 std::unique_ptr<base::ListValue> devices_as_list(new base::ListValue()); | 400 std::unique_ptr<base::ListValue> devices_as_list(new base::ListValue()); |
375 for (const auto& device : response.devices()) { | 401 for (const auto& device : response.devices()) { |
376 devices_as_list->Append(UnlockKeyToDictionary(device)); | 402 devices_as_list->Append(UnlockKeyToDictionary(device)); |
377 if (device.unlock_key()) | |
378 unlock_keys_pref->Append(UnlockKeyToDictionary(device)); | |
379 } | 403 } |
380 PA_LOG(INFO) << "Devices Synced:\n" << *devices_as_list; | 404 PA_LOG(INFO) << "Devices Synced:\n" << *devices_as_list; |
381 | 405 |
382 bool unlock_keys_changed = !unlock_keys_pref->Equals( | 406 bool unlock_keys_changed = !devices_as_list->Equals( |
383 pref_service_->GetList(prefs::kCryptAuthDeviceSyncUnlockKeys)); | 407 pref_service_->GetList(prefs::kCryptAuthDeviceSyncUnlockKeys)); |
384 { | 408 { |
385 ListPrefUpdate update(pref_service_, prefs::kCryptAuthDeviceSyncUnlockKeys); | 409 ListPrefUpdate update(pref_service_, prefs::kCryptAuthDeviceSyncUnlockKeys); |
386 update.Get()->Swap(unlock_keys_pref.get()); | 410 update.Get()->Swap(devices_as_list.get()); |
387 } | 411 } |
388 UpdateUnlockKeysFromPrefs(); | 412 UpdateUnlockKeysFromPrefs(); |
389 | 413 |
390 // Reset metadata used for scheduling syncing. | 414 // Reset metadata used for scheduling syncing. |
391 pref_service_->SetBoolean(prefs::kCryptAuthDeviceSyncIsRecoveringFromFailure, | 415 pref_service_->SetBoolean(prefs::kCryptAuthDeviceSyncIsRecoveringFromFailure, |
392 false); | 416 false); |
393 pref_service_->SetDouble(prefs::kCryptAuthDeviceSyncLastSyncTimeSeconds, | 417 pref_service_->SetDouble(prefs::kCryptAuthDeviceSyncLastSyncTimeSeconds, |
394 clock_->Now().ToDoubleT()); | 418 clock_->Now().ToDoubleT()); |
395 pref_service_->SetInteger(prefs::kCryptAuthDeviceSyncReason, | 419 pref_service_->SetInteger(prefs::kCryptAuthDeviceSyncReason, |
396 cryptauth::INVOCATION_REASON_UNKNOWN); | 420 cryptauth::INVOCATION_REASON_UNKNOWN); |
(...skipping 27 matching lines...) Expand all Loading... | |
424 kDeviceSyncMaxJitterRatio, "CryptAuth DeviceSync"); | 448 kDeviceSyncMaxJitterRatio, "CryptAuth DeviceSync"); |
425 } | 449 } |
426 | 450 |
427 void CryptAuthDeviceManager::OnResyncMessage() { | 451 void CryptAuthDeviceManager::OnResyncMessage() { |
428 ForceSyncNow(cryptauth::INVOCATION_REASON_SERVER_INITIATED); | 452 ForceSyncNow(cryptauth::INVOCATION_REASON_SERVER_INITIATED); |
429 } | 453 } |
430 | 454 |
431 void CryptAuthDeviceManager::UpdateUnlockKeysFromPrefs() { | 455 void CryptAuthDeviceManager::UpdateUnlockKeysFromPrefs() { |
432 const base::ListValue* unlock_key_list = | 456 const base::ListValue* unlock_key_list = |
433 pref_service_->GetList(prefs::kCryptAuthDeviceSyncUnlockKeys); | 457 pref_service_->GetList(prefs::kCryptAuthDeviceSyncUnlockKeys); |
434 unlock_keys_.clear(); | 458 synced_devices_.clear(); |
435 for (size_t i = 0; i < unlock_key_list->GetSize(); ++i) { | 459 for (size_t i = 0; i < unlock_key_list->GetSize(); ++i) { |
436 const base::DictionaryValue* unlock_key_dictionary; | 460 const base::DictionaryValue* unlock_key_dictionary; |
437 if (unlock_key_list->GetDictionary(i, &unlock_key_dictionary)) { | 461 if (unlock_key_list->GetDictionary(i, &unlock_key_dictionary)) { |
438 cryptauth::ExternalDeviceInfo unlock_key; | 462 cryptauth::ExternalDeviceInfo unlock_key; |
439 if (DictionaryToUnlockKey(*unlock_key_dictionary, &unlock_key)) { | 463 if (DictionaryToUnlockKey(*unlock_key_dictionary, &unlock_key)) { |
440 unlock_keys_.push_back(unlock_key); | 464 synced_devices_.push_back(unlock_key); |
441 } else { | 465 } else { |
442 PA_LOG(ERROR) << "Unable to deserialize unlock key dictionary " | 466 PA_LOG(ERROR) << "Unable to deserialize unlock key dictionary " |
443 << "(index=" << i << "):\n" << *unlock_key_dictionary; | 467 << "(index=" << i << "):\n" << *unlock_key_dictionary; |
444 } | 468 } |
445 } else { | 469 } else { |
446 PA_LOG(ERROR) << "Can not get dictionary in list of unlock keys " | 470 PA_LOG(ERROR) << "Can not get dictionary in list of unlock keys " |
447 << "(index=" << i << "):\n" << *unlock_key_list; | 471 << "(index=" << i << "):\n" << *unlock_key_list; |
448 } | 472 } |
449 } | 473 } |
450 } | 474 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 request.set_invocation_reason(invocation_reason); | 509 request.set_invocation_reason(invocation_reason); |
486 request.set_allow_stale_read(is_sync_speculative); | 510 request.set_allow_stale_read(is_sync_speculative); |
487 cryptauth_client_->GetMyDevices( | 511 cryptauth_client_->GetMyDevices( |
488 request, base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesSuccess, | 512 request, base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesSuccess, |
489 weak_ptr_factory_.GetWeakPtr()), | 513 weak_ptr_factory_.GetWeakPtr()), |
490 base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesFailure, | 514 base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesFailure, |
491 weak_ptr_factory_.GetWeakPtr())); | 515 weak_ptr_factory_.GetWeakPtr())); |
492 } | 516 } |
493 | 517 |
494 } // namespace cryptauth | 518 } // namespace cryptauth |
OLD | NEW |