| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 // Selected type has changed - log it. | 1072 // Selected type has changed - log it. |
| 1065 UMA_HISTOGRAM_ENUMERATION( | 1073 UMA_HISTOGRAM_ENUMERATION( |
| 1066 "Sync.CustomSync", | 1074 "Sync.CustomSync", |
| 1067 user_selectable_types[i], | 1075 user_selectable_types[i], |
| 1068 browser_sync::user_selectable_type::SELECTABLE_DATATYPE_COUNT + 1); | 1076 browser_sync::user_selectable_type::SELECTABLE_DATATYPE_COUNT + 1); |
| 1069 } | 1077 } |
| 1070 } | 1078 } |
| 1071 } | 1079 } |
| 1072 } | 1080 } |
| 1073 | 1081 |
| 1082 #if defined(OS_CHROMEOS) |
| 1083 void ProfileSyncService::RefreshSpareBootstrapToken( |
| 1084 const std::string& passphrase) { |
| 1085 browser_sync::ChromeEncryptor encryptor; |
| 1086 browser_sync::Cryptographer temp_cryptographer(&encryptor); |
| 1087 // The first 2 params (hostname and username) doesn't have any effect here. |
| 1088 browser_sync::KeyParams key_params = {"localhost", "dummy", passphrase}; |
| 1089 |
| 1090 std::string bootstrap_token; |
| 1091 if (!temp_cryptographer.AddKey(key_params)) { |
| 1092 NOTREACHED() << "Failed to add key to cryptographer."; |
| 1093 } |
| 1094 temp_cryptographer.GetBootstrapToken(&bootstrap_token); |
| 1095 sync_prefs_.SetSpareBootstrapToken(bootstrap_token); |
| 1096 } |
| 1097 #endif |
| 1098 |
| 1074 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything, | 1099 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything, |
| 1075 syncable::ModelTypeSet chosen_types) { | 1100 syncable::ModelTypeSet chosen_types) { |
| 1076 if (!backend_.get() && | 1101 if (!backend_.get() && |
| 1077 unrecoverable_error_detected_ == false) { | 1102 unrecoverable_error_detected_ == false) { |
| 1078 NOTREACHED(); | 1103 NOTREACHED(); |
| 1079 return; | 1104 return; |
| 1080 } | 1105 } |
| 1081 | 1106 |
| 1082 UpdateSelectedTypesHistogram(sync_everything, chosen_types); | 1107 UpdateSelectedTypesHistogram(sync_everything, chosen_types); |
| 1083 sync_prefs_.SetKeepEverythingSynced(sync_everything); | 1108 sync_prefs_.SetKeepEverythingSynced(sync_everything); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1431 content::Details<const GoogleServiceSigninSuccessDetails>( | 1456 content::Details<const GoogleServiceSigninSuccessDetails>( |
| 1432 details).ptr(); | 1457 details).ptr(); |
| 1433 DCHECK(!successful->password.empty()); | 1458 DCHECK(!successful->password.empty()); |
| 1434 if (!sync_prefs_.IsStartSuppressed()) { | 1459 if (!sync_prefs_.IsStartSuppressed()) { |
| 1435 cached_passphrase_ = successful->password; | 1460 cached_passphrase_ = successful->password; |
| 1436 // Try to consume the passphrase we just cached. If the sync backend | 1461 // Try to consume the passphrase we just cached. If the sync backend |
| 1437 // is not running yet, the passphrase will remain cached until the | 1462 // is not running yet, the passphrase will remain cached until the |
| 1438 // backend starts up. | 1463 // backend starts up. |
| 1439 ConsumeCachedPassphraseIfPossible(); | 1464 ConsumeCachedPassphraseIfPossible(); |
| 1440 } | 1465 } |
| 1466 #if defined(OS_CHROMEOS) |
| 1467 RefreshSpareBootstrapToken(successful->password); |
| 1468 #endif |
| 1441 if (!sync_initialized() || | 1469 if (!sync_initialized() || |
| 1442 GetAuthError().state() != GoogleServiceAuthError::NONE) { | 1470 GetAuthError().state() != GoogleServiceAuthError::NONE) { |
| 1443 // Track the fact that we're still waiting for auth to complete. | 1471 // Track the fact that we're still waiting for auth to complete. |
| 1444 is_auth_in_progress_ = true; | 1472 is_auth_in_progress_ = true; |
| 1445 } | 1473 } |
| 1446 break; | 1474 break; |
| 1447 } | 1475 } |
| 1448 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { | 1476 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { |
| 1449 const TokenService::TokenRequestFailedDetails& token_details = | 1477 const TokenService::TokenRequestFailedDetails& token_details = |
| 1450 *(content::Details<const TokenService::TokenRequestFailedDetails>( | 1478 *(content::Details<const TokenService::TokenRequestFailedDetails>( |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1595 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine
d-behaviour-after-directly-calling-the-destru. | 1623 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine
d-behaviour-after-directly-calling-the-destru. |
| 1596 ProfileSyncService* old_this = this; | 1624 ProfileSyncService* old_this = this; |
| 1597 this->~ProfileSyncService(); | 1625 this->~ProfileSyncService(); |
| 1598 new(old_this) ProfileSyncService( | 1626 new(old_this) ProfileSyncService( |
| 1599 new ProfileSyncComponentsFactoryImpl(profile, | 1627 new ProfileSyncComponentsFactoryImpl(profile, |
| 1600 CommandLine::ForCurrentProcess()), | 1628 CommandLine::ForCurrentProcess()), |
| 1601 profile, | 1629 profile, |
| 1602 signin, | 1630 signin, |
| 1603 behavior); | 1631 behavior); |
| 1604 } | 1632 } |
| OLD | NEW |