summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/sessions2
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/sync/sessions2')
-rw-r--r--chrome/browser/sync/sessions2/session_data_type_controller2.cc56
-rw-r--r--chrome/browser/sync/sessions2/session_data_type_controller2.h40
-rw-r--r--chrome/browser/sync/sessions2/sessions_sync_manager.cc60
-rw-r--r--chrome/browser/sync/sessions2/sessions_sync_manager.h40
-rw-r--r--chrome/browser/sync/sessions2/sessions_sync_manager_unittest.cc23
5 files changed, 176 insertions, 43 deletions
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>(