diff options
author | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-21 19:37:06 +0000 |
---|---|---|
committer | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-21 19:37:06 +0000 |
commit | a9f56629c59ad46837dc2b83444ac4578280ffa8 (patch) | |
tree | d27d41c5327cc38ab90094614f97afee9b892460 | |
parent | 72ca2f71ab6843b124383ab7b81f4da4bd702c03 (diff) | |
download | chromium_src-a9f56629c59ad46837dc2b83444ac4578280ffa8.zip chromium_src-a9f56629c59ad46837dc2b83444ac4578280ffa8.tar.gz chromium_src-a9f56629c59ad46837dc2b83444ac4578280ffa8.tar.bz2 |
sync: Add --enable-sync-sessions-v2 and necessary plumbing to use SessionsSyncManager.
Not a fully working solution as SSM doesn't listen to session changes after the
initial association, but does work across restarts.
Adds OpenTabsUIDelegate to a) reduce SessionModelAssociator proliferation and b)
allow swapping in a SessionsSyncManager if the command line flag is passed.
The changes in non sync/ files are basically s/SessionModelAssociator/OpenTabsUIDelegate. There are a few places I didn't make that change yet (such as OnSyncCycleComplete in ProfileSyncService), which I'll have to do in a follow up as SSM supports more of the bells-and-whistles in session sync.
BUG=98892
R=pkasting@chromium.org, rlarocque@chromium.org, yfriedman@chromium.org
TBR=tburkard@chromium.org, asargent@chromium.org, yfriedman@chromium.org, dbeam@chromium.org, pkasting@chromium.org
for chrome/browser/prerender
for chrome/browser/extensions/api
for chrome/browser/android and chrome/browser/ui/webui/ntp/android
for chrome/browser/ui/webui/ntp
for remainder of chrome/browser/ui
Review URL: https://codereview.chromium.org/74653002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236572 0039d316-1c4b-4281-b951-d872f2087c98
28 files changed, 486 insertions, 199 deletions
diff --git a/chrome/browser/android/favicon_helper.cc b/chrome/browser/android/favicon_helper.cc index 2413dde..6fd41c1 100644 --- a/chrome/browser/android/favicon_helper.cc +++ b/chrome/browser/android/favicon_helper.cc @@ -16,8 +16,7 @@ #include "chrome/browser/favicon/favicon_service_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_android.h" -#include "chrome/browser/sync/glue/session_model_associator.h" -#include "chrome/browser/sync/glue/session_model_associator.h" +#include "chrome/browser/sync/open_tabs_ui_delegate.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h" @@ -123,11 +122,11 @@ ScopedJavaLocalRef<jobject> FaviconHelper::GetSyncedFaviconImageForURL( DCHECK(sync_service); scoped_refptr<base::RefCountedMemory> favicon_png; - browser_sync::SessionModelAssociator* associator = - sync_service->GetSessionModelAssociator(); - DCHECK(associator); + browser_sync::OpenTabsUIDelegate* open_tabs = + sync_service->GetOpenTabsUIDelegate(); + DCHECK(open_tabs); - if (!associator->GetSyncedFaviconForPageURL(page_url, &favicon_png)) + if (!open_tabs->GetSyncedFaviconForPageURL(page_url, &favicon_png)) return ScopedJavaLocalRef<jobject>(); // Convert favicon_image_result to java objects. diff --git a/chrome/browser/android/foreign_session_helper.cc b/chrome/browser/android/foreign_session_helper.cc index cb634c3..13f4451 100644 --- a/chrome/browser/android/foreign_session_helper.cc +++ b/chrome/browser/android/foreign_session_helper.cc @@ -13,7 +13,7 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/profiles/profile_android.h" #include "chrome/browser/sessions/session_restore.h" -#include "chrome/browser/sync/glue/session_model_associator.h" +#include "chrome/browser/sync/open_tabs_ui_delegate.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/ui/android/tab_model/tab_model.h" @@ -30,20 +30,20 @@ using base::android::AttachCurrentThread; using base::android::ConvertUTF16ToJavaString; using base::android::ConvertUTF8ToJavaString; using base::android::ConvertJavaStringToUTF8; -using browser_sync::SessionModelAssociator; +using browser_sync::OpenTabsUIDelegate; using browser_sync::SyncedSession; namespace { -SessionModelAssociator* GetSessionModelAssociator(Profile* profile) { +OpenTabsUIDelegate* GetOpenTabsUIDelegate(Profile* profile) { ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> GetForProfile(profile); - // Only return the associator if it exists and it is done syncing sessions. + // Only return the delegate if it exists and it is done syncing sessions. if (!service || !service->ShouldPushChanges()) return NULL; - return service->GetSessionModelAssociator(); + return service->GetOpenTabsUIDelegate(); } bool ShouldSkipTab(const SessionTab& session_tab) { @@ -200,12 +200,12 @@ void ForeignSessionHelper::Observe( jboolean ForeignSessionHelper::GetForeignSessions(JNIEnv* env, jobject obj, jobject result) { - SessionModelAssociator* associator = GetSessionModelAssociator(profile_); - if (!associator) + OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(profile_); + if (!open_tabs) return false; std::vector<const browser_sync::SyncedSession*> sessions; - if (!associator->GetAllForeignSessions(&sessions)) + if (!open_tabs->GetAllForeignSessions(&sessions)) return false; // Use a pref to keep track of sessions that were collapsed by the user. @@ -253,17 +253,17 @@ jboolean ForeignSessionHelper::OpenForeignSessionTab(JNIEnv* env, jstring session_tag, jint session_tab_id, jint j_disposition) { - SessionModelAssociator* associator = GetSessionModelAssociator(profile_); - if (!associator) { - LOG(ERROR) << "Null SessionModelAssociator returned."; + OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(profile_); + if (!open_tabs) { + LOG(ERROR) << "Null OpenTabsUIDelegate returned."; return false; } const SessionTab* session_tab; - if (!associator->GetForeignTab(ConvertJavaStringToUTF8(env, session_tag), - session_tab_id, - &session_tab)) { + if (!open_tabs->GetForeignTab(ConvertJavaStringToUTF8(env, session_tag), + session_tab_id, + &session_tab)) { LOG(ERROR) << "Failed to load foreign tab."; return false; } @@ -291,9 +291,9 @@ jboolean ForeignSessionHelper::OpenForeignSessionTab(JNIEnv* env, void ForeignSessionHelper::DeleteForeignSession(JNIEnv* env, jobject obj, jstring session_tag) { - SessionModelAssociator* associator = GetSessionModelAssociator(profile_); - if (associator) - associator->DeleteForeignSession(ConvertJavaStringToUTF8(env, session_tag)); + OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(profile_); + if (open_tabs) + open_tabs->DeleteForeignSession(ConvertJavaStringToUTF8(env, session_tag)); } // static diff --git a/chrome/browser/extensions/api/sessions/sessions_api.cc b/chrome/browser/extensions/api/sessions/sessions_api.cc index cf0a759..96094d7 100644 --- a/chrome/browser/extensions/api/sessions/sessions_api.cc +++ b/chrome/browser/extensions/api/sessions/sessions_api.cc @@ -25,8 +25,8 @@ #include "chrome/browser/sessions/session_restore.h" #include "chrome/browser/sessions/tab_restore_service_delegate.h" #include "chrome/browser/sessions/tab_restore_service_factory.h" -#include "chrome/browser/sync/glue/session_model_associator.h" #include "chrome/browser/sync/glue/synced_session.h" +#include "chrome/browser/sync/open_tabs_ui_delegate.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/ui/browser.h" @@ -359,10 +359,10 @@ bool SessionsGetDevicesFunction::RunImpl() { return true; } - browser_sync::SessionModelAssociator* associator = - service->GetSessionModelAssociator(); + browser_sync::OpenTabsUIDelegate* open_tabs = + service->GetOpenTabsUIDelegate(); std::vector<const browser_sync::SyncedSession*> sessions; - if (!(associator && associator->GetAllForeignSessions(&sessions))) { + if (!(open_tabs && open_tabs->GetAllForeignSessions(&sessions))) { results_ = GetDevices::Results::Create( std::vector<linked_ptr<api::sessions::Device> >()); return true; @@ -504,17 +504,17 @@ bool SessionsRestoreFunction::RestoreForeignSession(const SessionId& session_id, SetError(kSessionSyncError); return false; } - browser_sync::SessionModelAssociator* associator = - service->GetSessionModelAssociator(); - if (!associator) { + browser_sync::OpenTabsUIDelegate* open_tabs = + service->GetOpenTabsUIDelegate(); + if (!open_tabs) { SetError(kSessionSyncError); return false; } const SessionTab* tab = NULL; - if (associator->GetForeignTab(session_id.session_tag(), - session_id.id(), - &tab)) { + if (open_tabs->GetForeignTab(session_id.session_tag(), + session_id.id(), + &tab)) { TabStripModel* tab_strip = browser->tab_strip_model(); content::WebContents* contents = tab_strip->GetActiveWebContents(); @@ -527,7 +527,7 @@ bool SessionsRestoreFunction::RestoreForeignSession(const SessionId& session_id, // Restoring a full window. std::vector<const SessionWindow*> windows; - if (!associator->GetForeignSession(session_id.session_tag(), &windows)) { + if (!open_tabs->GetForeignSession(session_id.session_tag(), &windows)) { SetInvalidIdError(session_id.ToString()); return false; } diff --git a/chrome/browser/extensions/api/sessions/sessions_apitest.cc b/chrome/browser/extensions/api/sessions/sessions_apitest.cc index 4643a4c..92326af 100644 --- a/chrome/browser/extensions/api/sessions/sessions_apitest.cc +++ b/chrome/browser/extensions/api/sessions/sessions_apitest.cc @@ -12,6 +12,7 @@ #include "chrome/browser/extensions/extension_function_test_utils.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/sync/glue/session_model_associator.h" +#include "chrome/browser/sync/open_tabs_ui_delegate.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_mock.h" @@ -119,7 +120,7 @@ void ExtensionSessionsTest::CreateTestProfileSyncService() { preferred_types.Put(syncer::SESSIONS); GoogleServiceAuthError no_error(GoogleServiceAuthError::NONE); - ON_CALL(*service, GetSessionModelAssociator()).WillByDefault( + ON_CALL(*service, GetOpenTabsUIDelegate()).WillByDefault( testing::Return(associator_)); ON_CALL(*service, GetPreferredDataTypes()).WillByDefault( testing::Return(preferred_types)); diff --git a/chrome/browser/extensions/api/signed_in_devices/signed_in_devices_api.cc b/chrome/browser/extensions/api/signed_in_devices/signed_in_devices_api.cc index 9a8f8f2..2c678f4 100644 --- a/chrome/browser/extensions/api/signed_in_devices/signed_in_devices_api.cc +++ b/chrome/browser/extensions/api/signed_in_devices/signed_in_devices_api.cc @@ -92,7 +92,7 @@ scoped_ptr<DeviceInfo> GetLocalDeviceInfo(const std::string& extension_id, if (!pss) { return scoped_ptr<DeviceInfo>(); } - std::string guid = pss->GetLocalDeviceGUID(); + std::string guid = pss->GetLocalSyncCacheGUID(); scoped_ptr<DeviceInfo> device = GetDeviceInfoForClientId(guid, extension_id, profile); diff --git a/chrome/browser/prerender/prerender_field_trial.cc b/chrome/browser/prerender/prerender_field_trial.cc index 3813c5f..52e63b5 100644 --- a/chrome/browser/prerender/prerender_field_trial.cc +++ b/chrome/browser/prerender/prerender_field_trial.cc @@ -320,7 +320,7 @@ string GetLocalPredictorSpecValue(string spec_key) { bool IsUnencryptedSyncEnabled(Profile* profile) { ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> GetForProfile(profile); - return service && service->GetSessionModelAssociator() && + return service && service->GetOpenTabsUIDelegate() && !service->EncryptEverythingEnabled(); } diff --git a/chrome/browser/sync/glue/session_model_associator.h b/chrome/browser/sync/glue/session_model_associator.h index 54561ce..a4d500b 100644 --- a/chrome/browser/sync/glue/session_model_associator.h +++ b/chrome/browser/sync/glue/session_model_associator.h @@ -24,6 +24,7 @@ #include "chrome/browser/sync/glue/model_associator.h" #include "chrome/browser/sync/glue/synced_session_tracker.h" #include "chrome/browser/sync/glue/tab_node_pool.h" +#include "chrome/browser/sync/open_tabs_ui_delegate.h" #include "sync/internal_api/public/base/model_type.h" class PrefServiceSyncable; @@ -54,6 +55,7 @@ class SyncedWindowDelegate; // the sync sessions model. class SessionModelAssociator : public AssociatorInterface, + public OpenTabsUIDelegate, public base::SupportsWeakPtr<SessionModelAssociator>, public base::NonThreadSafe { public: @@ -147,24 +149,6 @@ class SessionModelAssociator // local machine. Used primarily for testing. bool GetLocalSession(const SyncedSession* * local_session); - // Builds a list of all foreign sessions. Caller does NOT own SyncedSession - // objects. - // Returns true if foreign sessions were found, false otherwise. - bool GetAllForeignSessions(std::vector<const SyncedSession*>* sessions); - - // Loads all windows for foreign session with session tag |tag|. Caller does - // NOT own SyncedSession objects. - // Returns true if the foreign session was found, false otherwise. - bool GetForeignSession(const std::string& tag, - std::vector<const SessionWindow*>* windows); - - // Looks up the foreign tab identified by |tab_id| and belonging to foreign - // session |tag|. Caller does NOT own the SessionTab object. - // Returns true if the foreign session and tab were found, false otherwise. - bool GetForeignTab(const std::string& tag, - const SessionID::id_type tab_id, - const SessionTab** tab); - // Triggers garbage collection of stale sessions (as defined by // |stale_session_threshold_days_|). This is called automatically every // time we start up (via AssociateModels). @@ -174,9 +158,6 @@ class SessionModelAssociator // stale. void SetStaleSessionThreshold(size_t stale_session_threshold_days); - // Delete a foreign session and all its sync data. - void DeleteForeignSession(const std::string& tag); - // Control which local tabs we're interested in syncing. // Ensures the profile matches sync's profile and that the tab has valid // entries. @@ -194,11 +175,19 @@ class SessionModelAssociator // first. void BlockUntilLocalChangeForTest(base::TimeDelta timeout); - // If a valid favicon for the page at |url| is found, fills |favicon_png| with - // the png-encoded image and returns true. Else, returns false. - bool GetSyncedFaviconForPageURL( + // OpenTabsUIDelegate implementation. + virtual bool GetSyncedFaviconForPageURL( const std::string& pageurl, - scoped_refptr<base::RefCountedMemory>* favicon_png) const; + scoped_refptr<base::RefCountedMemory>* favicon_png) const OVERRIDE; + virtual bool GetAllForeignSessions( + std::vector<const SyncedSession*>* sessions) OVERRIDE; + virtual bool GetForeignSession( + const std::string& tag, + std::vector<const SessionWindow*>* windows) OVERRIDE; + virtual bool GetForeignTab(const std::string& tag, + const SessionID::id_type tab_id, + const SessionTab** tab) OVERRIDE; + virtual void DeleteForeignSession(const std::string& tag) OVERRIDE; void SetCurrentMachineTagForTesting(const std::string& machine_tag) { current_machine_tag_ = machine_tag; diff --git a/chrome/browser/sync/open_tabs_ui_delegate.cc b/chrome/browser/sync/open_tabs_ui_delegate.cc new file mode 100644 index 0000000..fe07733 --- /dev/null +++ b/chrome/browser/sync/open_tabs_ui_delegate.cc @@ -0,0 +1,11 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/sync/open_tabs_ui_delegate.h" + +namespace browser_sync { + +OpenTabsUIDelegate::~OpenTabsUIDelegate() {} + +} // namespace browser_sync diff --git a/chrome/browser/sync/open_tabs_ui_delegate.h b/chrome/browser/sync/open_tabs_ui_delegate.h new file mode 100644 index 0000000..eb21c9d --- /dev/null +++ b/chrome/browser/sync/open_tabs_ui_delegate.h @@ -0,0 +1,56 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_SYNC_OPEN_TABS_UI_DELEGATE_H_ +#define CHROME_BROWSER_SYNC_OPEN_TABS_UI_DELEGATE_H_ + +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "base/memory/ref_counted.h" +#include "base/memory/ref_counted_memory.h" +#include "chrome/browser/sessions/session_id.h" +#include "chrome/browser/sessions/session_types.h" +#include "chrome/browser/sync/glue/synced_session.h" + +namespace browser_sync { + +class OpenTabsUIDelegate { + public: + // If a valid favicon for the page at |url| is found, fills |favicon_png| with + // the png-encoded image and returns true. Else, returns false. + virtual bool GetSyncedFaviconForPageURL( + const std::string& pageurl, + scoped_refptr<base::RefCountedMemory>* favicon_png) const = 0; + + // Builds a list of all foreign sessions. Caller does NOT own SyncedSession + // objects. + // Returns true if foreign sessions were found, false otherwise. + virtual bool GetAllForeignSessions( + std::vector<const SyncedSession*>* sessions) = 0; + + // Looks up the foreign tab identified by |tab_id| and belonging to foreign + // session |tag|. Caller does NOT own the SessionTab object. + // Returns true if the foreign session and tab were found, false otherwise. + virtual bool GetForeignTab(const std::string& tag, + const SessionID::id_type tab_id, + const SessionTab** tab) = 0; + + // Delete a foreign session and all its sync data. + virtual void DeleteForeignSession(const std::string& tag) = 0; + + // Loads all windows for foreign session with session tag |tag|. Caller does + // NOT own SyncedSession objects. + // Returns true if the foreign session was found, false otherwise. + virtual bool GetForeignSession( + const std::string& tag, + std::vector<const SessionWindow*>* windows) = 0; + protected: + virtual ~OpenTabsUIDelegate(); +}; + +} // namespace browser_sync + +#endif // CHROME_BROWSER_SYNC_OPEN_TABS_UI_DELEGATE_H_ diff --git a/chrome/browser/sync/profile_sync_components_factory_impl.cc b/chrome/browser/sync/profile_sync_components_factory_impl.cc index de90dd7..87a75e4 100644 --- a/chrome/browser/sync/profile_sync_components_factory_impl.cc +++ b/chrome/browser/sync/profile_sync_components_factory_impl.cc @@ -51,6 +51,7 @@ #include "chrome/browser/sync/profile_sync_components_factory_impl.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" +#include "chrome/browser/sync/sessions2/session_data_type_controller2.h" #include "chrome/browser/themes/theme_service.h" #include "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/themes/theme_syncable_service.h" @@ -100,6 +101,7 @@ using browser_sync::ProxyDataTypeController; using browser_sync::SearchEngineDataTypeController; using browser_sync::SessionChangeProcessor; using browser_sync::SessionDataTypeController; +using browser_sync::SessionDataTypeController2; using browser_sync::SessionModelAssociator; using browser_sync::SharedChangeProcessor; using browser_sync::SyncBackendHost; @@ -172,10 +174,15 @@ void ProfileSyncComponentsFactoryImpl::RegisterCommonDataTypes( // Session sync is enabled by default. Register unless explicitly disabled. if (!command_line_->HasSwitch(switches::kDisableSyncTabs)) { - pss->RegisterDataTypeController( - new ProxyDataTypeController(syncer::PROXY_TABS)); - pss->RegisterDataTypeController( - new SessionDataTypeController(this, profile_, pss)); + pss->RegisterDataTypeController( + new ProxyDataTypeController(syncer::PROXY_TABS)); + if (!command_line_->HasSwitch(switches::kEnableSyncSessionsV2)) { + pss->RegisterDataTypeController( + new SessionDataTypeController(this, profile_, pss)); + } else { + pss->RegisterDataTypeController( + new SessionDataTypeController2(this, profile_, pss)); + } } // Favicon sync is enabled by default. Register unless explicitly disabled. @@ -397,12 +404,11 @@ base::WeakPtr<syncer::SyncableService> ProfileSyncComponentsFactoryImpl:: #endif case syncer::FAVICON_IMAGES: case syncer::FAVICON_TRACKING: { - browser_sync::SessionModelAssociator* model_associator = + browser_sync::FaviconCache* favicons = ProfileSyncServiceFactory::GetForProfile(profile_)-> - GetSessionModelAssociator(); - if (!model_associator) - return base::WeakPtr<syncer::SyncableService>(); - return model_associator->GetFaviconCache()->AsWeakPtr(); + GetFaviconCache(); + return favicons ? favicons->AsWeakPtr() + : base::WeakPtr<syncer::SyncableService>(); } #if defined(ENABLE_MANAGED_USERS) case syncer::MANAGED_USER_SETTINGS: @@ -415,12 +421,15 @@ base::WeakPtr<syncer::SyncableService> ProfileSyncComponentsFactoryImpl:: case syncer::ARTICLES: // TODO(nyquist) Hook up real syncer::SyncableService API here. return base::WeakPtr<syncer::SyncableService>(); + case syncer::SESSIONS: + DCHECK(command_line_->HasSwitch(switches::kEnableSyncSessionsV2)); + return ProfileSyncServiceFactory::GetForProfile(profile_)-> + GetSessionsSyncableService()->AsWeakPtr(); default: // The following datatypes still need to be transitioned to the // syncer::SyncableService API: // Bookmarks // Passwords - // Sessions // Typed URLs NOTREACHED(); return base::WeakPtr<syncer::SyncableService>(); diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index 710fb75..5173ed7 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -40,6 +40,7 @@ #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" #include "chrome/browser/sync/glue/data_type_controller.h" #include "chrome/browser/sync/glue/device_info.h" +#include "chrome/browser/sync/glue/favicon_cache.h" #include "chrome/browser/sync/glue/session_data_type_controller.h" #include "chrome/browser/sync/glue/session_model_associator.h" #include "chrome/browser/sync/glue/sync_backend_host.h" @@ -47,6 +48,7 @@ #include "chrome/browser/sync/glue/synced_device_tracker.h" #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" #include "chrome/browser/sync/profile_sync_components_factory_impl.h" +#include "chrome/browser/sync/sessions2/sessions_sync_manager.h" #include "chrome/browser/sync/sync_global_error.h" #include "chrome/browser/sync/user_selectable_sync_type.h" #include "chrome/browser/ui/browser.h" @@ -191,6 +193,11 @@ ProfileSyncService::ProfileSyncService( channel == chrome::VersionInfo::CHANNEL_BETA) { sync_service_url_ = GURL(kSyncServerUrl); } + + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableSyncSessionsV2)) { + sessions_sync_manager_.reset(new SessionsSyncManager(profile, this)); + } } ProfileSyncService::~ProfileSyncService() { @@ -349,18 +356,52 @@ void ProfileSyncService::RegisterDataTypeController( } browser_sync::SessionModelAssociator* - ProfileSyncService::GetSessionModelAssociator() { + ProfileSyncService::GetSessionModelAssociatorDeprecated() { if (data_type_controllers_.find(syncer::SESSIONS) == data_type_controllers_.end() || data_type_controllers_.find(syncer::SESSIONS)->second->state() != DataTypeController::RUNNING) { return NULL; } + + // If we're using sessions V2, there's no model associator. + if (sessions_sync_manager_.get()) + return NULL; + return static_cast<browser_sync::SessionDataTypeController*>( data_type_controllers_.find( syncer::SESSIONS)->second.get())->GetModelAssociator(); } +browser_sync::OpenTabsUIDelegate* ProfileSyncService::GetOpenTabsUIDelegate() { + if (data_type_controllers_.find(syncer::SESSIONS) == + data_type_controllers_.end() || + data_type_controllers_.find(syncer::SESSIONS)->second->state() != + DataTypeController::RUNNING) { + return NULL; + } + + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableSyncSessionsV2)) { + return sessions_sync_manager_.get(); + } else { + return GetSessionModelAssociatorDeprecated(); + } +} + +browser_sync::FaviconCache* ProfileSyncService::GetFaviconCache() { + // TODO(tim): Clean this up (or remove) once there's only one implementation. + // Bug 98892. + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableSyncSessionsV2)) { + return sessions_sync_manager_->GetFaviconCache(); + } else if (GetSessionModelAssociatorDeprecated()) { + return GetSessionModelAssociatorDeprecated()->GetFaviconCache(); + } else { + return NULL; + } +} + scoped_ptr<browser_sync::DeviceInfo> ProfileSyncService::GetLocalDeviceInfo() const { if (backend_) { @@ -397,7 +438,7 @@ ScopedVector<browser_sync::DeviceInfo> return devices.Pass(); } -std::string ProfileSyncService::GetLocalDeviceGUID() const { +std::string ProfileSyncService::GetLocalSyncCacheGUID() const { if (backend_) { browser_sync::SyncedDeviceTracker* device_tracker = backend_->GetSyncedDeviceTracker(); @@ -1020,7 +1061,7 @@ void ProfileSyncService::OnBackendInitialized( void ProfileSyncService::OnSyncCycleCompleted() { UpdateLastSyncedTime(); - if (GetSessionModelAssociator()) { + if (GetSessionModelAssociatorDeprecated()) { // Trigger garbage collection of old sessions now that we've downloaded // any new session data. TODO(zea): Have this be a notification the session // model associator listens too. Also consider somehow plumbing the current @@ -1028,7 +1069,7 @@ void ProfileSyncService::OnSyncCycleCompleted() { // rely on the local clock, which may be off significantly. base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions, - GetSessionModelAssociator()->AsWeakPtr())); + GetSessionModelAssociatorDeprecated()->AsWeakPtr())); } DVLOG(2) << "Notifying observers sync cycle completed"; NotifySyncCycleCompleted(); @@ -2197,6 +2238,10 @@ WeakHandle<syncer::JsEventHandler> ProfileSyncService::GetJsEventHandler() { return MakeWeakHandle(sync_js_controller_.AsWeakPtr()); } +syncer::SyncableService* ProfileSyncService::GetSessionsSyncableService() { + return sessions_sync_manager_.get(); +} + ProfileSyncService::SyncTokenStatus::SyncTokenStatus() : connection_status(syncer::CONNECTION_NOT_ATTEMPTED), last_get_token_error(GoogleServiceAuthError::AuthErrorNone()) {} diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h index 88e9601..c9bfd84 100644 --- a/chrome/browser/sync/profile_sync_service.h +++ b/chrome/browser/sync/profile_sync_service.h @@ -31,6 +31,7 @@ #include "chrome/browser/sync/glue/synced_device_tracker.h" #include "chrome/browser/sync/profile_sync_service_base.h" #include "chrome/browser/sync/profile_sync_service_observer.h" +#include "chrome/browser/sync/sessions2/sessions_sync_manager.h" #include "chrome/browser/sync/sync_prefs.h" #include "components/browser_context_keyed_service/browser_context_keyed_service.h" #include "content/public/browser/notification_observer.h" @@ -58,7 +59,9 @@ class BackendMigrator; class ChangeProcessor; class DataTypeManager; class DeviceInfo; +class FaviconCache; class JsController; +class OpenTabsUIDelegate; class SessionModelAssociator; namespace sessions { @@ -76,6 +79,8 @@ namespace sync_pb { class EncryptedData; } // namespace sync_pb +using browser_sync::SessionsSyncManager; + // ProfileSyncService is the layer between browser subsystems like bookmarks, // and the sync backend. Each subsystem is logically thought of as being // a sync datatype. @@ -159,16 +164,18 @@ class EncryptedData; // tell the sync engine that setup is completed and it can begin downloading // data from the sync server. // -class ProfileSyncService : public ProfileSyncServiceBase, - public browser_sync::SyncFrontend, - public browser_sync::SyncPrefObserver, - public browser_sync::DataTypeManagerObserver, - public syncer::UnrecoverableErrorHandler, - public content::NotificationObserver, - public BrowserContextKeyedService, - public browser_sync::DataTypeEncryptionHandler, - public OAuth2TokenService::Consumer, - public OAuth2TokenService::Observer { +class ProfileSyncService + : public ProfileSyncServiceBase, + public browser_sync::SyncFrontend, + public browser_sync::SyncPrefObserver, + public browser_sync::DataTypeManagerObserver, + public syncer::UnrecoverableErrorHandler, + public content::NotificationObserver, + public BrowserContextKeyedService, + public browser_sync::DataTypeEncryptionHandler, + public OAuth2TokenService::Consumer, + public OAuth2TokenService::Observer, + public SessionsSyncManager::SyncInternalApiDelegate { public: typedef browser_sync::SyncBackendHost::Status Status; @@ -299,13 +306,34 @@ class ProfileSyncService : public ProfileSyncServiceBase, // Returns the session model associator associated with this type, but only if // the associator is running. If it is doing anything else, it will return // null. - // TODO(zea): Figure out a better way to expose this to the UI elements that - // need it. - virtual browser_sync::SessionModelAssociator* GetSessionModelAssociator(); + // + // *** DONT USE THIS ANYMORE! *** + // If you think you want to use this, think again! Can you use + // GetOpenTabsUIDelegate instead? + // TODO(tim): Remove this method. + virtual browser_sync::SessionModelAssociator* + GetSessionModelAssociatorDeprecated(); + + // Return the active OpenTabsUIDelegate. If sessions is not enabled or not + // currently syncing, returns NULL. + virtual browser_sync::OpenTabsUIDelegate* GetOpenTabsUIDelegate(); + // Returns the SyncableService for syncer::SESSIONS. + virtual syncer::SyncableService* GetSessionsSyncableService(); + + // SyncInternalApiDelegate implementation. + // // Returns sync's representation of the local device info. // Return value is an empty scoped_ptr if the device info is unavailable. - virtual scoped_ptr<browser_sync::DeviceInfo> GetLocalDeviceInfo() const; + virtual scoped_ptr<browser_sync::DeviceInfo> GetLocalDeviceInfo() + const OVERRIDE; + + // Gets the guid for the local device. Can be used by other layers to + // to distinguish sync data that belongs to the local device vs data + // that belongs to remote devices. Returns empty string if sync is not + // initialized. The GUID is not persistent across Chrome signout/signin. + // If you sign out of Chrome and sign in, a new GUID is generated. + virtual std::string GetLocalSyncCacheGUID() const OVERRIDE; // Returns sync's representation of the device info for a client identified // by |client_id|. Return value is an empty scoped ptr if the device info @@ -317,12 +345,6 @@ class ProfileSyncService : public ProfileSyncServiceBase, // with this profile. virtual ScopedVector<browser_sync::DeviceInfo> GetAllSignedInDevices() const; - // Gets the partnership guid for the local device. Can be used by other - // layers to distinguish sync data that belongs to the local device vs - // data that belong to remote devices. Returns null if sync is not - // initialized. - virtual std::string GetLocalDeviceGUID() const; - // Notifies the observer of any device info changes. virtual void AddObserverForDeviceInfoChange( browser_sync::SyncedDeviceTracker::Observer* observer); @@ -675,6 +697,8 @@ class ProfileSyncService : public ProfileSyncServiceBase, // Return sync token status. SyncTokenStatus GetSyncTokenStatus() const; + browser_sync::FaviconCache* GetFaviconCache(); + protected: // Used by test classes that derive from ProfileSyncService. virtual browser_sync::SyncBackendHost* GetBackendForTest(); @@ -1014,6 +1038,8 @@ class ProfileSyncService : public ProfileSyncServiceBase, GoogleServiceAuthError last_get_token_error_; base::Time next_token_request_time_; + scoped_ptr<SessionsSyncManager> sessions_sync_manager_; + DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); }; diff --git a/chrome/browser/sync/profile_sync_service_mock.h b/chrome/browser/sync/profile_sync_service_mock.h index 8308272..43ea783 100644 --- a/chrome/browser/sync/profile_sync_service_mock.h +++ b/chrome/browser/sync/profile_sync_service_mock.h @@ -96,8 +96,8 @@ class ProfileSyncServiceMock : public ProfileSyncService { const syncer::SyncProtocolError&)); MOCK_METHOD1(SetSetupInProgress, void(bool)); - MOCK_METHOD0(GetSessionModelAssociator, - browser_sync::SessionModelAssociator*()); + MOCK_METHOD0(GetOpenTabsUIDelegate, + browser_sync::OpenTabsUIDelegate*()); MOCK_CONST_METHOD0(GetAllSignedInDevicesMock, std::vector<browser_sync::DeviceInfo*>* ()); // This is to get around the fact that GMOCK does not handle Scoped*. diff --git a/chrome/browser/sync/sessions2/session_data_type_controller2.cc b/chrome/browser/sync/sessions2/session_data_type_controller2.cc new file mode 100644 index 0000000..0add2e7 --- /dev/null +++ b/chrome/browser/sync/sessions2/session_data_type_controller2.cc @@ -0,0 +1,56 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/sync/sessions2/session_data_type_controller2.h" + +#include "chrome/browser/chrome_notification_types.h" +#include "chrome/browser/sync/glue/synced_window_delegate.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/notification_details.h" +#include "content/public/browser/notification_service.h" +#include "content/public/browser/notification_source.h" + +namespace browser_sync { + +SessionDataTypeController2::SessionDataTypeController2( + ProfileSyncComponentsFactory* profile_sync_factory, + Profile* profile, + ProfileSyncService* sync_service) + : UIDataTypeController(syncer::SESSIONS, + profile_sync_factory, + profile, + sync_service) { +} + +SessionDataTypeController2::~SessionDataTypeController2() {} + +bool SessionDataTypeController2::StartModels() { + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + std::set<browser_sync::SyncedWindowDelegate*> window = + browser_sync::SyncedWindowDelegate::GetSyncedWindowDelegates(); + for (std::set<browser_sync::SyncedWindowDelegate*>::const_iterator i = + window.begin(); i != window.end(); ++i) { + if ((*i)->IsSessionRestoreInProgress()) { + notification_registrar_.Add( + this, + chrome::NOTIFICATION_SESSION_RESTORE_COMPLETE, + content::Source<Profile>(profile_)); + return false; + } + } + return true; +} + +void SessionDataTypeController2::Observe( + int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) { + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + DCHECK_EQ(chrome::NOTIFICATION_SESSION_RESTORE_COMPLETE, type); + DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); + notification_registrar_.RemoveAll(); + OnModelLoaded(); +} + +} // namespace browser_sync diff --git a/chrome/browser/sync/sessions2/session_data_type_controller2.h b/chrome/browser/sync/sessions2/session_data_type_controller2.h new file mode 100644 index 0000000..c58797b --- /dev/null +++ b/chrome/browser/sync/sessions2/session_data_type_controller2.h @@ -0,0 +1,40 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_SYNC_SESSIONS2_SESSION_DATA_TYPE_CONTROLLER2_H_ +#define CHROME_BROWSER_SYNC_SESSIONS2_SESSION_DATA_TYPE_CONTROLLER2_H_ + +#include "chrome/browser/sync/glue/ui_data_type_controller.h" +#include "content/public/browser/notification_observer.h" +#include "content/public/browser/notification_registrar.h" + +namespace browser_sync { + +// Overrides StartModels to avoid sync contention with sessions during +// a session restore operation at startup. +class SessionDataTypeController2 : public UIDataTypeController, + public content::NotificationObserver { + public: + SessionDataTypeController2(ProfileSyncComponentsFactory* factory, + Profile* profile, + ProfileSyncService* service); + + // NotificationObserver interface. + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) OVERRIDE; + + protected: + virtual ~SessionDataTypeController2(); + virtual bool StartModels() OVERRIDE; + + private: + content::NotificationRegistrar notification_registrar_; + DISALLOW_COPY_AND_ASSIGN(SessionDataTypeController2); +}; + +} // namespace browser_sync + +#endif // CHROME_BROWSER_SYNC_SESSIONS2_SESSION_DATA_TYPE_CONTROLLER2_H_ + diff --git a/chrome/browser/sync/sessions2/sessions_sync_manager.cc b/chrome/browser/sync/sessions2/sessions_sync_manager.cc index 0da9fd0..66ae4d3 100644 --- a/chrome/browser/sync/sessions2/sessions_sync_manager.cc +++ b/chrome/browser/sync/sessions2/sessions_sync_manager.cc @@ -8,6 +8,7 @@ #if !defined(OS_ANDROID) #include "chrome/browser/network_time/navigation_time_helper.h" #endif +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/glue/synced_tab_delegate.h" #include "chrome/browser/sync/glue/synced_window_delegate.h" #include "chrome/common/url_constants.h" @@ -38,13 +39,12 @@ static const int kMaxSyncNavigationCount = 6; SessionsSyncManager::SessionsSyncManager( Profile* profile, - scoped_ptr<SyncPrefs> sync_prefs, SyncInternalApiDelegate* delegate) : favicon_cache_(profile, kMaxSyncFavicons), + sync_prefs_(profile->GetPrefs()), profile_(profile), delegate_(delegate), local_session_header_node_id_(TabNodePool2::kInvalidTabNodeID) { - sync_prefs_ = sync_prefs.Pass(); } SessionsSyncManager::~SessionsSyncManager() { @@ -105,9 +105,10 @@ syncer::SyncMergeResult SessionsSyncManager::MergeDataAndStartSyncing( } #if defined(OS_ANDROID) - std::string sync_machine_tag(BuildMachineTag(delegate_->GetCacheGuid())); + std::string sync_machine_tag(BuildMachineTag( + delegate_->GetLocalSyncCacheGUID())); if (current_machine_tag_.compare(sync_machine_tag) != 0) - DeleteForeignSession(sync_machine_tag, &new_changes); + DeleteForeignSessionInternal(sync_machine_tag, &new_changes); #endif // Check if anything has changed on the local client side. @@ -346,8 +347,17 @@ bool SessionsSyncManager::ShouldSyncWindow( void SessionsSyncManager::ForwardRelevantFaviconUpdatesToFaviconCache( const std::set<GURL>& updated_favicon_page_urls) { - NOTIMPLEMENTED() << - "TODO(tim): SessionModelAssociator::FaviconsUpdated equivalent."; + // TODO(zea): consider a separate container for tabs with outstanding favicon + // loads so we don't have to iterate through all tabs comparing urls. + for (std::set<GURL>::const_iterator i = updated_favicon_page_urls.begin(); + i != updated_favicon_page_urls.end(); ++i) { + for (TabLinksMap::iterator tab_iter = local_tab_map_.begin(); + tab_iter != local_tab_map_.end(); + ++tab_iter) { + if (tab_iter->second->url() == *i) + favicon_cache_.OnPageFaviconUpdated(*i); + } + } } void SessionsSyncManager::StopSyncing(syncer::ModelType type) { @@ -551,14 +561,14 @@ void SessionsSyncManager::UpdateTrackerWithForeignSession( void SessionsSyncManager::InitializeCurrentMachineTag() { DCHECK(current_machine_tag_.empty()); std::string persisted_guid; - persisted_guid = sync_prefs_->GetSyncSessionsGUID(); + persisted_guid = sync_prefs_.GetSyncSessionsGUID(); if (!persisted_guid.empty()) { current_machine_tag_ = persisted_guid; DVLOG(1) << "Restoring persisted session sync guid: " << persisted_guid; } else { - current_machine_tag_ = BuildMachineTag(delegate_->GetCacheGuid()); + current_machine_tag_ = BuildMachineTag(delegate_->GetLocalSyncCacheGUID()); DVLOG(1) << "Creating session sync guid: " << current_machine_tag_; - sync_prefs_->SetSyncSessionsGUID(current_machine_tag_); + sync_prefs_.SetSyncSessionsGUID(current_machine_tag_); } local_tab_pool_.SetMachineTag(current_machine_tag_); @@ -653,7 +663,13 @@ bool SessionsSyncManager::GetSyncedFaviconForPageURL( return favicon_cache_.GetSyncedFaviconForPageURL(GURL(page_url), favicon_png); } -void SessionsSyncManager::DeleteForeignSession( +void SessionsSyncManager::DeleteForeignSession(const std::string& tag) { + syncer::SyncChangeList changes; + DeleteForeignSessionInternal(tag, &changes); + sync_processor_->ProcessSyncChanges(FROM_HERE, changes); +} + +void SessionsSyncManager::DeleteForeignSessionInternal( const std::string& tag, syncer::SyncChangeList* change_output) { if (tag == current_machine_tag()) { LOG(ERROR) << "Attempting to delete local session. This is not currently " @@ -722,6 +738,25 @@ GURL SessionsSyncManager::GetCurrentFaviconURL( GURL()); } +bool SessionsSyncManager::GetForeignSession( + const std::string& tag, + std::vector<const SessionWindow*>* windows) { + return session_tracker_.LookupSessionWindows(tag, windows); +} + +bool SessionsSyncManager::GetForeignTab( + const std::string& tag, + const SessionID::id_type tab_id, + const SessionTab** tab) { + const SessionTab* synced_tab = NULL; + bool success = session_tracker_.LookupSessionTab(tag, + tab_id, + &synced_tab); + if (success) + *tab = synced_tab; + return success; +} + void SessionsSyncManager::LocalTabDelegateToSpecifics( const SyncedTabDelegate& tab_delegate, sync_pb::SessionSpecifics* specifics) { @@ -833,4 +868,9 @@ void SessionsSyncManager::SetSessionTabFromDelegate( session_tab->session_storage_persistent_id.clear(); } + +FaviconCache* SessionsSyncManager::GetFaviconCache() { + return &favicon_cache_; +} + }; // namespace browser_sync diff --git a/chrome/browser/sync/sessions2/sessions_sync_manager.h b/chrome/browser/sync/sessions2/sessions_sync_manager.h index 22bb936..88bb884 100644 --- a/chrome/browser/sync/sessions2/sessions_sync_manager.h +++ b/chrome/browser/sync/sessions2/sessions_sync_manager.h @@ -20,6 +20,7 @@ #include "chrome/browser/sync/glue/favicon_cache.h" #include "chrome/browser/sync/glue/synced_session.h" #include "chrome/browser/sync/glue/synced_session_tracker.h" +#include "chrome/browser/sync/open_tabs_ui_delegate.h" #include "chrome/browser/sync/sessions2/tab_node_pool2.h" #include "chrome/browser/sync/sync_prefs.h" #include "sync/api/syncable_service.h" @@ -46,7 +47,8 @@ class SyncedWindowDelegate; // Contains all logic for associating the Chrome sessions model and // the sync sessions model. -class SessionsSyncManager : public syncer::SyncableService { +class SessionsSyncManager : public syncer::SyncableService, + public OpenTabsUIDelegate { public: // Isolates SessionsSyncManager from having to depend on sync internals. class SyncInternalApiDelegate { @@ -56,11 +58,10 @@ class SessionsSyncManager : public syncer::SyncableService { virtual scoped_ptr<DeviceInfo> GetLocalDeviceInfo() const = 0; // Used for creation of the machine tag for this local session. - virtual std::string GetCacheGuid() const = 0; + virtual std::string GetLocalSyncCacheGUID() const = 0; }; SessionsSyncManager(Profile* profile, - scoped_ptr<SyncPrefs> sync_prefs, SyncInternalApiDelegate* delegate); virtual ~SessionsSyncManager(); @@ -88,17 +89,6 @@ class SessionsSyncManager : public syncer::SyncableService { return current_machine_tag_; } - // Builds a list of all foreign sessions. Caller does NOT own SyncedSession - // objects. - // Returns true if foreign sessions were found, false otherwise. - bool GetAllForeignSessions(std::vector<const SyncedSession*>* sessions); - - // If a valid favicon for the page at |url| is found, fills |favicon_png| with - // the png-encoded image and returns true. Else, returns false. - bool GetSyncedFaviconForPageURL( - const std::string& page_url, - scoped_refptr<base::RefCountedMemory>* favicon_png) const; - // syncer::SyncableService implementation. virtual syncer::SyncMergeResult MergeDataAndStartSyncing( syncer::ModelType type, @@ -118,6 +108,22 @@ class SessionsSyncManager : public syncer::SyncableService { // Return the favicon url of the current tab, even if it's pending. static GURL GetCurrentFaviconURL(const SyncedTabDelegate& tab_delegate); + FaviconCache* GetFaviconCache(); + + // OpenTabsUIDelegate implementation. + virtual bool GetSyncedFaviconForPageURL( + const std::string& pageurl, + scoped_refptr<base::RefCountedMemory>* favicon_png) const OVERRIDE; + virtual bool GetAllForeignSessions( + std::vector<const SyncedSession*>* sessions) OVERRIDE; + virtual bool GetForeignSession( + const std::string& tag, + std::vector<const SessionWindow*>* windows) OVERRIDE; + virtual bool GetForeignTab(const std::string& tag, + const SessionID::id_type tab_id, + const SessionTab** tab) OVERRIDE; + virtual void DeleteForeignSession(const std::string& tag) OVERRIDE; + private: // Keep all the links to local tab data in one place. A tab_node_id and tab // must be passed at creation. The tab_node_id is not mutable, although @@ -200,8 +206,8 @@ class SessionsSyncManager : public syncer::SyncableService { // |change_output| *must* be provided as a link to the SyncChange pipeline // that exists in the caller's context. This function will append necessary // changes for processing later. - void DeleteForeignSession(const std::string& tag, - syncer::SyncChangeList* change_output); + void DeleteForeignSessionInternal(const std::string& tag, + syncer::SyncChangeList* change_output); // Used to populate a session header from the session specifics header // provided. @@ -283,7 +289,7 @@ class SessionsSyncManager : public syncer::SyncableService { // Pool of used/available sync nodes associated with local tabs. TabNodePool2 local_tab_pool_; - scoped_ptr<SyncPrefs> sync_prefs_; + SyncPrefs sync_prefs_; const Profile* const profile_; diff --git a/chrome/browser/sync/sessions2/sessions_sync_manager_unittest.cc b/chrome/browser/sync/sessions2/sessions_sync_manager_unittest.cc index 6183e67..3f21000 100644 --- a/chrome/browser/sync/sessions2/sessions_sync_manager_unittest.cc +++ b/chrome/browser/sync/sessions2/sessions_sync_manager_unittest.cc @@ -102,10 +102,7 @@ class SessionsSyncManagerTest virtual void SetUp() OVERRIDE { BrowserWithTestWindowTest::SetUp(); - manager_.reset(new SessionsSyncManager( - profile(), - scoped_ptr<SyncPrefs>(new SyncPrefs(profile()->GetPrefs())), - this)); + manager_.reset(new SessionsSyncManager(profile(), this)); } virtual void TearDown() OVERRIDE { @@ -116,14 +113,14 @@ class SessionsSyncManagerTest virtual scoped_ptr<DeviceInfo> GetLocalDeviceInfo() const OVERRIDE { return scoped_ptr<DeviceInfo>( - new DeviceInfo(GetCacheGuid(), + new DeviceInfo(GetLocalSyncCacheGUID(), "Wayne Gretzky's Hacking Box", "Chromium 10k", "Chrome 10k", sync_pb::SyncEnums_DeviceType_TYPE_LINUX)); } - virtual std::string GetCacheGuid() const OVERRIDE { + virtual std::string GetLocalSyncCacheGUID() const OVERRIDE { return "cache_guid"; } @@ -522,10 +519,7 @@ TEST_F(SessionsSyncManagerTest, MergeLocalSessionNoTabs) { SyncData d(SyncData::CreateRemoteData(1, data.GetSpecifics(), base::Time())); syncer::SyncDataList in(&d, &d + 1); out.clear(); - SessionsSyncManager manager2( - profile(), - scoped_ptr<SyncPrefs>(new SyncPrefs(profile()->GetPrefs())), - this); + SessionsSyncManager manager2(profile(), this); syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( syncer::SESSIONS, in, scoped_ptr<syncer::SyncChangeProcessor>( @@ -754,7 +748,7 @@ TEST_F(SessionsSyncManagerTest, DeleteForeignSession) { std::vector<const SyncedSession*> foreign_sessions; ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); - manager()->DeleteForeignSession(tag, &changes); + manager()->DeleteForeignSessionInternal(tag, &changes); ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); EXPECT_TRUE(changes.empty()); @@ -775,7 +769,7 @@ TEST_F(SessionsSyncManagerTest, DeleteForeignSession) { ASSERT_EQ(1U, foreign_sessions.size()); // Now delete the foreign session. - manager()->DeleteForeignSession(tag, &changes); + manager()->DeleteForeignSessionInternal(tag, &changes); EXPECT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); EXPECT_EQ(5U, changes.size()); @@ -918,10 +912,7 @@ TEST_F(SessionsSyncManagerTest, SaveUnassociatedNodesForReassociation) { SyncData d(SyncData::CreateRemoteData(1, entity, base::Time())); syncer::SyncDataList in(&d, &d + 1); changes.clear(); - SessionsSyncManager manager2( - profile(), - scoped_ptr<SyncPrefs>(new SyncPrefs(profile()->GetPrefs())), - this); + SessionsSyncManager manager2(profile(), this); syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( syncer::SESSIONS, in, scoped_ptr<syncer::SyncChangeProcessor>( diff --git a/chrome/browser/sync/test/integration/sessions_helper.cc b/chrome/browser/sync/test/integration/sessions_helper.cc index fa90917..c315a69 100644 --- a/chrome/browser/sync/test/integration/sessions_helper.cc +++ b/chrome/browser/sync/test/integration/sessions_helper.cc @@ -51,8 +51,8 @@ void ScopedWindowMap::Reset(SessionWindowMap* windows) { bool GetLocalSession(int index, const browser_sync::SyncedSession** session) { return ProfileSyncServiceFactory::GetInstance()->GetForProfile( - test()->GetProfile(index))->GetSessionModelAssociator()->GetLocalSession( - session); + test()->GetProfile(index))->GetSessionModelAssociatorDeprecated()-> + GetLocalSession(session); } bool ModelAssociatorHasTabWithUrl(int index, const GURL& url) { @@ -136,7 +136,7 @@ bool WaitForTabsToLoad(int index, const std::vector<GURL>& urls) { } if (!found) { ProfileSyncServiceFactory::GetInstance()->GetForProfile( - test()->GetProfile(index))->GetSessionModelAssociator()-> + test()->GetProfile(index))->GetSessionModelAssociatorDeprecated()-> BlockUntilLocalChangeForTest(TestTimeouts::action_max_timeout()); content::RunMessageLoop(); } @@ -200,16 +200,20 @@ int GetNumForeignSessions(int index) { SyncedSessionVector sessions; if (!ProfileSyncServiceFactory::GetInstance()->GetForProfile( test()->GetProfile(index))-> - GetSessionModelAssociator()->GetAllForeignSessions(&sessions)) + GetSessionModelAssociatorDeprecated()->GetAllForeignSessions( + &sessions)) { return 0; + } return sessions.size(); } bool GetSessionData(int index, SyncedSessionVector* sessions) { if (!ProfileSyncServiceFactory::GetInstance()->GetForProfile( test()->GetProfile(index))-> - GetSessionModelAssociator()->GetAllForeignSessions(sessions)) + GetSessionModelAssociatorDeprecated()->GetAllForeignSessions( + sessions)) { return false; + } SortSyncedSessions(sessions); return true; } @@ -313,7 +317,7 @@ bool CheckForeignSessionsAgainst( void DeleteForeignSession(int index, std::string session_tag) { ProfileSyncServiceFactory::GetInstance()->GetForProfile( test()->GetProfile(index))-> - GetSessionModelAssociator()->DeleteForeignSession(session_tag); + GetSessionModelAssociatorDeprecated()->DeleteForeignSession(session_tag); } } // namespace sessions_helper diff --git a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc index 4049cc4..702275f 100644 --- a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc +++ b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc @@ -17,8 +17,8 @@ #include "chrome/browser/sessions/tab_restore_service.h" #include "chrome/browser/sessions/tab_restore_service_delegate.h" #include "chrome/browser/sessions/tab_restore_service_factory.h" -#include "chrome/browser/sync/glue/session_model_associator.h" #include "chrome/browser/sync/glue/synced_session.h" +#include "chrome/browser/sync/open_tabs_ui_delegate.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/ui/browser.h" @@ -167,10 +167,10 @@ const int RecentTabsSubMenuModel::kDisabledRecentlyClosedHeaderCommandId = 1121; RecentTabsSubMenuModel::RecentTabsSubMenuModel( ui::AcceleratorProvider* accelerator_provider, Browser* browser, - browser_sync::SessionModelAssociator* associator) + browser_sync::OpenTabsUIDelegate* open_tabs_delegate) : ui::SimpleMenuModel(this), browser_(browser), - associator_(associator), + open_tabs_delegate_(open_tabs_delegate), last_local_model_index_(-1), default_favicon_(ResourceBundle::GetSharedInstance(). GetNativeImageNamed(IDR_DEFAULT_FAVICON)), @@ -285,11 +285,11 @@ void RecentTabsSubMenuModel::ExecuteCommand(int command_id, int event_flags) { browser_->host_desktop_type(), disposition); } } else { // Restore tab of session from other devices. - browser_sync::SessionModelAssociator* associator = GetModelAssociator(); - if (!associator) + browser_sync::OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(); + if (!open_tabs) return; const SessionTab* tab; - if (!associator->GetForeignTab(item.session_tag, item.tab_id, &tab)) + if (!open_tabs->GetForeignTab(item.session_tag, item.tab_id, &tab)) return; if (tab->navigations.empty()) return; @@ -422,9 +422,9 @@ void RecentTabsSubMenuModel::BuildTabsFromOtherDevices() { // a menu item, because they are always only built once (i.e. invoked from // Constructor()) and don't change after that. - browser_sync::SessionModelAssociator* associator = GetModelAssociator(); + browser_sync::OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(); std::vector<const browser_sync::SyncedSession*> sessions; - if (!associator || !associator->GetAllForeignSessions(&sessions)) { + if (!open_tabs || !open_tabs->GetAllForeignSessions(&sessions)) { AddSeparator(ui::NORMAL_SEPARATOR); AddItemWithStringId(IDC_RECENT_TABS_NO_DEVICE_TABS, IDS_RECENT_TABS_NO_DEVICE_TABS); @@ -443,7 +443,7 @@ void RecentTabsSubMenuModel::BuildTabsFromOtherDevices() { // Get windows of session. std::vector<const SessionWindow*> windows; - if (!associator->GetForeignSession(session_tag, &windows) || + if (!open_tabs->GetForeignSession(session_tag, &windows) || windows.empty()) { continue; } @@ -588,10 +588,10 @@ void RecentTabsSubMenuModel::AddTabFavicon(int command_id, const GURL& url) { // --sync-tab-favicons switch is on; according to zea@, this flag is now // automatically enabled for iOS and android, and they're looking into // enabling it for other platforms. - browser_sync::SessionModelAssociator* associator = GetModelAssociator(); + browser_sync::OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(); scoped_refptr<base::RefCountedMemory> favicon_png; - if (associator && - associator->GetSyncedFaviconForPageURL(url.spec(), &favicon_png)) { + if (open_tabs && + open_tabs->GetSyncedFaviconForPageURL(url.spec(), &favicon_png)) { gfx::Image image = gfx::Image::CreateFrom1xPNGBytes(favicon_png->front(), favicon_png->size()); SetIcon(index_in_menu, image); @@ -660,16 +660,16 @@ void RecentTabsSubMenuModel::ClearLocalEntries() { local_window_items_.clear(); } -browser_sync::SessionModelAssociator* - RecentTabsSubMenuModel::GetModelAssociator() { - if (!associator_) { +browser_sync::OpenTabsUIDelegate* + RecentTabsSubMenuModel::GetOpenTabsUIDelegate() { + if (!open_tabs_delegate_) { ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> GetForProfile(browser_->profile()); - // Only return the associator if it exists and it is done syncing sessions. + // Only return the delegate if it exists and it is done syncing sessions. if (service && service->ShouldPushChanges()) - associator_ = service->GetSessionModelAssociator(); + open_tabs_delegate_ = service->GetOpenTabsUIDelegate(); } - return associator_; + return open_tabs_delegate_; } void RecentTabsSubMenuModel::TabRestoreServiceChanged( diff --git a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h index 3dbbc72..ad175ad 100644 --- a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h +++ b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h @@ -20,7 +20,7 @@ class Browser; struct SessionTab; namespace browser_sync { -class SessionModelAssociator; +class OpenTabsUIDelegate; } namespace chrome { @@ -47,11 +47,11 @@ class RecentTabsSubMenuModel : public ui::SimpleMenuModel, static const int kRecentlyClosedHeaderCommandId; static const int kDisabledRecentlyClosedHeaderCommandId; - // If |associator| is NULL, default associator for |browser|'s profile will - // be used. Testing may require a specific |associator|. + // If |open_tabs_delegate| is NULL, the default delegate for |browser|'s + // profile will be used. Testing may require a specific |open_tabs_delegate|. RecentTabsSubMenuModel(ui::AcceleratorProvider* accelerator_provider, Browser* browser, - browser_sync::SessionModelAssociator* associator); + browser_sync::OpenTabsUIDelegate* open_tabs_delegate); virtual ~RecentTabsSubMenuModel(); // Overridden from ui::SimpleMenuModel::Delegate: @@ -117,7 +117,13 @@ class RecentTabsSubMenuModel : public ui::SimpleMenuModel, // TabNavigationItems, and returns the corresponding local or other devices' // TabNavigationItems in |tab_items|. int CommandIdToTabVectorIndex(int command_id, TabNavigationItems** tab_items); - browser_sync::SessionModelAssociator* GetModelAssociator(); + + // Used to access (and lazily initialize) open_tabs_delegate_. + // TODO(tim): This lazy-init for member variables is error prone because you + // can always skip going through the function and access the field directly. + // Consider instead having code just deal with potentially NULL open_tabs_ + // and have it initialized by an event / callback. + browser_sync::OpenTabsUIDelegate* GetOpenTabsUIDelegate(); // Overridden from TabRestoreServiceObserver: virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE; @@ -125,7 +131,7 @@ class RecentTabsSubMenuModel : public ui::SimpleMenuModel, Browser* browser_; // Weak. - browser_sync::SessionModelAssociator* associator_; // Weak. + browser_sync::OpenTabsUIDelegate* open_tabs_delegate_; // Weak. // Accelerator for reopening last closed tab. ui::Accelerator reopen_closed_tab_accelerator_; diff --git a/chrome/browser/ui/webui/favicon_source.cc b/chrome/browser/ui/webui/favicon_source.cc index d5744ac..765b804 100644 --- a/chrome/browser/ui/webui/favicon_source.cc +++ b/chrome/browser/ui/webui/favicon_source.cc @@ -11,7 +11,7 @@ #include "chrome/browser/history/top_sites.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search/instant_io_context.h" -#include "chrome/browser/sync/glue/session_model_associator.h" +#include "chrome/browser/sync/open_tabs_ui_delegate.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/common/favicon/favicon_url_parser.h" @@ -143,13 +143,13 @@ bool FaviconSource::HandleMissingResource(const IconRequest& request) { // If the favicon is not available, try to use the synced favicon. ProfileSyncService* sync_service = ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); - browser_sync::SessionModelAssociator* associator = sync_service ? - sync_service->GetSessionModelAssociator() : NULL; + browser_sync::OpenTabsUIDelegate* open_tabs = sync_service ? + sync_service->GetOpenTabsUIDelegate() : NULL; scoped_refptr<base::RefCountedMemory> response; - if (associator && - associator->GetSyncedFaviconForPageURL(request.request_path.spec(), - &response)) { + if (open_tabs && + open_tabs->GetSyncedFaviconForPageURL(request.request_path.spec(), + &response)) { request.callback.Run(response.get()); return true; } diff --git a/chrome/browser/ui/webui/ntp/android/promo_handler.cc b/chrome/browser/ui/webui/ntp/android/promo_handler.cc index 4c8ba25c..d5a0bfd 100644 --- a/chrome/browser/ui/webui/ntp/android/promo_handler.cc +++ b/chrome/browser/ui/webui/ntp/android/promo_handler.cc @@ -16,8 +16,8 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/signin/signin_manager.h" -#include "chrome/browser/sync/glue/session_model_associator.h" #include "chrome/browser/sync/glue/synced_session.h" +#include "chrome/browser/sync/open_tabs_ui_delegate.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/web_resource/notification_promo.h" @@ -312,15 +312,15 @@ void PromoHandler::CheckDesktopSessions() { return; // Check if the sync has any open sessions. - browser_sync::SessionModelAssociator* associator = - service->GetSessionModelAssociator(); - if (!associator) + browser_sync::OpenTabsUIDelegate* open_tabs = + service->GetOpenTabsUIDelegate(); + if (!open_tabs) return; // Let's see if there are no desktop sessions. std::vector<const browser_sync::SyncedSession*> sessions; ListValue session_list; - if (!associator->GetAllForeignSessions(&sessions)) + if (!open_tabs->GetAllForeignSessions(&sessions)) return; for (size_t i = 0; i < sessions.size(); ++i) { diff --git a/chrome/browser/ui/webui/ntp/foreign_session_handler.cc b/chrome/browser/ui/webui/ntp/foreign_session_handler.cc index 2167292..9b151ed 100644 --- a/chrome/browser/ui/webui/ntp/foreign_session_handler.cc +++ b/chrome/browser/ui/webui/ntp/foreign_session_handler.cc @@ -71,14 +71,14 @@ void ForeignSessionHandler::OpenForeignSessionTab( SessionID::id_type window_num, SessionID::id_type tab_id, const WindowOpenDisposition& disposition) { - SessionModelAssociator* associator = GetModelAssociator(web_ui); - if (!associator) + OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(web_ui); + if (!open_tabs) return; // We don't actually care about |window_num|, this is just a sanity check. DCHECK_LT(kInvalidId, window_num); const SessionTab* tab; - if (!associator->GetForeignTab(session_string_value, tab_id, &tab)) { + if (!open_tabs->GetForeignTab(session_string_value, tab_id, &tab)) { LOG(ERROR) << "Failed to load foreign tab."; return; } @@ -95,15 +95,15 @@ void ForeignSessionHandler::OpenForeignSessionWindows( content::WebUI* web_ui, const std::string& session_string_value, SessionID::id_type window_num) { - SessionModelAssociator* associator = GetModelAssociator(web_ui); - if (!associator) + OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(web_ui); + if (!open_tabs) return; std::vector<const SessionWindow*> windows; // Note: we don't own the ForeignSessions themselves. - if (!associator->GetForeignSession(session_string_value, &windows)) { + if (!open_tabs->GetForeignSession(session_string_value, &windows)) { LOG(ERROR) << "ForeignSessionHandler failed to get session data from" - "SessionModelAssociator."; + "OpenTabsUIDelegate."; return; } std::vector<const SessionWindow*>::const_iterator iter_begin = @@ -147,15 +147,15 @@ bool ForeignSessionHandler::SessionTabToValue( } // static -SessionModelAssociator* ForeignSessionHandler::GetModelAssociator( +OpenTabsUIDelegate* ForeignSessionHandler::GetOpenTabsUIDelegate( content::WebUI* web_ui) { Profile* profile = Profile::FromWebUI(web_ui); ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); - // Only return the associator if it exists and it is done syncing sessions. + // Only return the delegate if it exists and it is done syncing sessions. if (service && service->ShouldPushChanges()) - return service->GetSessionModelAssociator(); + return service->GetOpenTabsUIDelegate(); return NULL; } @@ -226,11 +226,11 @@ string16 ForeignSessionHandler::FormatSessionTime(const base::Time& time) { } void ForeignSessionHandler::HandleGetForeignSessions(const ListValue* args) { - SessionModelAssociator* associator = GetModelAssociator(web_ui()); + OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(web_ui()); std::vector<const SyncedSession*> sessions; ListValue session_list; - if (associator && associator->GetAllForeignSessions(&sessions)) { + if (open_tabs && open_tabs->GetAllForeignSessions(&sessions)) { // Sort sessions from most recent to least recent. std::sort(sessions.begin(), sessions.end(), SortSessionsByRecency); @@ -339,9 +339,9 @@ void ForeignSessionHandler::HandleDeleteForeignSession(const ListValue* args) { return; } - SessionModelAssociator* associator = GetModelAssociator(web_ui()); - if (associator) - associator->DeleteForeignSession(session_tag); + OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(web_ui()); + if (open_tabs) + open_tabs->DeleteForeignSession(session_tag); } void ForeignSessionHandler::HandleSetForeignSessionCollapsed( diff --git a/chrome/browser/ui/webui/ntp/foreign_session_handler.h b/chrome/browser/ui/webui/ntp/foreign_session_handler.h index 25fb14e..443f124 100644 --- a/chrome/browser/ui/webui/ntp/foreign_session_handler.h +++ b/chrome/browser/ui/webui/ntp/foreign_session_handler.h @@ -9,7 +9,7 @@ #include "base/time/time.h" #include "chrome/browser/sessions/session_service.h" -#include "chrome/browser/sync/glue/session_model_associator.h" +#include "chrome/browser/sync/open_tabs_ui_delegate.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/web_ui.h" @@ -50,7 +50,7 @@ class ForeignSessionHandler : public content::WebUIMessageHandler, DictionaryValue* dictionary); // Returns a pointer to the current session model associator or NULL. - static SessionModelAssociator* GetModelAssociator(content::WebUI* web_ui); + static OpenTabsUIDelegate* GetOpenTabsUIDelegate(content::WebUI* web_ui); private: // Used to register ForeignSessionHandler for notifications. diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 91ec735..6927948 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2229,6 +2229,8 @@ 'browser/sync/backend_migrator.h', 'browser/sync/backend_unrecoverable_error_handler.cc', 'browser/sync/backend_unrecoverable_error_handler.h', + 'browser/sync/open_tabs_ui_delegate.cc', + 'browser/sync/open_tabs_ui_delegate.h', 'browser/sync/glue/autofill_data_type_controller.cc', 'browser/sync/glue/autofill_data_type_controller.h', 'browser/sync/glue/autofill_profile_data_type_controller.cc', @@ -2362,6 +2364,8 @@ 'browser/sync/profile_sync_service_observer.h', 'browser/sync/retry_verifier.cc', 'browser/sync/retry_verifier.h', + 'browser/sync/sessions2/session_data_type_controller2.cc', + 'browser/sync/sessions2/session_data_type_controller2.h', 'browser/sync/sessions2/sessions_sync_manager.cc', 'browser/sync/sessions2/sessions_sync_manager.h', 'browser/sync/sessions2/tab_node_pool2.cc', diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index cbf190f..1790b22 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -766,6 +766,9 @@ const char kEnableSuggestionsTabPage[] = "enable-suggestions-ntp"; const char kEnableSyncSyncedNotifications[] = "enable-sync-synced-notifications"; +// Enables sync/API based session sync implementation (in favor of legacy). +const char kEnableSyncSessionsV2[] = "enable-sync-sessions-v2"; + // Enables synced articles. const char kEnableSyncArticles[] = "enable-sync-articles"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 74dfcc4..299c1fd 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -220,6 +220,7 @@ extern const char kEnableStreamlinedHostedApps[]; extern const char kEnableSuggestionsTabPage[]; extern const char kEnableSyncArticles[]; extern const char kEnableSyncSyncedNotifications[]; +extern const char kEnableSyncSessionsV2[]; extern const char kEnableTabGroupsContextMenu[]; extern const char kEnableThumbnailRetargeting[]; extern const char kEnableTranslateNewUX[]; |