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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 9956097: suppress user/password dialog when re-enabling sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/sync/profile_sync_service.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 15 matching lines...) Expand all
26 #include "chrome/browser/defaults.h" 26 #include "chrome/browser/defaults.h"
27 #include "chrome/browser/net/chrome_cookie_notification_details.h" 27 #include "chrome/browser/net/chrome_cookie_notification_details.h"
28 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/signin/signin_manager.h" 29 #include "chrome/browser/signin/signin_manager.h"
30 #include "chrome/browser/signin/signin_manager_factory.h" 30 #include "chrome/browser/signin/signin_manager_factory.h"
31 #include "chrome/browser/signin/token_service.h" 31 #include "chrome/browser/signin/token_service.h"
32 #include "chrome/browser/signin/token_service_factory.h" 32 #include "chrome/browser/signin/token_service_factory.h"
33 #include "chrome/browser/sync/api/sync_error.h" 33 #include "chrome/browser/sync/api/sync_error.h"
34 #include "chrome/browser/sync/backend_migrator.h" 34 #include "chrome/browser/sync/backend_migrator.h"
35 #include "chrome/browser/sync/glue/change_processor.h" 35 #include "chrome/browser/sync/glue/change_processor.h"
36 #include "chrome/browser/sync/glue/chrome_encryptor.h"
36 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" 37 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"
37 #include "chrome/browser/sync/glue/data_type_controller.h" 38 #include "chrome/browser/sync/glue/data_type_controller.h"
38 #include "chrome/browser/sync/glue/session_data_type_controller.h" 39 #include "chrome/browser/sync/glue/session_data_type_controller.h"
39 #include "chrome/browser/sync/glue/session_model_associator.h" 40 #include "chrome/browser/sync/glue/session_model_associator.h"
40 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" 41 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h"
41 #include "chrome/browser/sync/internal_api/configure_reason.h" 42 #include "chrome/browser/sync/internal_api/configure_reason.h"
42 #include "chrome/browser/sync/internal_api/sync_manager.h" 43 #include "chrome/browser/sync/internal_api/sync_manager.h"
43 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" 44 #include "chrome/browser/sync/profile_sync_components_factory_impl.h"
44 #include "chrome/browser/sync/sync_global_error.h" 45 #include "chrome/browser/sync/sync_global_error.h"
45 #include "chrome/browser/sync/user_selectable_sync_type.h" 46 #include "chrome/browser/sync/user_selectable_sync_type.h"
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 // Don't start up multiple times. 391 // Don't start up multiple times.
391 if (backend_.get()) { 392 if (backend_.get()) {
392 DVLOG(1) << "Skipping bringing up backend host."; 393 DVLOG(1) << "Skipping bringing up backend host.";
393 return; 394 return;
394 } 395 }
395 396
396 DCHECK(AreCredentialsAvailable()); 397 DCHECK(AreCredentialsAvailable());
397 398
398 last_synced_time_ = sync_prefs_.GetLastSyncedTime(); 399 last_synced_time_ = sync_prefs_.GetLastSyncedTime();
399 400
401 #if defined(OS_CHROMEOS)
402 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken();
403 if (bootstrap_token.empty()) {
404 sync_prefs_.SetEncryptionBootstrapToken(
405 sync_prefs_.GetSpareBootstrapToken());
406 }
407 #endif
400 CreateBackend(); 408 CreateBackend();
401 409
402 // Initialize the backend. Every time we start up a new SyncBackendHost, 410 // Initialize the backend. Every time we start up a new SyncBackendHost,
403 // we'll want to start from a fresh SyncDB, so delete any old one that might 411 // we'll want to start from a fresh SyncDB, so delete any old one that might
404 // be there. 412 // be there.
405 InitializeBackend(!HasSyncSetupCompleted()); 413 InitializeBackend(!HasSyncSetupCompleted());
406 414
407 if (!sync_global_error_.get()) { 415 if (!sync_global_error_.get()) {
408 sync_global_error_.reset(new SyncGlobalError(this)); 416 sync_global_error_.reset(new SyncGlobalError(this));
409 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( 417 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 // PSS clients don't think we're set up while we're shutting down. 504 // PSS clients don't think we're set up while we're shutting down.
497 sync_prefs_.ClearPreferences(); 505 sync_prefs_.ClearPreferences();
498 ClearUnrecoverableError(); 506 ClearUnrecoverableError();
499 ShutdownImpl(true); 507 ShutdownImpl(true);
500 508
501 // TODO(atwilson): Don't call SignOut() on *any* platform - move this into 509 // TODO(atwilson): Don't call SignOut() on *any* platform - move this into
502 // the UI layer if needed (sync activity should never result in the user 510 // the UI layer if needed (sync activity should never result in the user
503 // being logged out of all chrome services). 511 // being logged out of all chrome services).
504 if (!auto_start_enabled_) 512 if (!auto_start_enabled_)
505 signin_->SignOut(); 513 signin_->SignOut();
514 else
515 sync_prefs_.SetStartSuppressed(true);
506 516
507 NotifyObservers(); 517 NotifyObservers();
508 } 518 }
509 519
510 bool ProfileSyncService::HasSyncSetupCompleted() const { 520 bool ProfileSyncService::HasSyncSetupCompleted() const {
511 return sync_prefs_.HasSyncSetupCompleted(); 521 return sync_prefs_.HasSyncSetupCompleted();
512 } 522 }
513 523
514 void ProfileSyncService::SetSyncSetupCompleted() { 524 void ProfileSyncService::SetSyncSetupCompleted() {
515 sync_prefs_.SetSyncSetupCompleted(); 525 sync_prefs_.SetSyncSetupCompleted();
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 // Selected type has changed - log it. 1074 // Selected type has changed - log it.
1065 UMA_HISTOGRAM_ENUMERATION( 1075 UMA_HISTOGRAM_ENUMERATION(
1066 "Sync.CustomSync", 1076 "Sync.CustomSync",
1067 user_selectable_types[i], 1077 user_selectable_types[i],
1068 browser_sync::user_selectable_type::SELECTABLE_DATATYPE_COUNT + 1); 1078 browser_sync::user_selectable_type::SELECTABLE_DATATYPE_COUNT + 1);
1069 } 1079 }
1070 } 1080 }
1071 } 1081 }
1072 } 1082 }
1073 1083
1084 #if defined(OS_CHROMEOS)
1085 void ProfileSyncService::RefreshSpareBootstrapToken(
1086 const std::string& passphrase) {
1087 browser_sync::ChromeEncryptor encryptor;
1088 browser_sync::Cryptographer temp_cryptographer(&encryptor);
1089 // The first 2 params (hostname and username) doesn't have any effect here.
1090 browser_sync::KeyParams key_params = {"localhost", "dummy", passphrase};
1091
1092 std::string bootstrap_token;
1093 if (!temp_cryptographer.AddKey(key_params)) {
1094 NOTREACHED() << "Failed to add key to cryptographer.";
1095 }
1096 temp_cryptographer.GetBootstrapToken(&bootstrap_token);
1097 sync_prefs_.SetSpareBootstrapToken(bootstrap_token);
1098 }
1099 #endif
1100
1074 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything, 1101 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything,
1075 syncable::ModelTypeSet chosen_types) { 1102 syncable::ModelTypeSet chosen_types) {
1076 if (!backend_.get() && 1103 if (!backend_.get() &&
1077 unrecoverable_error_detected_ == false) { 1104 unrecoverable_error_detected_ == false) {
1078 NOTREACHED(); 1105 NOTREACHED();
1079 return; 1106 return;
1080 } 1107 }
1081 1108
1082 UpdateSelectedTypesHistogram(sync_everything, chosen_types); 1109 UpdateSelectedTypesHistogram(sync_everything, chosen_types);
1083 sync_prefs_.SetKeepEverythingSynced(sync_everything); 1110 sync_prefs_.SetKeepEverythingSynced(sync_everything);
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 content::Details<const GoogleServiceSigninSuccessDetails>( 1458 content::Details<const GoogleServiceSigninSuccessDetails>(
1432 details).ptr(); 1459 details).ptr();
1433 DCHECK(!successful->password.empty()); 1460 DCHECK(!successful->password.empty());
1434 if (!sync_prefs_.IsStartSuppressed()) { 1461 if (!sync_prefs_.IsStartSuppressed()) {
1435 cached_passphrase_ = successful->password; 1462 cached_passphrase_ = successful->password;
1436 // Try to consume the passphrase we just cached. If the sync backend 1463 // Try to consume the passphrase we just cached. If the sync backend
1437 // is not running yet, the passphrase will remain cached until the 1464 // is not running yet, the passphrase will remain cached until the
1438 // backend starts up. 1465 // backend starts up.
1439 ConsumeCachedPassphraseIfPossible(); 1466 ConsumeCachedPassphraseIfPossible();
1440 } 1467 }
1468 #if defined(OS_CHROMEOS)
1469 RefreshSpareBootstrapToken(successful->password);
1470 #endif
1441 if (!sync_initialized() || 1471 if (!sync_initialized() ||
1442 GetAuthError().state() != GoogleServiceAuthError::NONE) { 1472 GetAuthError().state() != GoogleServiceAuthError::NONE) {
1443 // Track the fact that we're still waiting for auth to complete. 1473 // Track the fact that we're still waiting for auth to complete.
1444 is_auth_in_progress_ = true; 1474 is_auth_in_progress_ = true;
1445 } 1475 }
1446 break; 1476 break;
1447 } 1477 }
1448 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { 1478 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: {
1449 const TokenService::TokenRequestFailedDetails& token_details = 1479 const TokenService::TokenRequestFailedDetails& token_details =
1450 *(content::Details<const TokenService::TokenRequestFailedDetails>( 1480 *(content::Details<const TokenService::TokenRequestFailedDetails>(
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. 1625 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru.
1596 ProfileSyncService* old_this = this; 1626 ProfileSyncService* old_this = this;
1597 this->~ProfileSyncService(); 1627 this->~ProfileSyncService();
1598 new(old_this) ProfileSyncService( 1628 new(old_this) ProfileSyncService(
1599 new ProfileSyncComponentsFactoryImpl(profile, 1629 new ProfileSyncComponentsFactoryImpl(profile,
1600 CommandLine::ForCurrentProcess()), 1630 CommandLine::ForCurrentProcess()),
1601 profile, 1631 profile,
1602 signin, 1632 signin,
1603 behavior); 1633 behavior);
1604 } 1634 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698