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

Unified Diff: components/sync_sessions/sessions_sync_manager.h

Issue 2575773003: Revert "Reland of [Sync] Put session tracker in charge of maintaining local state." (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/sync_sessions/sessions_sync_manager.h
diff --git a/components/sync_sessions/sessions_sync_manager.h b/components/sync_sessions/sessions_sync_manager.h
index 1f6af391d7a6844f3e75fc0965ef3cc3b93636f9..5f2b59813f78e32d7040c1b8fb96ece9e60aa36c 100644
--- a/components/sync_sessions/sessions_sync_manager.h
+++ b/components/sync_sessions/sessions_sync_manager.h
@@ -30,6 +30,7 @@
#include "components/sync_sessions/revisit/page_revisit_broadcaster.h"
#include "components/sync_sessions/synced_session.h"
#include "components/sync_sessions/synced_session_tracker.h"
+#include "components/sync_sessions/tab_node_pool.h"
namespace syncer {
class LocalDeviceInfoProvider;
@@ -117,6 +118,37 @@ class SessionsSyncManager : public syncer::SyncableService,
void DoGarbageCollection();
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
+ // all other fields are.
+ class TabLink {
+ public:
+ TabLink(int tab_node_id, const SyncedTabDelegate* tab)
+ : tab_node_id_(tab_node_id), tab_(tab) {}
+
+ void set_tab(const SyncedTabDelegate* tab) { tab_ = tab; }
+ void set_url(const GURL& url) { url_ = url; }
+
+ int tab_node_id() const { return tab_node_id_; }
+ const SyncedTabDelegate* tab() const { return tab_; }
+ const GURL& url() const { return url_; }
+
+ private:
+ // The id for the sync node this tab is stored in.
+ const int tab_node_id_;
+
+ // The tab object itself.
+ const SyncedTabDelegate* tab_;
+
+ // The currently visible url of the tab (used for syncing favicons).
+ GURL url_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabLink);
+ };
+
+ // Container for accessing local tab data by tab id.
+ typedef std::map<SessionID::id_type, linked_ptr<TabLink>> TabLinksMap;
+
friend class extensions::ExtensionSessionsTest;
friend class SessionsSyncManagerTest;
FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, PopulateSessionHeader);
@@ -150,16 +182,20 @@ class SessionsSyncManager : public syncer::SyncableService,
void InitializeCurrentMachineTag(const std::string& cache_guid);
- // Load and add window or tab data from synced specifics to our internal
+ // Load and add window or tab data for a foreign session to our internal
// tracking.
- void UpdateTrackerWithSpecifics(const sync_pb::SessionSpecifics& specifics,
- const base::Time& modification_time);
+ void UpdateTrackerWithForeignSession(
+ const sync_pb::SessionSpecifics& specifics,
+ const base::Time& modification_time);
// Returns true if |sync_data| contained a header node for the current
- // machine, false otherwise. |new_changes| is a link to the SyncChange
- // pipeline that exists in the caller's context. This function will append
- // necessary changes for processing later.
+ // machine, false otherwise. |restored_tabs| is a filtered tab-only
+ // subset of |sync_data| returned by this function for convenience.
+ // |new_changes| is a link to the SyncChange pipeline that exists in the
+ // caller's context. This function will append necessary changes for
+ // processing later.
bool InitFromSyncModel(const syncer::SyncDataList& sync_data,
+ syncer::SyncDataList* restored_tabs,
syncer::SyncChangeList* new_changes);
// Helper to construct a deletion SyncChange for a *tab node*.
@@ -208,6 +244,11 @@ class SessionsSyncManager : public syncer::SyncableService,
// RELOAD_TABS will additionally cause a resync of all tabs (same as calling
// AssociateTabs with a vector of all tabs).
//
+ // |restored_tabs| is a filtered tab-only subset of initial sync data, if
+ // available (during MergeDataAndStartSyncing). It can be used to obtain
+ // baseline SessionSpecifics for tabs we can't fully associate any other
+ // way because they don't yet have a WebContents.
+ //
// Returns: false if the local session's sync nodes were deleted and
// reassociation is necessary, true otherwise.
//
@@ -216,6 +257,7 @@ class SessionsSyncManager : public syncer::SyncableService,
// changes for processing later.
enum ReloadTabsOption { RELOAD_TABS, DONT_RELOAD_TABS };
void AssociateWindows(ReloadTabsOption option,
+ const syncer::SyncDataList& restored_tabs,
syncer::SyncChangeList* change_output);
// Loads and reassociates the local tabs referenced in |tabs|.
@@ -244,10 +286,17 @@ class SessionsSyncManager : public syncer::SyncableService,
// as they may have changed after a session was restored. This method
// compares new_tab_id and new_window_id against the previously persisted tab
// ID and window ID (from our TabNodePool) and updates them if either differs.
+ // |restored_tabs| is a filtered tab-only subset of initial sync data, if
+ // available (during MergeDataAndStartSyncing). It can be used to obtain
+ // baseline SessionSpecifics for tabs we can't fully associate any other
+ // way because they don't yet have a WebContents.
+ // TODO(tim): Bug 98892. We should be able to test this for this on android
+ // even though we didn't have tests for old API-based sessions sync.
void AssociateRestoredPlaceholderTab(
const SyncedTabDelegate& tab_delegate,
SessionID::id_type new_tab_id,
SessionID::id_type new_window_id,
+ const syncer::SyncDataList& restored_tabs,
syncer::SyncChangeList* change_output);
// Stops and re-starts syncing to rebuild association mappings. Returns true
@@ -274,9 +323,15 @@ class SessionsSyncManager : public syncer::SyncableService,
// The client of this sync sessions datatype.
SyncSessionsClient* const sessions_client_;
+ // Mapping of current open (local) tabs to their sync identifiers.
+ TabLinksMap local_tab_map_;
+
SyncedSessionTracker session_tracker_;
FaviconCache favicon_cache_;
+ // Pool of used/available sync nodes associated with local tabs.
+ TabNodePool local_tab_pool_;
+
// Tracks whether our local representation of which sync nodes map to what
// tabs (belonging to the current local session) is inconsistent. This can
// happen if a foreign client deems our session as "stale" and decides to
« no previous file with comments | « chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc ('k') | components/sync_sessions/sessions_sync_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698