Chromium Code Reviews| Index: chrome/browser/sync/glue/sync_backend_host.cc |
| diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc |
| index efa717b1d97cdac7119bb3f4691b24a8436caecf..7807dfa8c460e79d508dbda2f5c63cbb2665f0bf 100644 |
| --- a/chrome/browser/sync/glue/sync_backend_host.cc |
| +++ b/chrome/browser/sync/glue/sync_backend_host.cc |
| @@ -15,6 +15,8 @@ |
| #include "base/threading/thread_restrictions.h" |
| #include "base/tracked.h" |
| #include "base/utf_string_conversions.h" |
| +#include "chrome/browser/about_flags.h" |
| +#include "chrome/browser/browser_process.h" |
| #include "chrome/browser/net/gaia/token_service.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| #include "chrome/browser/profiles/profile.h" |
| @@ -25,6 +27,7 @@ |
| #include "chrome/browser/sync/glue/history_model_worker.h" |
| #include "chrome/browser/sync/glue/http_bridge.h" |
| #include "chrome/browser/sync/glue/password_model_worker.h" |
| +#include "chrome/browser/sync/glue/session_data_type_controller.h" |
| #include "chrome/browser/sync/glue/sync_backend_host.h" |
| #include "chrome/browser/sync/internal_api/base_transaction.h" |
| #include "chrome/browser/sync/internal_api/sync_manager.h" |
| @@ -94,6 +97,7 @@ SyncBackendHost::~SyncBackendHost() { |
| void SyncBackendHost::Initialize( |
| SyncFrontend* frontend, |
| + ProfileSyncFactory* factory, |
| const WeakHandle<JsEventHandler>& event_handler, |
| const GURL& sync_service_url, |
| const syncable::ModelTypeSet& initial_types, |
| @@ -103,6 +107,7 @@ void SyncBackendHost::Initialize( |
| return; |
| frontend_ = frontend; |
| + profile_sync_factory_ = factory; |
| DCHECK(frontend); |
| registrar_.workers[GROUP_DB] = new DatabaseModelWorker(); |
| @@ -862,9 +867,46 @@ void SyncBackendHost::Core::HandleSyncCycleCompletedOnFrontendLoop( |
| host_->last_snapshot_.reset(snapshot); |
| - const syncable::ModelTypeSet& to_migrate = |
| + syncable::ModelTypeSet to_migrate = |
| snapshot->syncer_status.types_needing_local_migration; |
| - if (!to_migrate.empty()) |
| + if (sync_manager()->ShouldEnableSessions() && host_->initialized()) { |
| + // Have to grab these before we register the sessions DTC. |
| + syncable::ModelTypeSet enabled_types; |
| + host_->frontend_->GetPreferredDataTypes(&enabled_types); |
| + syncable::ModelTypeSet registered_types; |
| + host_->frontend_->GetRegisteredDataTypes(®istered_types); |
| + |
| + // Received notice to enable tab (sessions) sync. Check if sessions are |
| + // registered, and if not register a new datatype controller. |
| + if (registered_types.count(syncable::SESSIONS) == 0) { |
|
tim (not reviewing)
2011/08/22 15:42:08
Something about this is circuitous. First, 'Get'i
Nicolas Zea
2011/08/22 22:50:15
Done.
|
| + ProfileSyncService* service = profile_->GetProfileSyncService(); |
| + ProfileSyncFactory* factory = host_->profile_sync_factory_; |
| + host_->frontend_->RegisterDataTypeController( |
| + new SessionDataTypeController(factory, profile_, service)); |
| + |
| + // Check if the user has "Keep Everything Synced" enabled. If so, we want |
| + // to turn on sessions if it's not already on. Otherwise we leave it off. |
| + // Note: if sessions are already registered, we don't turn it on. This |
| + // covers the case where we're already in the process of reconfiguring |
| + // to turn sessions on. |
| + if (profile_->GetPrefs()->GetBoolean(prefs::kKeepEverythingSynced) && |
| + enabled_types.count(syncable::SESSIONS) == 0){ |
| + // Enable the about:flags switch for sessions so we don't have to always |
| + // perform this reconfiguration. Once we set this, sessions will remain |
| + // registered, so we will no longer go down this code path. |
| + about_flags::SetExperimentEnabled(g_browser_process->local_state(), |
| + "sync-sessions", |
| + true); |
| + profile_->GetPrefs()->SetBoolean(prefs::kSyncSessions, true); |
| + to_migrate.insert(syncable::SESSIONS); |
| + } |
| + } |
| + } |
| + |
| + // We can only start migration if we have finished initialization. Any |
| + // datatypes that need migration currently will still require it after we |
| + // finish initializing. |
| + if (!to_migrate.empty() && host_->initialized()) |
| host_->frontend_->OnMigrationNeededForTypes(to_migrate); |
| // If we are waiting for a configuration change, check here to see |