summaryrefslogtreecommitdiffstats
path: root/components/proximity_auth
diff options
context:
space:
mode:
authortengs <tengs@chromium.org>2015-08-06 11:53:10 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-06 18:53:45 +0000
commit344af25bb30ca45d3b7163d3e4b15f38d8449d21 (patch)
treed691c2db4bb003decd6bc6143336416c3634d4c9 /components/proximity_auth
parente672df8c07fd7f03dff5cfc4d13dec71a9710c03 (diff)
downloadchromium_src-344af25bb30ca45d3b7163d3e4b15f38d8449d21.zip
chromium_src-344af25bb30ca45d3b7163d3e4b15f38d8449d21.tar.gz
chromium_src-344af25bb30ca45d3b7163d3e4b15f38d8449d21.tar.bz2
Set allow_stale_read flag for speculative GetMyDevices CryptAuth API calls.
BUG=512230 TEST=unit test Review URL: https://codereview.chromium.org/1255413006 Cr-Commit-Position: refs/heads/master@{#342159}
Diffstat (limited to 'components/proximity_auth')
-rw-r--r--components/proximity_auth/cryptauth/cryptauth_device_manager.cc7
-rw-r--r--components/proximity_auth/cryptauth/cryptauth_device_manager_unittest.cc44
2 files changed, 51 insertions, 0 deletions
diff --git a/components/proximity_auth/cryptauth/cryptauth_device_manager.cc b/components/proximity_auth/cryptauth/cryptauth_device_manager.cc
index a7e11ac..bbb6c17 100644
--- a/components/proximity_auth/cryptauth/cryptauth_device_manager.cc
+++ b/components/proximity_auth/cryptauth/cryptauth_device_manager.cc
@@ -261,6 +261,12 @@ void CryptAuthDeviceManager::OnSyncRequested(
int reason_stored_in_prefs =
pref_service_->GetInteger(prefs::kCryptAuthDeviceSyncReason);
+ // If the sync attempt is not forced, it is acceptable for CryptAuth to return
+ // a cached copy of the user's devices, rather taking a database hit for the
+ // freshest data.
+ bool is_sync_speculative =
+ reason_stored_in_prefs != cryptauth::INVOCATION_REASON_UNKNOWN;
+
if (cryptauth::InvocationReason_IsValid(reason_stored_in_prefs) &&
reason_stored_in_prefs != cryptauth::INVOCATION_REASON_UNKNOWN) {
invocation_reason =
@@ -275,6 +281,7 @@ void CryptAuthDeviceManager::OnSyncRequested(
cryptauth::GetMyDevicesRequest request;
request.set_invocation_reason(invocation_reason);
+ request.set_allow_stale_read(is_sync_speculative);
cryptauth_client_->GetMyDevices(
request, base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesSuccess,
weak_ptr_factory_.GetWeakPtr()),
diff --git a/components/proximity_auth/cryptauth/cryptauth_device_manager_unittest.cc b/components/proximity_auth/cryptauth/cryptauth_device_manager_unittest.cc
index 091d190..907e811 100644
--- a/components/proximity_auth/cryptauth/cryptauth_device_manager_unittest.cc
+++ b/components/proximity_auth/cryptauth/cryptauth_device_manager_unittest.cc
@@ -244,6 +244,12 @@ class ProximityAuthCryptAuthDeviceManagerTest
EXPECT_EQ(expected_invocation_reason,
get_my_devices_request_.invocation_reason());
+
+ // The allow_stale_read flag is set if the sync was not forced.
+ bool allow_stale_read =
+ pref_service_.GetInteger(prefs::kCryptAuthDeviceSyncReason) !=
+ cryptauth::INVOCATION_REASON_UNKNOWN;
+ EXPECT_EQ(allow_stale_read, get_my_devices_request_.allow_stale_read());
}
// MockCryptAuthClientFactory::Observer:
@@ -444,6 +450,44 @@ TEST_F(ProximityAuthCryptAuthDeviceManagerTest, ForceSyncFailsThenSucceeds) {
prefs::kCryptAuthDeviceSyncIsRecoveringFromFailure));
}
+TEST_F(ProximityAuthCryptAuthDeviceManagerTest, PeriodicSyncFailsThenSucceeds) {
+ device_manager_.Start();
+ base::Time old_sync_time = device_manager_.GetLastSyncTime();
+
+ // The first periodic sync fails.
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_PERIODIC);
+ clock_->SetNow(base::Time::FromDoubleT(kLaterTimeNowSeconds));
+ EXPECT_CALL(*this,
+ OnSyncFinishedProxy(
+ CryptAuthDeviceManager::SyncResult::FAILURE,
+ CryptAuthDeviceManager::DeviceChangeResult::UNCHANGED));
+ error_callback_.Run("401");
+ EXPECT_EQ(old_sync_time, device_manager_.GetLastSyncTime());
+ EXPECT_TRUE(pref_service_.GetBoolean(
+ prefs::kCryptAuthDeviceSyncIsRecoveringFromFailure));
+
+ // The second recovery sync succeeds.
+ ON_CALL(*sync_scheduler(), GetStrategy())
+ .WillByDefault(Return(SyncScheduler::Strategy::AGGRESSIVE_RECOVERY));
+ FireSchedulerForSync(cryptauth::INVOCATION_REASON_FAILURE_RECOVERY);
+ clock_->SetNow(base::Time::FromDoubleT(kLaterTimeNowSeconds + 30));
+ EXPECT_CALL(*this, OnSyncFinishedProxy(
+ CryptAuthDeviceManager::SyncResult::SUCCESS,
+ CryptAuthDeviceManager::DeviceChangeResult::CHANGED));
+ success_callback_.Run(get_my_devices_response_);
+ EXPECT_EQ(clock_->Now(), device_manager_.GetLastSyncTime());
+
+ ExpectUnlockKeysAndPrefAreEqual(std::vector<cryptauth::ExternalDeviceInfo>(
+ 1, get_my_devices_response_.devices(0)),
+ device_manager_.unlock_keys(), pref_service_);
+
+ EXPECT_FLOAT_EQ(
+ clock_->Now().ToDoubleT(),
+ pref_service_.GetDouble(prefs::kCryptAuthDeviceSyncLastSyncTimeSeconds));
+ EXPECT_FALSE(pref_service_.GetBoolean(
+ prefs::kCryptAuthDeviceSyncIsRecoveringFromFailure));
+}
+
TEST_F(ProximityAuthCryptAuthDeviceManagerTest, SyncSameDevice) {
// Set the same unlock key in the user prefs as the one that would be synced.
{