Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: components/cryptauth/cryptauth_device_manager.cc

Issue 2561683002: Update CryptAuthDeviceManager to store all synced devices instead of only unlock keys. (Closed)
Patch Set: tengs@ comments. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 std::vector<ExternalDeviceInfo>
371 CryptAuthDeviceManager::GetSyncedDevices() const {
372 return synced_devices_;
373 }
374
375 std::vector<ExternalDeviceInfo> CryptAuthDeviceManager::GetUnlockKeys() const {
376 std::vector<ExternalDeviceInfo> unlock_keys;
377 for (const auto& device : synced_devices_) {
378 if (device.unlock_key()) {
379 unlock_keys.push_back(device);
380 }
381 }
382 return unlock_keys;
383 }
384
385 std::vector<ExternalDeviceInfo> CryptAuthDeviceManager::GetTetherHosts() const {
386 std::vector<ExternalDeviceInfo> tether_hosts;
387 for (const auto& device : synced_devices_) {
388 if (device.mobile_hotspot_supported()) {
389 tether_hosts.push_back(device);
390 }
391 }
392 return tether_hosts;
393 }
394
370 void CryptAuthDeviceManager::OnGetMyDevicesSuccess( 395 void CryptAuthDeviceManager::OnGetMyDevicesSuccess(
371 const cryptauth::GetMyDevicesResponse& response) { 396 const cryptauth::GetMyDevicesResponse& response) {
372 // Update the unlock keys stored in the user's prefs. 397 // 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()); 398 std::unique_ptr<base::ListValue> devices_as_list(new base::ListValue());
375 for (const auto& device : response.devices()) { 399 for (const auto& device : response.devices()) {
376 devices_as_list->Append(UnlockKeyToDictionary(device)); 400 devices_as_list->Append(UnlockKeyToDictionary(device));
377 if (device.unlock_key())
378 unlock_keys_pref->Append(UnlockKeyToDictionary(device));
379 } 401 }
380 PA_LOG(INFO) << "Devices Synced:\n" << *devices_as_list; 402 PA_LOG(INFO) << "Devices Synced:\n" << *devices_as_list;
381 403
382 bool unlock_keys_changed = !unlock_keys_pref->Equals( 404 bool unlock_keys_changed = !devices_as_list->Equals(
383 pref_service_->GetList(prefs::kCryptAuthDeviceSyncUnlockKeys)); 405 pref_service_->GetList(prefs::kCryptAuthDeviceSyncUnlockKeys));
384 { 406 {
385 ListPrefUpdate update(pref_service_, prefs::kCryptAuthDeviceSyncUnlockKeys); 407 ListPrefUpdate update(pref_service_, prefs::kCryptAuthDeviceSyncUnlockKeys);
386 update.Get()->Swap(unlock_keys_pref.get()); 408 update.Get()->Swap(devices_as_list.get());
387 } 409 }
388 UpdateUnlockKeysFromPrefs(); 410 UpdateUnlockKeysFromPrefs();
389 411
390 // Reset metadata used for scheduling syncing. 412 // Reset metadata used for scheduling syncing.
391 pref_service_->SetBoolean(prefs::kCryptAuthDeviceSyncIsRecoveringFromFailure, 413 pref_service_->SetBoolean(prefs::kCryptAuthDeviceSyncIsRecoveringFromFailure,
392 false); 414 false);
393 pref_service_->SetDouble(prefs::kCryptAuthDeviceSyncLastSyncTimeSeconds, 415 pref_service_->SetDouble(prefs::kCryptAuthDeviceSyncLastSyncTimeSeconds,
394 clock_->Now().ToDoubleT()); 416 clock_->Now().ToDoubleT());
395 pref_service_->SetInteger(prefs::kCryptAuthDeviceSyncReason, 417 pref_service_->SetInteger(prefs::kCryptAuthDeviceSyncReason,
396 cryptauth::INVOCATION_REASON_UNKNOWN); 418 cryptauth::INVOCATION_REASON_UNKNOWN);
(...skipping 27 matching lines...) Expand all
424 kDeviceSyncMaxJitterRatio, "CryptAuth DeviceSync"); 446 kDeviceSyncMaxJitterRatio, "CryptAuth DeviceSync");
425 } 447 }
426 448
427 void CryptAuthDeviceManager::OnResyncMessage() { 449 void CryptAuthDeviceManager::OnResyncMessage() {
428 ForceSyncNow(cryptauth::INVOCATION_REASON_SERVER_INITIATED); 450 ForceSyncNow(cryptauth::INVOCATION_REASON_SERVER_INITIATED);
429 } 451 }
430 452
431 void CryptAuthDeviceManager::UpdateUnlockKeysFromPrefs() { 453 void CryptAuthDeviceManager::UpdateUnlockKeysFromPrefs() {
432 const base::ListValue* unlock_key_list = 454 const base::ListValue* unlock_key_list =
433 pref_service_->GetList(prefs::kCryptAuthDeviceSyncUnlockKeys); 455 pref_service_->GetList(prefs::kCryptAuthDeviceSyncUnlockKeys);
434 unlock_keys_.clear(); 456 synced_devices_.clear();
435 for (size_t i = 0; i < unlock_key_list->GetSize(); ++i) { 457 for (size_t i = 0; i < unlock_key_list->GetSize(); ++i) {
436 const base::DictionaryValue* unlock_key_dictionary; 458 const base::DictionaryValue* unlock_key_dictionary;
437 if (unlock_key_list->GetDictionary(i, &unlock_key_dictionary)) { 459 if (unlock_key_list->GetDictionary(i, &unlock_key_dictionary)) {
438 cryptauth::ExternalDeviceInfo unlock_key; 460 cryptauth::ExternalDeviceInfo unlock_key;
439 if (DictionaryToUnlockKey(*unlock_key_dictionary, &unlock_key)) { 461 if (DictionaryToUnlockKey(*unlock_key_dictionary, &unlock_key)) {
440 unlock_keys_.push_back(unlock_key); 462 synced_devices_.push_back(unlock_key);
441 } else { 463 } else {
442 PA_LOG(ERROR) << "Unable to deserialize unlock key dictionary " 464 PA_LOG(ERROR) << "Unable to deserialize unlock key dictionary "
443 << "(index=" << i << "):\n" << *unlock_key_dictionary; 465 << "(index=" << i << "):\n" << *unlock_key_dictionary;
444 } 466 }
445 } else { 467 } else {
446 PA_LOG(ERROR) << "Can not get dictionary in list of unlock keys " 468 PA_LOG(ERROR) << "Can not get dictionary in list of unlock keys "
447 << "(index=" << i << "):\n" << *unlock_key_list; 469 << "(index=" << i << "):\n" << *unlock_key_list;
448 } 470 }
449 } 471 }
450 } 472 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 request.set_invocation_reason(invocation_reason); 507 request.set_invocation_reason(invocation_reason);
486 request.set_allow_stale_read(is_sync_speculative); 508 request.set_allow_stale_read(is_sync_speculative);
487 cryptauth_client_->GetMyDevices( 509 cryptauth_client_->GetMyDevices(
488 request, base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesSuccess, 510 request, base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesSuccess,
489 weak_ptr_factory_.GetWeakPtr()), 511 weak_ptr_factory_.GetWeakPtr()),
490 base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesFailure, 512 base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesFailure,
491 weak_ptr_factory_.GetWeakPtr())); 513 weak_ptr_factory_.GetWeakPtr()));
492 } 514 }
493 515
494 } // namespace cryptauth 516 } // namespace cryptauth
OLDNEW
« no previous file with comments | « components/cryptauth/cryptauth_device_manager.h ('k') | components/cryptauth/cryptauth_device_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698