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

Side by Side Diff: chrome/browser/cryptauth/chrome_cryptauth_service.cc

Issue 2911583003: ChromeCryptAuthService: only perform device sync once enrollment is complete. (Closed)
Patch Set: khorimoto@ comments. Created 3 years, 6 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
« no previous file with comments | « chrome/browser/cryptauth/chrome_cryptauth_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "chrome/browser/cryptauth/chrome_cryptauth_service.h" 5 #include "chrome/browser/cryptauth/chrome_cryptauth_service.h"
6 6
7 #include "base/guid.h" 7 #include "base/guid.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/sys_info.h" 9 #include "base/sys_info.h"
10 #include "base/time/default_clock.h" 10 #include "base/time/default_clock.h"
11 #include "base/version.h" 11 #include "base/version.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chrome_content_browser_client.h" 13 #include "chrome/browser/chrome_content_browser_client.h"
14 #include "chrome/browser/gcm/gcm_profile_service_factory.h" 14 #include "chrome/browser/gcm/gcm_profile_service_factory.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
17 #include "chrome/browser/signin/signin_manager_factory.h" 17 #include "chrome/browser/signin/signin_manager_factory.h"
18 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "components/cryptauth/cryptauth_client.h" 19 #include "components/cryptauth/cryptauth_client.h"
20 #include "components/cryptauth/cryptauth_client_impl.h" 20 #include "components/cryptauth/cryptauth_client_impl.h"
21 #include "components/cryptauth/cryptauth_device_manager.h" 21 #include "components/cryptauth/cryptauth_device_manager.h"
22 #include "components/cryptauth/cryptauth_enroller.h" 22 #include "components/cryptauth/cryptauth_enroller.h"
23 #include "components/cryptauth/cryptauth_enroller_impl.h" 23 #include "components/cryptauth/cryptauth_enroller_impl.h"
24 #include "components/cryptauth/cryptauth_enrollment_manager.h"
25 #include "components/cryptauth/cryptauth_enrollment_utils.h" 24 #include "components/cryptauth/cryptauth_enrollment_utils.h"
26 #include "components/cryptauth/cryptauth_gcm_manager_impl.h" 25 #include "components/cryptauth/cryptauth_gcm_manager_impl.h"
27 #include "components/cryptauth/proto/cryptauth_api.pb.h" 26 #include "components/cryptauth/proto/cryptauth_api.pb.h"
28 #include "components/cryptauth/secure_message_delegate.h" 27 #include "components/cryptauth/secure_message_delegate.h"
29 #include "components/gcm_driver/gcm_profile_service.h" 28 #include "components/gcm_driver/gcm_profile_service.h"
30 #include "components/prefs/pref_service.h" 29 #include "components/prefs/pref_service.h"
31 #include "components/proximity_auth/logging/logging.h" 30 #include "components/proximity_auth/logging/logging.h"
32 #include "components/signin/core/browser/profile_oauth2_token_service.h" 31 #include "components/signin/core/browser/profile_oauth2_token_service.h"
33 #include "components/signin/core/browser/signin_manager.h" 32 #include "components/signin/core/browser/signin_manager.h"
34 #include "components/translate/core/browser/translate_download_manager.h" 33 #include "components/translate/core/browser/translate_download_manager.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 device_manager_(std::move(device_manager)), 218 device_manager_(std::move(device_manager)),
220 profile_(profile), 219 profile_(profile),
221 token_service_(token_service) { 220 token_service_(token_service) {
222 gcm_manager_->StartListening(); 221 gcm_manager_->StartListening();
223 222
224 if (!token_service_->RefreshTokenIsAvailable(GetAccountId())) { 223 if (!token_service_->RefreshTokenIsAvailable(GetAccountId())) {
225 PA_LOG(INFO) << "Refresh token not yet available; " 224 PA_LOG(INFO) << "Refresh token not yet available; "
226 << "waiting before starting CryptAuth managers."; 225 << "waiting before starting CryptAuth managers.";
227 token_service_->AddObserver(this); 226 token_service_->AddObserver(this);
228 } else { 227 } else {
229 enrollment_manager_->Start(); 228 PerformEnrollmentAndDeviceSync();
230 device_manager_->Start();
231 } 229 }
232 } 230 }
233 231
234 ChromeCryptAuthService::~ChromeCryptAuthService() {} 232 ChromeCryptAuthService::~ChromeCryptAuthService() {}
235 233
236 void ChromeCryptAuthService::Shutdown() { 234 void ChromeCryptAuthService::Shutdown() {
237 token_service_->RemoveObserver(this); 235 token_service_->RemoveObserver(this);
238 enrollment_manager_.reset(); 236 enrollment_manager_.reset();
239 device_manager_.reset(); 237 device_manager_.reset();
240 gcm_manager_.reset(); 238 gcm_manager_.reset();
(...skipping 20 matching lines...) Expand all
261 std::unique_ptr<cryptauth::SecureMessageDelegate> 259 std::unique_ptr<cryptauth::SecureMessageDelegate>
262 ChromeCryptAuthService::CreateSecureMessageDelegate() { 260 ChromeCryptAuthService::CreateSecureMessageDelegate() {
263 return CreateSecureMessageDelegateImpl(); 261 return CreateSecureMessageDelegateImpl();
264 } 262 }
265 263
266 std::unique_ptr<cryptauth::CryptAuthClientFactory> 264 std::unique_ptr<cryptauth::CryptAuthClientFactory>
267 ChromeCryptAuthService::CreateCryptAuthClientFactory() { 265 ChromeCryptAuthService::CreateCryptAuthClientFactory() {
268 return CreateCryptAuthClientFactoryImpl(profile_); 266 return CreateCryptAuthClientFactoryImpl(profile_);
269 } 267 }
270 268
269 void ChromeCryptAuthService::OnEnrollmentStarted() {}
270
271 void ChromeCryptAuthService::OnEnrollmentFinished(bool success) {
272 if (success)
273 device_manager_->Start();
274 else
275 PA_LOG(ERROR) << "CryptAuth enrollment failed. Device manager was not "
276 << " started.";
277
278 enrollment_manager_->RemoveObserver(this);
279 }
280
271 void ChromeCryptAuthService::OnRefreshTokenAvailable( 281 void ChromeCryptAuthService::OnRefreshTokenAvailable(
272 const std::string& account_id) { 282 const std::string& account_id) {
273 if (account_id == GetAccountId()) { 283 if (account_id == GetAccountId()) {
274 token_service_->RemoveObserver(this); 284 token_service_->RemoveObserver(this);
275 enrollment_manager_->Start(); 285 PerformEnrollmentAndDeviceSync();
276 device_manager_->Start();
277 } 286 }
278 } 287 }
288
289 void ChromeCryptAuthService::PerformEnrollmentAndDeviceSync() {
290 if (enrollment_manager_->IsEnrollmentValid()) {
291 device_manager_->Start();
292 } else {
293 // If enrollment is not valid, wait for the new enrollment attempt to finish
294 // before starting CryptAuthDeviceManager. See OnEnrollmentFinished(),
295 enrollment_manager_->AddObserver(this);
296 }
297
298 // Even if enrollment was valid, CryptAuthEnrollmentManager must be started in
299 // order to schedule the next enrollment attempt.
300 enrollment_manager_->Start();
301 }
OLDNEW
« no previous file with comments | « chrome/browser/cryptauth/chrome_cryptauth_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698