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

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

Issue 2423353002: Reduce usage of FOR_EACH_OBSERVER macro in components/ (Closed)
Patch Set: Created 4 years, 2 months 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/proximity_auth/cryptauth/cryptauth_device_manager.h" 5 #include "components/proximity_auth/cryptauth/cryptauth_device_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 pref_service_->SetBoolean(prefs::kCryptAuthDeviceSyncIsRecoveringFromFailure, 208 pref_service_->SetBoolean(prefs::kCryptAuthDeviceSyncIsRecoveringFromFailure,
209 false); 209 false);
210 pref_service_->SetDouble(prefs::kCryptAuthDeviceSyncLastSyncTimeSeconds, 210 pref_service_->SetDouble(prefs::kCryptAuthDeviceSyncLastSyncTimeSeconds,
211 clock_->Now().ToDoubleT()); 211 clock_->Now().ToDoubleT());
212 pref_service_->SetInteger(prefs::kCryptAuthDeviceSyncReason, 212 pref_service_->SetInteger(prefs::kCryptAuthDeviceSyncReason,
213 cryptauth::INVOCATION_REASON_UNKNOWN); 213 cryptauth::INVOCATION_REASON_UNKNOWN);
214 214
215 sync_request_->OnDidComplete(true); 215 sync_request_->OnDidComplete(true);
216 cryptauth_client_.reset(); 216 cryptauth_client_.reset();
217 sync_request_.reset(); 217 sync_request_.reset();
218 FOR_EACH_OBSERVER( 218 for (auto& observer : observers_) {
219 Observer, observers_, 219 observer.OnSyncFinished(SyncResult::SUCCESS,
220 OnSyncFinished(SyncResult::SUCCESS, unlock_keys_changed 220 unlock_keys_changed
221 ? DeviceChangeResult::CHANGED 221 ? DeviceChangeResult::CHANGED
222 : DeviceChangeResult::UNCHANGED)); 222 : DeviceChangeResult::UNCHANGED);
223 }
223 } 224 }
224 225
225 void CryptAuthDeviceManager::OnGetMyDevicesFailure(const std::string& error) { 226 void CryptAuthDeviceManager::OnGetMyDevicesFailure(const std::string& error) {
226 PA_LOG(ERROR) << "GetMyDevices API failed: " << error; 227 PA_LOG(ERROR) << "GetMyDevices API failed: " << error;
227 pref_service_->SetBoolean(prefs::kCryptAuthDeviceSyncIsRecoveringFromFailure, 228 pref_service_->SetBoolean(prefs::kCryptAuthDeviceSyncIsRecoveringFromFailure,
228 true); 229 true);
229 sync_request_->OnDidComplete(false); 230 sync_request_->OnDidComplete(false);
230 cryptauth_client_.reset(); 231 cryptauth_client_.reset();
231 sync_request_.reset(); 232 sync_request_.reset();
232 FOR_EACH_OBSERVER( 233 for (auto& observer : observers_)
233 Observer, observers_, 234 observer.OnSyncFinished(SyncResult::FAILURE, DeviceChangeResult::UNCHANGED);
234 OnSyncFinished(SyncResult::FAILURE, DeviceChangeResult::UNCHANGED));
235 } 235 }
236 236
237 std::unique_ptr<SyncScheduler> CryptAuthDeviceManager::CreateSyncScheduler() { 237 std::unique_ptr<SyncScheduler> CryptAuthDeviceManager::CreateSyncScheduler() {
238 return base::MakeUnique<SyncSchedulerImpl>( 238 return base::MakeUnique<SyncSchedulerImpl>(
239 this, base::TimeDelta::FromHours(kRefreshPeriodHours), 239 this, base::TimeDelta::FromHours(kRefreshPeriodHours),
240 base::TimeDelta::FromMinutes(kDeviceSyncBaseRecoveryPeriodMinutes), 240 base::TimeDelta::FromMinutes(kDeviceSyncBaseRecoveryPeriodMinutes),
241 kDeviceSyncMaxJitterRatio, "CryptAuth DeviceSync"); 241 kDeviceSyncMaxJitterRatio, "CryptAuth DeviceSync");
242 } 242 }
243 243
244 void CryptAuthDeviceManager::OnResyncMessage() { 244 void CryptAuthDeviceManager::OnResyncMessage() {
(...skipping 16 matching lines...) Expand all
261 } 261 }
262 } else { 262 } else {
263 PA_LOG(ERROR) << "Can not get dictionary in list of unlock keys " 263 PA_LOG(ERROR) << "Can not get dictionary in list of unlock keys "
264 << "(index=" << i << "):\n" << *unlock_key_list; 264 << "(index=" << i << "):\n" << *unlock_key_list;
265 } 265 }
266 } 266 }
267 } 267 }
268 268
269 void CryptAuthDeviceManager::OnSyncRequested( 269 void CryptAuthDeviceManager::OnSyncRequested(
270 std::unique_ptr<SyncScheduler::SyncRequest> sync_request) { 270 std::unique_ptr<SyncScheduler::SyncRequest> sync_request) {
271 FOR_EACH_OBSERVER(Observer, observers_, OnSyncStarted()); 271 for (auto& observer : observers_)
272 observer.OnSyncStarted();
272 273
273 sync_request_ = std::move(sync_request); 274 sync_request_ = std::move(sync_request);
274 cryptauth_client_ = client_factory_->CreateInstance(); 275 cryptauth_client_ = client_factory_->CreateInstance();
275 276
276 cryptauth::InvocationReason invocation_reason = 277 cryptauth::InvocationReason invocation_reason =
277 cryptauth::INVOCATION_REASON_UNKNOWN; 278 cryptauth::INVOCATION_REASON_UNKNOWN;
278 279
279 int reason_stored_in_prefs = 280 int reason_stored_in_prefs =
280 pref_service_->GetInteger(prefs::kCryptAuthDeviceSyncReason); 281 pref_service_->GetInteger(prefs::kCryptAuthDeviceSyncReason);
281 282
(...skipping 19 matching lines...) Expand all
301 request.set_invocation_reason(invocation_reason); 302 request.set_invocation_reason(invocation_reason);
302 request.set_allow_stale_read(is_sync_speculative); 303 request.set_allow_stale_read(is_sync_speculative);
303 cryptauth_client_->GetMyDevices( 304 cryptauth_client_->GetMyDevices(
304 request, base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesSuccess, 305 request, base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesSuccess,
305 weak_ptr_factory_.GetWeakPtr()), 306 weak_ptr_factory_.GetWeakPtr()),
306 base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesFailure, 307 base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesFailure,
307 weak_ptr_factory_.GetWeakPtr())); 308 weak_ptr_factory_.GetWeakPtr()));
308 } 309 }
309 310
310 } // namespace proximity_auth 311 } // namespace proximity_auth
OLDNEW
« no previous file with comments | « components/proximity_auth/connection.cc ('k') | components/proximity_auth/cryptauth/cryptauth_enrollment_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698