| OLD | NEW |
| 1 // Copyright (c) 2011 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> |
| 11 | 11 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 31 #include "chrome/browser/sync/glue/change_processor.h" | 31 #include "chrome/browser/sync/glue/change_processor.h" |
| 32 #include "chrome/browser/sync/glue/data_type_controller.h" | 32 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 33 #include "chrome/browser/sync/glue/data_type_manager.h" | 33 #include "chrome/browser/sync/glue/data_type_manager.h" |
| 34 #include "chrome/browser/sync/glue/session_data_type_controller.h" | 34 #include "chrome/browser/sync/glue/session_data_type_controller.h" |
| 35 #include "chrome/browser/sync/glue/session_model_associator.h" | 35 #include "chrome/browser/sync/glue/session_model_associator.h" |
| 36 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" | 36 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" |
| 37 #include "chrome/browser/sync/internal_api/configure_reason.h" | 37 #include "chrome/browser/sync/internal_api/configure_reason.h" |
| 38 #include "chrome/browser/sync/internal_api/sync_manager.h" | 38 #include "chrome/browser/sync/internal_api/sync_manager.h" |
| 39 #include "chrome/browser/sync/js/js_arg_list.h" | 39 #include "chrome/browser/sync/js/js_arg_list.h" |
| 40 #include "chrome/browser/sync/js/js_event_details.h" | 40 #include "chrome/browser/sync/js/js_event_details.h" |
| 41 #include "chrome/browser/sync/profile_sync_components_factory.h" | 41 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" |
| 42 #include "chrome/browser/sync/signin_manager.h" | 42 #include "chrome/browser/sync/signin_manager.h" |
| 43 #include "chrome/browser/sync/sync_global_error.h" | 43 #include "chrome/browser/sync/sync_global_error.h" |
| 44 #include "chrome/browser/sync/util/cryptographer.h" | 44 #include "chrome/browser/sync/util/cryptographer.h" |
| 45 #include "chrome/browser/sync/util/oauth.h" | 45 #include "chrome/browser/sync/util/oauth.h" |
| 46 #include "chrome/browser/ui/browser.h" | 46 #include "chrome/browser/ui/browser.h" |
| 47 #include "chrome/browser/ui/browser_list.h" | 47 #include "chrome/browser/ui/browser_list.h" |
| 48 #include "chrome/browser/ui/browser_window.h" | 48 #include "chrome/browser/ui/browser_window.h" |
| 49 #include "chrome/browser/ui/global_error_service.h" | 49 #include "chrome/browser/ui/global_error_service.h" |
| 50 #include "chrome/browser/ui/global_error_service_factory.h" | 50 #include "chrome/browser/ui/global_error_service_factory.h" |
| 51 #include "chrome/common/chrome_notification_types.h" | 51 #include "chrome/common/chrome_notification_types.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // sync servers. Users with officially-branded Chrome stable and beta builds | 132 // sync servers. Users with officially-branded Chrome stable and beta builds |
| 133 // will go to the standard sync servers. | 133 // will go to the standard sync servers. |
| 134 // | 134 // |
| 135 // GetChannel hits the registry on Windows. See http://crbug.com/70380. | 135 // GetChannel hits the registry on Windows. See http://crbug.com/70380. |
| 136 base::ThreadRestrictions::ScopedAllowIO allow_io; | 136 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 137 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 137 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| 138 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 138 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
| 139 channel == chrome::VersionInfo::CHANNEL_BETA) { | 139 channel == chrome::VersionInfo::CHANNEL_BETA) { |
| 140 sync_service_url_ = GURL(kSyncServerUrl); | 140 sync_service_url_ = GURL(kSyncServerUrl); |
| 141 } | 141 } |
| 142 | |
| 143 } | 142 } |
| 144 | 143 |
| 145 ProfileSyncService::~ProfileSyncService() { | 144 ProfileSyncService::~ProfileSyncService() { |
| 146 sync_prefs_.RemoveSyncPrefObserver(this); | 145 sync_prefs_.RemoveSyncPrefObserver(this); |
| 147 Shutdown(false); | 146 Shutdown(); |
| 148 } | 147 } |
| 149 | 148 |
| 150 bool ProfileSyncService::AreCredentialsAvailable() { | 149 bool ProfileSyncService::AreCredentialsAvailable() { |
| 151 return AreCredentialsAvailable(false); | 150 return AreCredentialsAvailable(false); |
| 152 } | 151 } |
| 153 | 152 |
| 154 bool ProfileSyncService::AreCredentialsAvailable( | 153 bool ProfileSyncService::AreCredentialsAvailable( |
| 155 bool check_oauth_login_token) { | 154 bool check_oauth_login_token) { |
| 156 if (IsManaged()) { | 155 if (IsManaged()) { |
| 157 return false; | 156 return false; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 InitializeBackend(!HasSyncSetupCompleted()); | 369 InitializeBackend(!HasSyncSetupCompleted()); |
| 371 | 370 |
| 372 if (!sync_global_error_.get()) { | 371 if (!sync_global_error_.get()) { |
| 373 sync_global_error_.reset(new SyncGlobalError(this)); | 372 sync_global_error_.reset(new SyncGlobalError(this)); |
| 374 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( | 373 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( |
| 375 sync_global_error_.get()); | 374 sync_global_error_.get()); |
| 376 AddObserver(sync_global_error_.get()); | 375 AddObserver(sync_global_error_.get()); |
| 377 } | 376 } |
| 378 } | 377 } |
| 379 | 378 |
| 380 void ProfileSyncService::Shutdown(bool sync_disabled) { | 379 void ProfileSyncService::Shutdown() { |
| 380 ShutdownImpl(false); |
| 381 } |
| 382 |
| 383 void ProfileSyncService::ShutdownImpl(bool sync_disabled) { |
| 381 // First, we spin down the backend and wait for it to stop syncing completely | 384 // First, we spin down the backend and wait for it to stop syncing completely |
| 382 // before we Stop the data type manager. This is to avoid a late sync cycle | 385 // before we Stop the data type manager. This is to avoid a late sync cycle |
| 383 // applying changes to the sync db that wouldn't get applied via | 386 // applying changes to the sync db that wouldn't get applied via |
| 384 // ChangeProcessors, leading to back-from-the-dead bugs. | 387 // ChangeProcessors, leading to back-from-the-dead bugs. |
| 385 if (backend_.get()) | 388 if (backend_.get()) |
| 386 backend_->StopSyncingForShutdown(); | 389 backend_->StopSyncingForShutdown(); |
| 387 | 390 |
| 388 // Stop all data type controllers, if needed. Note that until Stop | 391 // Stop all data type controllers, if needed. Note that until Stop |
| 389 // completes, it is possible in theory to have a ChangeProcessor apply a | 392 // completes, it is possible in theory to have a ChangeProcessor apply a |
| 390 // change from a native model. In that case, it will get applied to the sync | 393 // change from a native model. In that case, it will get applied to the sync |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 } | 457 } |
| 455 | 458 |
| 456 void ProfileSyncService::DisableForUser() { | 459 void ProfileSyncService::DisableForUser() { |
| 457 if (SetupInProgress()) | 460 if (SetupInProgress()) |
| 458 wizard_.Step(SyncSetupWizard::ABORT); | 461 wizard_.Step(SyncSetupWizard::ABORT); |
| 459 | 462 |
| 460 // Clear prefs (including SyncSetupHasCompleted) before shutting down so | 463 // Clear prefs (including SyncSetupHasCompleted) before shutting down so |
| 461 // PSS clients don't think we're set up while we're shutting down. | 464 // PSS clients don't think we're set up while we're shutting down. |
| 462 sync_prefs_.ClearPreferences(); | 465 sync_prefs_.ClearPreferences(); |
| 463 ClearUnrecoverableError(); | 466 ClearUnrecoverableError(); |
| 464 Shutdown(true); | 467 ShutdownImpl(true); |
| 465 | 468 |
| 466 signin_->SignOut(); | 469 signin_->SignOut(); |
| 467 | 470 |
| 468 NotifyObservers(); | 471 NotifyObservers(); |
| 469 } | 472 } |
| 470 | 473 |
| 471 bool ProfileSyncService::HasSyncSetupCompleted() const { | 474 bool ProfileSyncService::HasSyncSetupCompleted() const { |
| 472 return sync_prefs_.HasSyncSetupCompleted(); | 475 return sync_prefs_.HasSyncSetupCompleted(); |
| 473 } | 476 } |
| 474 | 477 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 NOTREACHED(); | 515 NOTREACHED(); |
| 513 return ""; | 516 return ""; |
| 514 } | 517 } |
| 515 | 518 |
| 516 void ProfileSyncService::RegisterNewDataType(syncable::ModelType data_type) { | 519 void ProfileSyncService::RegisterNewDataType(syncable::ModelType data_type) { |
| 517 if (data_type_controllers_.count(data_type) > 0) | 520 if (data_type_controllers_.count(data_type) > 0) |
| 518 return; | 521 return; |
| 519 switch (data_type) { | 522 switch (data_type) { |
| 520 case syncable::SESSIONS: | 523 case syncable::SESSIONS: |
| 521 RegisterDataTypeController( | 524 RegisterDataTypeController( |
| 522 new browser_sync::SessionDataTypeController(factory_, | 525 new browser_sync::SessionDataTypeController(factory_.get(), |
| 523 profile_, | 526 profile_, |
| 524 this)); | 527 this)); |
| 525 return; | 528 return; |
| 526 case syncable::TYPED_URLS: | 529 case syncable::TYPED_URLS: |
| 527 RegisterDataTypeController( | 530 new browser_sync::TypedUrlDataTypeController(factory_.get(), |
| 528 new browser_sync::TypedUrlDataTypeController(factory_, | |
| 529 profile_, | 531 profile_, |
| 530 this)); | 532 this); |
| 531 return; | 533 return; |
| 532 default: | 534 default: |
| 533 break; | 535 break; |
| 534 } | 536 } |
| 535 NOTREACHED(); | 537 NOTREACHED(); |
| 536 } | 538 } |
| 537 | 539 |
| 538 // An invariant has been violated. Transition to an error state where we try | 540 // An invariant has been violated. Transition to an error state where we try |
| 539 // to do as little work as possible, to avoid further corruption or crashes. | 541 // to do as little work as possible, to avoid further corruption or crashes. |
| 540 void ProfileSyncService::OnUnrecoverableError( | 542 void ProfileSyncService::OnUnrecoverableError( |
| 541 const tracked_objects::Location& from_here, | 543 const tracked_objects::Location& from_here, |
| 542 const std::string& message) { | 544 const std::string& message) { |
| 543 unrecoverable_error_detected_ = true; | 545 unrecoverable_error_detected_ = true; |
| 544 unrecoverable_error_message_ = message; | 546 unrecoverable_error_message_ = message; |
| 545 unrecoverable_error_location_ = from_here; | 547 unrecoverable_error_location_ = from_here; |
| 546 | 548 |
| 547 // Tell the wizard so it can inform the user only if it is already open. | 549 // Tell the wizard so it can inform the user only if it is already open. |
| 548 wizard_.Step(SyncSetupWizard::FATAL_ERROR); | 550 wizard_.Step(SyncSetupWizard::FATAL_ERROR); |
| 549 | 551 |
| 550 NotifyObservers(); | 552 NotifyObservers(); |
| 551 std::string location; | 553 std::string location; |
| 552 from_here.Write(true, true, &location); | 554 from_here.Write(true, true, &location); |
| 553 LOG(ERROR) | 555 LOG(ERROR) |
| 554 << "Unrecoverable error detected at " << location | 556 << "Unrecoverable error detected at " << location |
| 555 << " -- ProfileSyncService unusable: " << message; | 557 << " -- ProfileSyncService unusable: " << message; |
| 556 | 558 |
| 557 // Shut all data types down. | 559 // Shut all data types down. |
| 558 MessageLoop::current()->PostTask(FROM_HERE, | 560 MessageLoop::current()->PostTask(FROM_HERE, |
| 559 base::Bind(&ProfileSyncService::Shutdown, weak_factory_.GetWeakPtr(), | 561 base::Bind(&ProfileSyncService::ShutdownImpl, weak_factory_.GetWeakPtr(), |
| 560 true)); | 562 true)); |
| 561 } | 563 } |
| 562 | 564 |
| 563 void ProfileSyncService::OnBackendInitialized( | 565 void ProfileSyncService::OnBackendInitialized( |
| 564 const WeakHandle<JsBackend>& js_backend, bool success) { | 566 const WeakHandle<JsBackend>& js_backend, bool success) { |
| 565 if (!HasSyncSetupCompleted()) { | 567 if (!HasSyncSetupCompleted()) { |
| 566 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); | 568 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); |
| 567 } else { | 569 } else { |
| 568 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); | 570 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); |
| 569 } | 571 } |
| (...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1525 return false; | 1527 return false; |
| 1526 | 1528 |
| 1527 if (!data_type_manager_.get()) | 1529 if (!data_type_manager_.get()) |
| 1528 return false; | 1530 return false; |
| 1529 | 1531 |
| 1530 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1532 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
| 1531 } | 1533 } |
| 1532 | 1534 |
| 1533 void ProfileSyncService::StopAndSuppress() { | 1535 void ProfileSyncService::StopAndSuppress() { |
| 1534 sync_prefs_.SetStartSuppressed(true); | 1536 sync_prefs_.SetStartSuppressed(true); |
| 1535 Shutdown(false); | 1537 ShutdownImpl(false); |
| 1536 } | 1538 } |
| 1537 | 1539 |
| 1538 void ProfileSyncService::UnsuppressAndStart() { | 1540 void ProfileSyncService::UnsuppressAndStart() { |
| 1539 DCHECK(profile_); | 1541 DCHECK(profile_); |
| 1540 sync_prefs_.SetStartSuppressed(false); | 1542 sync_prefs_.SetStartSuppressed(false); |
| 1541 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess | 1543 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess |
| 1542 // is never called for some clients. | 1544 // is never called for some clients. |
| 1543 if (signin_->GetAuthenticatedUsername().empty()) { | 1545 if (signin_->GetAuthenticatedUsername().empty()) { |
| 1544 signin_->SetAuthenticatedUsername( | 1546 signin_->SetAuthenticatedUsername( |
| 1545 sync_prefs_.GetGoogleServicesUsername()); | 1547 sync_prefs_.GetGoogleServicesUsername()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1569 << "Unrecoverable error."; | 1571 << "Unrecoverable error."; |
| 1570 } else { | 1572 } else { |
| 1571 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " | 1573 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " |
| 1572 << "initialized"; | 1574 << "initialized"; |
| 1573 } | 1575 } |
| 1574 } | 1576 } |
| 1575 | 1577 |
| 1576 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { | 1578 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { |
| 1577 return failed_datatypes_handler_; | 1579 return failed_datatypes_handler_; |
| 1578 } | 1580 } |
| OLD | NEW |