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