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

Unified Diff: components/sync_sessions/sessions_sync_manager.h

Issue 2694963002: Revert of Reland v4 of Session refactor (Closed)
Patch Set: Created 3 years, 10 months 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 d685c65cd42b58f7cb22d4b2b3b6810761165eec..66ec40e916f647a8cad52819b28a39cc8fb15bbb 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 @@
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 @@
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*.
@@ -207,6 +243,11 @@
//
// 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 @@
// 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 @@
// 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,8 +323,14 @@
// 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
« 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