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

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

Issue 9232011: sync: Make ProfileSyncService a ProfileKeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: init Created 8 years, 11 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 22 matching lines...) Expand all
33 #include "chrome/browser/sync/glue/change_processor.h" 33 #include "chrome/browser/sync/glue/change_processor.h"
34 #include "chrome/browser/sync/glue/data_type_controller.h" 34 #include "chrome/browser/sync/glue/data_type_controller.h"
35 #include "chrome/browser/sync/glue/data_type_manager.h" 35 #include "chrome/browser/sync/glue/data_type_manager.h"
36 #include "chrome/browser/sync/glue/session_data_type_controller.h" 36 #include "chrome/browser/sync/glue/session_data_type_controller.h"
37 #include "chrome/browser/sync/glue/session_model_associator.h" 37 #include "chrome/browser/sync/glue/session_model_associator.h"
38 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" 38 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h"
39 #include "chrome/browser/sync/internal_api/configure_reason.h" 39 #include "chrome/browser/sync/internal_api/configure_reason.h"
40 #include "chrome/browser/sync/internal_api/sync_manager.h" 40 #include "chrome/browser/sync/internal_api/sync_manager.h"
41 #include "chrome/browser/sync/js/js_arg_list.h" 41 #include "chrome/browser/sync/js/js_arg_list.h"
42 #include "chrome/browser/sync/js/js_event_details.h" 42 #include "chrome/browser/sync/js/js_event_details.h"
43 #include "chrome/browser/sync/profile_sync_components_factory.h" 43 #include "chrome/browser/sync/profile_sync_components_factory_impl.h"
44 #include "chrome/browser/sync/sync_global_error.h" 44 #include "chrome/browser/sync/sync_global_error.h"
45 #include "chrome/browser/sync/util/cryptographer.h" 45 #include "chrome/browser/sync/util/cryptographer.h"
46 #include "chrome/browser/sync/util/oauth.h" 46 #include "chrome/browser/sync/util/oauth.h"
47 #include "chrome/browser/ui/browser.h" 47 #include "chrome/browser/ui/browser.h"
48 #include "chrome/browser/ui/browser_list.h" 48 #include "chrome/browser/ui/browser_list.h"
49 #include "chrome/browser/ui/browser_window.h" 49 #include "chrome/browser/ui/browser_window.h"
50 #include "chrome/browser/ui/global_error_service.h" 50 #include "chrome/browser/ui/global_error_service.h"
51 #include "chrome/browser/ui/global_error_service_factory.h" 51 #include "chrome/browser/ui/global_error_service_factory.h"
52 #include "chrome/common/chrome_notification_types.h" 52 #include "chrome/common/chrome_notification_types.h"
53 #include "chrome/common/chrome_switches.h" 53 #include "chrome/common/chrome_switches.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // sync servers. Users with officially-branded Chrome stable and beta builds 133 // sync servers. Users with officially-branded Chrome stable and beta builds
134 // will go to the standard sync servers. 134 // will go to the standard sync servers.
135 // 135 //
136 // GetChannel hits the registry on Windows. See http://crbug.com/70380. 136 // GetChannel hits the registry on Windows. See http://crbug.com/70380.
137 base::ThreadRestrictions::ScopedAllowIO allow_io; 137 base::ThreadRestrictions::ScopedAllowIO allow_io;
138 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); 138 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
139 if (channel == chrome::VersionInfo::CHANNEL_STABLE || 139 if (channel == chrome::VersionInfo::CHANNEL_STABLE ||
140 channel == chrome::VersionInfo::CHANNEL_BETA) { 140 channel == chrome::VersionInfo::CHANNEL_BETA) {
141 sync_service_url_ = GURL(kSyncServerUrl); 141 sync_service_url_ = GURL(kSyncServerUrl);
142 } 142 }
143
144 } 143 }
145 144
146 ProfileSyncService::~ProfileSyncService() { 145 ProfileSyncService::~ProfileSyncService() {
147 sync_prefs_.RemoveSyncPrefObserver(this); 146 sync_prefs_.RemoveSyncPrefObserver(this);
148 Shutdown(false); 147 Shutdown();
149 } 148 }
150 149
151 bool ProfileSyncService::AreCredentialsAvailable() { 150 bool ProfileSyncService::AreCredentialsAvailable() {
152 return AreCredentialsAvailable(false); 151 return AreCredentialsAvailable(false);
153 } 152 }
154 153
155 bool ProfileSyncService::AreCredentialsAvailable( 154 bool ProfileSyncService::AreCredentialsAvailable(
156 bool check_oauth_login_token) { 155 bool check_oauth_login_token) {
157 if (IsManaged()) { 156 if (IsManaged()) {
158 return false; 157 return false;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 InitializeBackend(!HasSyncSetupCompleted()); 371 InitializeBackend(!HasSyncSetupCompleted());
373 372
374 if (!sync_global_error_.get()) { 373 if (!sync_global_error_.get()) {
375 sync_global_error_.reset(new SyncGlobalError(this)); 374 sync_global_error_.reset(new SyncGlobalError(this));
376 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( 375 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(
377 sync_global_error_.get()); 376 sync_global_error_.get());
378 AddObserver(sync_global_error_.get()); 377 AddObserver(sync_global_error_.get());
379 } 378 }
380 } 379 }
381 380
382 void ProfileSyncService::Shutdown(bool sync_disabled) { 381 void ProfileSyncService::Shutdown() {
382 ShutdownImpl(false);
383 }
384
385 void ProfileSyncService::ShutdownImpl(bool sync_disabled) {
383 // First, we spin down the backend and wait for it to stop syncing completely 386 // First, we spin down the backend and wait for it to stop syncing completely
384 // before we Stop the data type manager. This is to avoid a late sync cycle 387 // before we Stop the data type manager. This is to avoid a late sync cycle
385 // applying changes to the sync db that wouldn't get applied via 388 // applying changes to the sync db that wouldn't get applied via
386 // ChangeProcessors, leading to back-from-the-dead bugs. 389 // ChangeProcessors, leading to back-from-the-dead bugs.
387 if (backend_.get()) 390 if (backend_.get())
388 backend_->StopSyncingForShutdown(); 391 backend_->StopSyncingForShutdown();
389 392
390 // Stop all data type controllers, if needed. Note that until Stop 393 // Stop all data type controllers, if needed. Note that until Stop
391 // completes, it is possible in theory to have a ChangeProcessor apply a 394 // completes, it is possible in theory to have a ChangeProcessor apply a
392 // change from a native model. In that case, it will get applied to the sync 395 // change from a native model. In that case, it will get applied to the sync
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 } 458 }
456 459
457 void ProfileSyncService::DisableForUser() { 460 void ProfileSyncService::DisableForUser() {
458 if (SetupInProgress()) 461 if (SetupInProgress())
459 wizard_.Step(SyncSetupWizard::ABORT); 462 wizard_.Step(SyncSetupWizard::ABORT);
460 463
461 // Clear prefs (including SyncSetupHasCompleted) before shutting down so 464 // Clear prefs (including SyncSetupHasCompleted) before shutting down so
462 // PSS clients don't think we're set up while we're shutting down. 465 // PSS clients don't think we're set up while we're shutting down.
463 sync_prefs_.ClearPreferences(); 466 sync_prefs_.ClearPreferences();
464 ClearUnrecoverableError(); 467 ClearUnrecoverableError();
465 Shutdown(true); 468 ShutdownImpl(true);
466 469
467 // TODO(atwilson): Don't call SignOut() on *any* platform - move this into 470 // TODO(atwilson): Don't call SignOut() on *any* platform - move this into
468 // the UI layer if needed (sync activity should never result in the user 471 // the UI layer if needed (sync activity should never result in the user
469 // being logged out of all chrome services). 472 // being logged out of all chrome services).
470 if (!auto_start_enabled_) 473 if (!auto_start_enabled_)
471 signin_->SignOut(); 474 signin_->SignOut();
472 475
473 NotifyObservers(); 476 NotifyObservers();
474 } 477 }
475 478
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 NOTREACHED(); 520 NOTREACHED();
518 return ""; 521 return "";
519 } 522 }
520 523
521 void ProfileSyncService::RegisterNewDataType(syncable::ModelType data_type) { 524 void ProfileSyncService::RegisterNewDataType(syncable::ModelType data_type) {
522 if (data_type_controllers_.count(data_type) > 0) 525 if (data_type_controllers_.count(data_type) > 0)
523 return; 526 return;
524 switch (data_type) { 527 switch (data_type) {
525 case syncable::SESSIONS: 528 case syncable::SESSIONS:
526 RegisterDataTypeController( 529 RegisterDataTypeController(
527 new browser_sync::SessionDataTypeController(factory_, 530 new browser_sync::SessionDataTypeController(factory_.get(),
528 profile_, 531 profile_,
529 this)); 532 this));
530 return; 533 return;
531 case syncable::TYPED_URLS: 534 case syncable::TYPED_URLS:
532 RegisterDataTypeController( 535 RegisterDataTypeController(
533 new browser_sync::TypedUrlDataTypeController(factory_, profile_)); 536 new browser_sync::TypedUrlDataTypeController(factory_.get(),
537 profile_));
534 return; 538 return;
535 default: 539 default:
536 break; 540 break;
537 } 541 }
538 NOTREACHED(); 542 NOTREACHED();
539 } 543 }
540 544
541 // An invariant has been violated. Transition to an error state where we try 545 // An invariant has been violated. Transition to an error state where we try
542 // to do as little work as possible, to avoid further corruption or crashes. 546 // to do as little work as possible, to avoid further corruption or crashes.
543 void ProfileSyncService::OnUnrecoverableError( 547 void ProfileSyncService::OnUnrecoverableError(
544 const tracked_objects::Location& from_here, 548 const tracked_objects::Location& from_here,
545 const std::string& message) { 549 const std::string& message) {
546 unrecoverable_error_detected_ = true; 550 unrecoverable_error_detected_ = true;
547 unrecoverable_error_message_ = message; 551 unrecoverable_error_message_ = message;
548 unrecoverable_error_location_ = from_here; 552 unrecoverable_error_location_ = from_here;
549 553
550 // Tell the wizard so it can inform the user only if it is already open. 554 // Tell the wizard so it can inform the user only if it is already open.
551 wizard_.Step(SyncSetupWizard::FATAL_ERROR); 555 wizard_.Step(SyncSetupWizard::FATAL_ERROR);
552 556
553 NotifyObservers(); 557 NotifyObservers();
554 std::string location; 558 std::string location;
555 from_here.Write(true, true, &location); 559 from_here.Write(true, true, &location);
556 LOG(ERROR) 560 LOG(ERROR)
557 << "Unrecoverable error detected at " << location 561 << "Unrecoverable error detected at " << location
558 << " -- ProfileSyncService unusable: " << message; 562 << " -- ProfileSyncService unusable: " << message;
559 563
560 // Shut all data types down. 564 // Shut all data types down.
561 MessageLoop::current()->PostTask(FROM_HERE, 565 MessageLoop::current()->PostTask(FROM_HERE,
562 base::Bind(&ProfileSyncService::Shutdown, weak_factory_.GetWeakPtr(), 566 base::Bind(&ProfileSyncService::ShutdownImpl, weak_factory_.GetWeakPtr(),
563 true)); 567 true));
564 } 568 }
565 569
566 void ProfileSyncService::OnBackendInitialized( 570 void ProfileSyncService::OnBackendInitialized(
567 const WeakHandle<JsBackend>& js_backend, bool success) { 571 const WeakHandle<JsBackend>& js_backend, bool success) {
568 if (!HasSyncSetupCompleted()) { 572 if (!HasSyncSetupCompleted()) {
569 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); 573 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success);
570 } else { 574 } else {
571 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); 575 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success);
572 } 576 }
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 return false; 1513 return false;
1510 1514
1511 if (!data_type_manager_.get()) 1515 if (!data_type_manager_.get())
1512 return false; 1516 return false;
1513 1517
1514 return data_type_manager_->state() == DataTypeManager::CONFIGURED; 1518 return data_type_manager_->state() == DataTypeManager::CONFIGURED;
1515 } 1519 }
1516 1520
1517 void ProfileSyncService::StopAndSuppress() { 1521 void ProfileSyncService::StopAndSuppress() {
1518 sync_prefs_.SetStartSuppressed(true); 1522 sync_prefs_.SetStartSuppressed(true);
1519 Shutdown(false); 1523 ShutdownImpl(false);
1520 } 1524 }
1521 1525
1522 void ProfileSyncService::UnsuppressAndStart() { 1526 void ProfileSyncService::UnsuppressAndStart() {
1523 DCHECK(profile_); 1527 DCHECK(profile_);
1524 sync_prefs_.SetStartSuppressed(false); 1528 sync_prefs_.SetStartSuppressed(false);
1525 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess 1529 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess
1526 // is never called for some clients. 1530 // is never called for some clients.
1527 if (signin_->GetAuthenticatedUsername().empty()) { 1531 if (signin_->GetAuthenticatedUsername().empty()) {
1528 signin_->SetAuthenticatedUsername( 1532 signin_->SetAuthenticatedUsername(
1529 sync_prefs_.GetGoogleServicesUsername()); 1533 sync_prefs_.GetGoogleServicesUsername());
(...skipping 23 matching lines...) Expand all
1553 << "Unrecoverable error."; 1557 << "Unrecoverable error.";
1554 } else { 1558 } else {
1555 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " 1559 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not "
1556 << "initialized"; 1560 << "initialized";
1557 } 1561 }
1558 } 1562 }
1559 1563
1560 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { 1564 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() {
1561 return failed_datatypes_handler_; 1565 return failed_datatypes_handler_;
1562 } 1566 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698