OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
8 #include <cstddef> | 8 #include <cstddef> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 cros_user_(cros_user), | 104 cros_user_(cros_user), |
105 sync_service_url_(kDevServerUrl), | 105 sync_service_url_(kDevServerUrl), |
106 backend_initialized_(false), | 106 backend_initialized_(false), |
107 is_auth_in_progress_(false), | 107 is_auth_in_progress_(false), |
108 wizard_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 108 wizard_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
109 signin_(signin_manager), | 109 signin_(signin_manager), |
110 unrecoverable_error_detected_(false), | 110 unrecoverable_error_detected_(false), |
111 scoped_runnable_method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 111 scoped_runnable_method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
112 expect_sync_configuration_aborted_(false), | 112 expect_sync_configuration_aborted_(false), |
113 clear_server_data_state_(CLEAR_NOT_STARTED), | 113 clear_server_data_state_(CLEAR_NOT_STARTED), |
114 encrypted_types_(browser_sync::Cryptographer::SensitiveTypes()), | |
115 encrypt_everything_(false), | |
114 encryption_pending_(false), | 116 encryption_pending_(false), |
115 auto_start_enabled_(false), | 117 auto_start_enabled_(false), |
116 failed_datatypes_handler_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 118 failed_datatypes_handler_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
117 // By default, dev, canary, and unbranded Chromium users will go to the | 119 // By default, dev, canary, and unbranded Chromium users will go to the |
118 // development servers. Development servers have more features than standard | 120 // development servers. Development servers have more features than standard |
119 // sync servers. Users with officially-branded Chrome stable and beta builds | 121 // sync servers. Users with officially-branded Chrome stable and beta builds |
120 // will go to the standard sync servers. | 122 // will go to the standard sync servers. |
121 // | 123 // |
122 // GetChannel hits the registry on Windows. See http://crbug.com/70380. | 124 // GetChannel hits the registry on Windows. See http://crbug.com/70380. |
123 base::ThreadRestrictions::ScopedAllowIO allow_io; | 125 base::ThreadRestrictions::ScopedAllowIO allow_io; |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 } | 418 } |
417 | 419 |
418 scoped_runnable_method_factory_.RevokeAll(); | 420 scoped_runnable_method_factory_.RevokeAll(); |
419 | 421 |
420 // Clear various flags. | 422 // Clear various flags. |
421 expect_sync_configuration_aborted_ = false; | 423 expect_sync_configuration_aborted_ = false; |
422 is_auth_in_progress_ = false; | 424 is_auth_in_progress_ = false; |
423 backend_initialized_ = false; | 425 backend_initialized_ = false; |
424 cached_passphrases_ = CachedPassphrases(); | 426 cached_passphrases_ = CachedPassphrases(); |
425 encryption_pending_ = false; | 427 encryption_pending_ = false; |
428 encrypt_everything_ = false; | |
429 encrypted_types_ = browser_sync::Cryptographer::SensitiveTypes(); | |
426 passphrase_required_reason_ = sync_api::REASON_PASSPHRASE_NOT_REQUIRED; | 430 passphrase_required_reason_ = sync_api::REASON_PASSPHRASE_NOT_REQUIRED; |
427 last_attempted_user_email_.clear(); | 431 last_attempted_user_email_.clear(); |
428 last_auth_error_ = GoogleServiceAuthError::None(); | 432 last_auth_error_ = GoogleServiceAuthError::None(); |
429 | 433 |
430 if (sync_global_error_.get()) { | 434 if (sync_global_error_.get()) { |
431 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( | 435 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( |
432 sync_global_error_.get()); | 436 sync_global_error_.get()); |
433 RemoveObserver(sync_global_error_.get()); | 437 RemoveObserver(sync_global_error_.get()); |
434 sync_global_error_.reset(NULL); | 438 sync_global_error_.reset(NULL); |
435 } | 439 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
548 if (!success) { | 552 if (!success) { |
549 // If backend initialization failed, abort. We only want to blow away | 553 // If backend initialization failed, abort. We only want to blow away |
550 // state (DBs, etc) if this was a first-time scenario that failed. | 554 // state (DBs, etc) if this was a first-time scenario that failed. |
551 wizard_.Step(SyncSetupWizard::FATAL_ERROR); | 555 wizard_.Step(SyncSetupWizard::FATAL_ERROR); |
552 Shutdown(!HasSyncSetupCompleted()); | 556 Shutdown(!HasSyncSetupCompleted()); |
553 return; | 557 return; |
554 } | 558 } |
555 | 559 |
556 backend_initialized_ = true; | 560 backend_initialized_ = true; |
557 | 561 |
562 // Get initial encrypted types and encrypt everything setting. | |
563 // TODO(akalin): Ideally these would be parameters to | |
564 // OnBackendInitialized(). | |
565 encrypted_types_ = backend_->GetEncryptedDataTypes(); | |
566 DCHECK_GT(encrypted_types_.count(syncable::PASSWORDS), 0u); | |
567 encrypt_everything_ = backend_->EncryptEverythingEnabled(); | |
568 | |
558 sync_js_controller_.AttachJsBackend(js_backend); | 569 sync_js_controller_.AttachJsBackend(js_backend); |
559 | 570 |
560 // The very first time the backend initializes is effectively the first time | 571 // The very first time the backend initializes is effectively the first time |
561 // we can say we successfully "synced". last_synced_time_ will only be null | 572 // we can say we successfully "synced". last_synced_time_ will only be null |
562 // in this case, because the pref wasn't restored on StartUp. | 573 // in this case, because the pref wasn't restored on StartUp. |
563 if (last_synced_time_.is_null()) { | 574 if (last_synced_time_.is_null()) { |
564 UpdateLastSyncedTime(); | 575 UpdateLastSyncedTime(); |
565 } | 576 } |
566 NotifyObservers(); | 577 NotifyObservers(); |
567 | 578 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
828 // wizard we're done (no need to hang around waiting for the sync to | 839 // wizard we're done (no need to hang around waiting for the sync to |
829 // complete). If encryption is pending, its successful completion will trigger | 840 // complete). If encryption is pending, its successful completion will trigger |
830 // the done step. | 841 // the done step. |
831 if (WizardIsVisible() && !encryption_pending()) | 842 if (WizardIsVisible() && !encryption_pending()) |
832 wizard_.Step(SyncSetupWizard::DONE); | 843 wizard_.Step(SyncSetupWizard::DONE); |
833 | 844 |
834 NotifyObservers(); | 845 NotifyObservers(); |
835 } | 846 } |
836 | 847 |
837 void ProfileSyncService::OnEncryptionComplete( | 848 void ProfileSyncService::OnEncryptionComplete( |
838 const syncable::ModelTypeSet& encrypted_types) { | 849 const syncable::ModelTypeSet& encrypted_types, |
850 bool encrypt_everything) { | |
851 encrypted_types_ = encrypted_types; | |
852 encrypt_everything_ = encrypt_everything; | |
853 VLOG(2) << "Encryption complete for " | |
854 << syncable::ModelTypeSetToString(encrypted_types) | |
855 << " (encrypt everything is set to " | |
856 << (encrypt_everything_ ? "true" : "false") << ")"; | |
857 DCHECK_GT(encrypted_types_.count(syncable::PASSWORDS), 0u); | |
839 if (encryption_pending_) { | 858 if (encryption_pending_) { |
840 syncable::ModelTypeSet registered_types; | 859 syncable::ModelTypeSet registered_types; |
841 GetRegisteredDataTypes(®istered_types); | 860 GetRegisteredDataTypes(®istered_types); |
842 bool encryption_complete = true; | 861 bool encryption_complete = true; |
843 for (syncable::ModelTypeSet::const_iterator it = registered_types.begin(); | 862 for (syncable::ModelTypeSet::const_iterator it = registered_types.begin(); |
844 it != registered_types.end(); | 863 it != registered_types.end(); |
845 ++it) { | 864 ++it) { |
846 if (encrypted_types.count(*it) == 0) { | 865 if (encrypted_types.count(*it) == 0) { |
847 // One of our types is not yet encrypted - keep waiting. | 866 // One of our types is not yet encrypted - keep waiting. |
848 encryption_complete = false; | 867 encryption_complete = false; |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1314 if (is_explicit) { | 1333 if (is_explicit) { |
1315 cached_passphrases_.explicit_passphrase = passphrase; | 1334 cached_passphrases_.explicit_passphrase = passphrase; |
1316 } else { | 1335 } else { |
1317 cached_passphrases_.gaia_passphrase = passphrase; | 1336 cached_passphrases_.gaia_passphrase = passphrase; |
1318 } | 1337 } |
1319 } | 1338 } |
1320 } | 1339 } |
1321 | 1340 |
1322 void ProfileSyncService::SetEncryptEverything(bool encrypt_everything) { | 1341 void ProfileSyncService::SetEncryptEverything(bool encrypt_everything) { |
1323 encryption_pending_ = encrypt_everything; | 1342 encryption_pending_ = encrypt_everything; |
1343 encrypt_everything_ = false; | |
Nicolas Zea
2011/10/20 18:40:41
presumably encrypt_everything_ should already be f
akalin
2011/10/21 02:24:17
Done.
| |
1324 } | 1344 } |
1325 | 1345 |
1326 bool ProfileSyncService::encryption_pending() const { | 1346 bool ProfileSyncService::encryption_pending() const { |
1327 return encryption_pending_; | 1347 return encryption_pending_; |
1328 } | 1348 } |
1329 | 1349 |
1330 bool ProfileSyncService::EncryptEverythingEnabled() const { | 1350 bool ProfileSyncService::EncryptEverythingEnabled() const { |
1331 if (!backend_.get() || !backend_initialized_) { | 1351 if (!backend_.get() || !backend_initialized_) { |
1332 NOTREACHED() << "Cannot check encryption without initialized backend."; | 1352 NOTREACHED() << "Cannot check encryption without initialized backend."; |
1333 return false; | 1353 return false; |
1334 } | 1354 } |
1335 return backend_->EncryptEverythingEnabled(); | 1355 return backend_->EncryptEverythingEnabled(); |
1336 } | 1356 } |
1337 | 1357 |
1338 // This will open a transaction to get the encrypted types. Do not call this | |
1339 // if you already have a transaction open. | |
1340 void ProfileSyncService::GetEncryptedDataTypes( | 1358 void ProfileSyncService::GetEncryptedDataTypes( |
1341 syncable::ModelTypeSet* encrypted_types) const { | 1359 syncable::ModelTypeSet* encrypted_types) const { |
1342 CHECK(encrypted_types); | 1360 CHECK(encrypted_types); |
1343 if (backend_.get()) { | 1361 *encrypted_types = encrypted_types_; |
Nicolas Zea
2011/10/20 18:40:41
Is it valid to call this before the backend is ini
akalin
2011/10/21 02:24:17
Yeah, the UI functions call it. Sigh.
| |
1344 *encrypted_types = backend_->GetEncryptedDataTypes(); | 1362 DCHECK_GT(encrypted_types->count(syncable::PASSWORDS), 0u); |
1345 DCHECK(encrypted_types->count(syncable::PASSWORDS)); | |
1346 } else { | |
1347 // Either we are in an unrecoverable error or the sync is not yet done | |
1348 // initializing. In either case just return the sensitive types. During | |
1349 // sync initialization the UI might need to know what our encrypted | |
1350 // types are. | |
1351 *encrypted_types = browser_sync::Cryptographer::SensitiveTypes(); | |
1352 DCHECK(encrypted_types->count(syncable::PASSWORDS)); | |
1353 } | |
1354 } | 1363 } |
1355 | 1364 |
1356 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { | 1365 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { |
1357 NotifyObservers(); | 1366 NotifyObservers(); |
1358 if (is_sync_managed) { | 1367 if (is_sync_managed) { |
1359 DisableForUser(); | 1368 DisableForUser(); |
1360 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { | 1369 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { |
1361 StartUp(); | 1370 StartUp(); |
1362 } | 1371 } |
1363 } | 1372 } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1530 << "Unrecoverable error."; | 1539 << "Unrecoverable error."; |
1531 } else { | 1540 } else { |
1532 VLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " | 1541 VLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " |
1533 << "initialized"; | 1542 << "initialized"; |
1534 } | 1543 } |
1535 } | 1544 } |
1536 | 1545 |
1537 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { | 1546 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { |
1538 return failed_datatypes_handler_; | 1547 return failed_datatypes_handler_; |
1539 } | 1548 } |
OLD | NEW |