summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/profile_sync_service.cc
diff options
context:
space:
mode:
authorskrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-16 22:20:26 +0000
committerskrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-16 22:20:26 +0000
commit500f176dbbd17fee9f903d0163dafa89593cc1c0 (patch)
tree4a7550425c7bf70879d4146b959bac0ab0712131 /chrome/browser/sync/profile_sync_service.cc
parent4cedf0dadf16c181be11d86f15af28c43c81b705 (diff)
downloadchromium_src-500f176dbbd17fee9f903d0163dafa89593cc1c0.zip
chromium_src-500f176dbbd17fee9f903d0163dafa89593cc1c0.tar.gz
chromium_src-500f176dbbd17fee9f903d0163dafa89593cc1c0.tar.bz2
This change will include preferences as part of the usual startup sequence of the PSS that already includes bookmarks. This is a temporary solution until we have a proper component to manage the startup and shutdown of multiple data types.
Review URL: http://codereview.chromium.org/601037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39143 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/profile_sync_service.cc')
-rw-r--r--chrome/browser/sync/profile_sync_service.cc98
1 files changed, 83 insertions, 15 deletions
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc
index c6baf7f..9932d72 100644
--- a/chrome/browser/sync/profile_sync_service.cc
+++ b/chrome/browser/sync/profile_sync_service.cc
@@ -43,6 +43,7 @@ ProfileSyncService::ProfileSyncService(Profile* profile)
is_auth_in_progress_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(wizard_(this)),
unrecoverable_error_detected_(false),
+ startup_had_first_time_(false),
notification_method_(browser_sync::kDefaultNotificationMethod) {
}
@@ -162,7 +163,8 @@ void ProfileSyncService::StartUp() {
last_synced_time_ = base::Time::FromInternalValue(
profile_->GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime));
- backend_.reset(new SyncBackendHost(this, profile_->GetPath()));
+ backend_.reset(
+ new SyncBackendHost(this, profile_->GetPath(), data_type_controllers_));
// Initialize the backend. Every time we start up a new SyncBackendHost,
// we'll want to start from a fresh SyncDB, so delete any old one that might
@@ -176,8 +178,8 @@ void ProfileSyncService::Shutdown(bool sync_disabled) {
// Stop all data type controllers.
// TODO(skrul): Change this to support multiple data type controllers.
- if (data_type_controllers_.count(syncable::BOOKMARKS))
- data_type_controllers_[syncable::BOOKMARKS]->Stop();
+ StopDataType(syncable::BOOKMARKS);
+ StopDataType(syncable::PREFERENCES);
backend_.reset();
@@ -233,7 +235,8 @@ void ProfileSyncService::OnUnrecoverableError() {
unrecoverable_error_detected_ = true;
// TODO(skrul): Change this to support multiple data type controllers.
- data_type_controllers_[syncable::BOOKMARKS]->Stop();
+ StopDataType(syncable::BOOKMARKS);
+ StopDataType(syncable::PREFERENCES);
// Tell the wizard so it can inform the user only if it is already open.
wizard_.Step(SyncSetupWizard::FATAL_ERROR);
@@ -348,6 +351,14 @@ string16 ProfileSyncService::GetAuthenticatedUsername() const {
return backend_->GetAuthenticatedUsername();
}
+void ProfileSyncService::StopDataType(syncable::ModelType model_type) {
+ if (data_type_controllers_.count(model_type) &&
+ data_type_controllers_[model_type]->state() !=
+ DataTypeController::NOT_RUNNING) {
+ data_type_controllers_[model_type]->Stop();
+ }
+}
+
void ProfileSyncService::OnUserSubmittedAuth(
const std::string& username, const std::string& password,
const std::string& captcha) {
@@ -380,6 +391,7 @@ void ProfileSyncService::OnUserCancelledDialog() {
void ProfileSyncService::StartProcessingChangesIfReady() {
DCHECK(backend_initialized_);
+ startup_had_first_time_ = false;
// If the user has completed sync setup, we are always allowed to
// merge data.
@@ -395,9 +407,17 @@ void ProfileSyncService::StartProcessingChangesIfReady() {
// Start data types.
// TODO(skrul): Change this to support multiple data type controllers.
- data_type_controllers_[syncable::BOOKMARKS]->Start(
- merge_allowed,
- NewCallback(this, &ProfileSyncService::BookmarkStartCallback));
+ if (data_type_controllers_.count(syncable::BOOKMARKS)) {
+ data_type_controllers_[syncable::BOOKMARKS]->Start(
+ merge_allowed,
+ NewCallback(this, &ProfileSyncService::BookmarkStartCallback));
+ } else {
+ if (data_type_controllers_.count(syncable::PREFERENCES)) {
+ data_type_controllers_[syncable::PREFERENCES]->Start(
+ true,
+ NewCallback(this, &ProfileSyncService::PreferenceStartCallback));
+ }
+ }
}
void ProfileSyncService::BookmarkStartCallback(
@@ -405,9 +425,22 @@ void ProfileSyncService::BookmarkStartCallback(
switch (result) {
case DataTypeController::OK:
case DataTypeController::OK_FIRST_RUN: {
- wizard_.Step(result == DataTypeController::OK ? SyncSetupWizard::DONE :
- SyncSetupWizard::DONE_FIRST_TIME);
- FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged());
+ startup_had_first_time_ |= result == DataTypeController::OK_FIRST_RUN;
+
+ // If the preference data type was registered, start it here.
+ // Since we only care about presenting the merge warning dialog
+ // for bookmarks, pass a "true" for merge_allowed so preferences
+ // will always start. If preferences is not registered, just
+ // call the callback directly so we can finish startup.
+ // TODO(skrul): Change this to support multiple data type
+ // controllers.
+ if (data_type_controllers_.count(syncable::PREFERENCES)) {
+ data_type_controllers_[syncable::PREFERENCES]->Start(
+ true,
+ NewCallback(this, &ProfileSyncService::PreferenceStartCallback));
+ } else {
+ PreferenceStartCallback(DataTypeController::OK);
+ }
break;
}
@@ -420,6 +453,27 @@ void ProfileSyncService::BookmarkStartCallback(
default: {
LOG(ERROR) << "Bookmark start failed";
OnUnrecoverableError();
+ break;
+ }
+ }
+}
+
+void ProfileSyncService::PreferenceStartCallback(
+ DataTypeController::StartResult result) {
+ switch (result) {
+ case DataTypeController::OK:
+ case DataTypeController::OK_FIRST_RUN: {
+ startup_had_first_time_ |= result == DataTypeController::OK_FIRST_RUN;
+
+ wizard_.Step(startup_had_first_time_ ? SyncSetupWizard:: DONE_FIRST_TIME :
+ SyncSetupWizard::DONE);
+ FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged());
+ break;
+ }
+ default: {
+ LOG(ERROR) << "Preference start failed";
+ OnUnrecoverableError();
+ break;
}
}
}
@@ -460,9 +514,23 @@ bool ProfileSyncService::ShouldPushChanges() {
// True only after all bootstrapping has succeeded: the bookmark model is
// loaded, the sync backend is initialized, the two domains are
// consistent with one another, and no unrecoverable error has transpired.
- if (data_type_controllers_.count(syncable::BOOKMARKS)) {
- return data_type_controllers_[syncable::BOOKMARKS]->state() ==
- DataTypeController::RUNNING;
- }
- return false;
+
+ // Don't push changes if there are no data type controllers registered.
+ if (data_type_controllers_.size() == 0)
+ return false;
+
+ // TODO: make this size_t
+ DataTypeController::TypeMap::size_type running_data_type_controllers = 0;
+ if (data_type_controllers_.count(syncable::BOOKMARKS) &&
+ data_type_controllers_[syncable::BOOKMARKS]->state() ==
+ DataTypeController::RUNNING)
+ running_data_type_controllers++;
+
+ if (data_type_controllers_.count(syncable::PREFERENCES) &&
+ data_type_controllers_[syncable::PREFERENCES]->state() ==
+ DataTypeController::RUNNING)
+ running_data_type_controllers++;
+
+ // Return true only if all data type controllers are running.
+ return data_type_controllers_.size() == running_data_type_controllers;
}