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

Side by Side Diff: components/sync_sessions/sessions_sync_manager.h

Issue 2494533002: [Sync] Put session tracker in charge of maintaining local state. (Closed)
Patch Set: Rebase Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_SYNC_SESSIONS_SESSIONS_SYNC_MANAGER_H_ 5 #ifndef COMPONENTS_SYNC_SESSIONS_SESSIONS_SYNC_MANAGER_H_
6 #define COMPONENTS_SYNC_SESSIONS_SESSIONS_SYNC_MANAGER_H_ 6 #define COMPONENTS_SYNC_SESSIONS_SESSIONS_SYNC_MANAGER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // |stale_session_threshold_days_|). This is called every time we see new 117 // |stale_session_threshold_days_|). This is called every time we see new
118 // sessions data downloaded (sync cycles complete). 118 // sessions data downloaded (sync cycles complete).
119 void DoGarbageCollection(); 119 void DoGarbageCollection();
120 120
121 private: 121 private:
122 // Keep all the links to local tab data in one place. A tab_node_id and tab 122 // Keep all the links to local tab data in one place. A tab_node_id and tab
123 // must be passed at creation. The tab_node_id is not mutable, although 123 // must be passed at creation. The tab_node_id is not mutable, although
124 // all other fields are. 124 // all other fields are.
125 class TabLink { 125 class TabLink {
126 public: 126 public:
127 TabLink(int tab_node_id, const SyncedTabDelegate* tab) 127 explicit TabLink(int tab_node_id) : tab_node_id_(tab_node_id) {}
128 : tab_node_id_(tab_node_id), tab_(tab) {}
129 128
130 void set_tab(const SyncedTabDelegate* tab) { tab_ = tab; }
131 void set_url(const GURL& url) { url_ = url; } 129 void set_url(const GURL& url) { url_ = url; }
132 130
133 int tab_node_id() const { return tab_node_id_; } 131 int tab_node_id() const { return tab_node_id_; }
134 const SyncedTabDelegate* tab() const { return tab_; }
135 const GURL& url() const { return url_; } 132 const GURL& url() const { return url_; }
136 133
137 private: 134 private:
138 // The id for the sync node this tab is stored in. 135 // The id for the sync node this tab is stored in.
139 const int tab_node_id_; 136 const int tab_node_id_;
140 137
141 // The tab object itself.
142 const SyncedTabDelegate* tab_;
143
144 // The currently visible url of the tab (used for syncing favicons). 138 // The currently visible url of the tab (used for syncing favicons).
145 GURL url_; 139 GURL url_;
146 140
147 DISALLOW_COPY_AND_ASSIGN(TabLink); 141 DISALLOW_COPY_AND_ASSIGN(TabLink);
148 }; 142 };
149 143
150 // Container for accessing local tab data by tab id. 144 // Container for accessing local tab data by tab id.
151 typedef std::map<SessionID::id_type, linked_ptr<TabLink>> TabLinksMap; 145 typedef std::map<SessionID::id_type, linked_ptr<TabLink>> TabLinksMap;
152 146
153 friend class extensions::ExtensionSessionsTest; 147 friend class extensions::ExtensionSessionsTest;
(...skipping 22 matching lines...) Expand all
176 CheckPrerenderedWebContentsSwap); 170 CheckPrerenderedWebContentsSwap);
177 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, 171 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest,
178 AssociateWindowsDontReloadTabs); 172 AssociateWindowsDontReloadTabs);
179 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, SwappedOutOnRestore); 173 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, SwappedOutOnRestore);
180 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, 174 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest,
181 ProcessRemoteDeleteOfLocalSession); 175 ProcessRemoteDeleteOfLocalSession);
182 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, SetVariationIds); 176 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, SetVariationIds);
183 177
184 void InitializeCurrentMachineTag(); 178 void InitializeCurrentMachineTag();
185 179
186 // Load and add window or tab data for a foreign session to our internal 180 // Load and add window or tab data from synced specifics to our internal
187 // tracking. 181 // tracking.
188 void UpdateTrackerWithForeignSession( 182 void UpdateTrackerWithSpecifics(const sync_pb::SessionSpecifics& specifics,
189 const sync_pb::SessionSpecifics& specifics, 183 const base::Time& modification_time);
190 const base::Time& modification_time);
191 184
192 // Returns true if |sync_data| contained a header node for the current 185 // Returns true if |sync_data| contained a header node for the current
193 // machine, false otherwise. |restored_tabs| is a filtered tab-only 186 // machine, false otherwise. |new_changes| is a link to the SyncChange
194 // subset of |sync_data| returned by this function for convenience. 187 // pipeline that exists in the caller's context. This function will append
195 // |new_changes| is a link to the SyncChange pipeline that exists in the 188 // necessary changes for processing later.
196 // caller's context. This function will append necessary changes for
197 // processing later.
198 bool InitFromSyncModel(const syncer::SyncDataList& sync_data, 189 bool InitFromSyncModel(const syncer::SyncDataList& sync_data,
199 syncer::SyncDataList* restored_tabs,
200 syncer::SyncChangeList* new_changes); 190 syncer::SyncChangeList* new_changes);
201 191
202 // Helper to construct a deletion SyncChange for a *tab node*. 192 // Helper to construct a deletion SyncChange for a *tab node*.
203 // Caller should check IsValid() on the returned change, as it's possible 193 // Caller should check IsValid() on the returned change, as it's possible
204 // this node could not be deleted. 194 // this node could not be deleted.
205 syncer::SyncChange TombstoneTab(const sync_pb::SessionSpecifics& tab); 195 syncer::SyncChange TombstoneTab(const sync_pb::SessionSpecifics& tab);
206 196
207 // Helper method to load the favicon data from the tab specifics. If the 197 // Helper method to load the favicon data from the tab specifics. If the
208 // favicon is valid, stores the favicon data into the favicon cache. 198 // favicon is valid, stores the favicon data into the favicon cache.
209 void RefreshFaviconVisitTimesFromForeignTab( 199 void RefreshFaviconVisitTimesFromForeignTab(
(...skipping 28 matching lines...) Expand all
238 sessions::SessionWindow* session_window); 228 sessions::SessionWindow* session_window);
239 229
240 // Resync local window information. Updates the local sessions header node 230 // Resync local window information. Updates the local sessions header node
241 // with the status of open windows and the order of tabs they contain. Should 231 // with the status of open windows and the order of tabs they contain. Should
242 // only be called for changes that affect a window, not a change within a 232 // only be called for changes that affect a window, not a change within a
243 // single tab. 233 // single tab.
244 // 234 //
245 // RELOAD_TABS will additionally cause a resync of all tabs (same as calling 235 // RELOAD_TABS will additionally cause a resync of all tabs (same as calling
246 // AssociateTabs with a vector of all tabs). 236 // AssociateTabs with a vector of all tabs).
247 // 237 //
248 // |restored_tabs| is a filtered tab-only subset of initial sync data, if
249 // available (during MergeDataAndStartSyncing). It can be used to obtain
250 // baseline SessionSpecifics for tabs we can't fully associate any other
251 // way because they don't yet have a WebContents.
252 //
253 // Returns: false if the local session's sync nodes were deleted and 238 // Returns: false if the local session's sync nodes were deleted and
254 // reassociation is necessary, true otherwise. 239 // reassociation is necessary, true otherwise.
255 // 240 //
256 // |change_output| *must* be provided as a link to the SyncChange pipeline 241 // |change_output| *must* be provided as a link to the SyncChange pipeline
257 // that exists in the caller's context. This function will append necessary 242 // that exists in the caller's context. This function will append necessary
258 // changes for processing later. 243 // changes for processing later.
259 enum ReloadTabsOption { RELOAD_TABS, DONT_RELOAD_TABS }; 244 enum ReloadTabsOption { RELOAD_TABS, DONT_RELOAD_TABS };
260 void AssociateWindows(ReloadTabsOption option, 245 void AssociateWindows(ReloadTabsOption option,
261 const syncer::SyncDataList& restored_tabs,
262 syncer::SyncChangeList* change_output); 246 syncer::SyncChangeList* change_output);
263 247
264 // Loads and reassociates the local tabs referenced in |tabs|. 248 // Loads and reassociates the local tabs referenced in |tabs|.
265 // |change_output| *must* be provided as a link to the SyncChange pipeline 249 // |change_output| *must* be provided as a link to the SyncChange pipeline
266 // that exists in the caller's context. This function will append necessary 250 // that exists in the caller's context. This function will append necessary
267 // changes for processing later. 251 // changes for processing later.
268 void AssociateTab(SyncedTabDelegate* const tab, 252 void AssociateTab(SyncedTabDelegate* const tab,
269 syncer::SyncChangeList* change_output); 253 syncer::SyncChangeList* change_output);
270 254
271 // Set |session_tab| from |tab_delegate| and |mtime|. 255 // Set |session_tab| from |tab_delegate| and |mtime|.
272 void SetSessionTabFromDelegate(const SyncedTabDelegate& tab_delegate, 256 void SetSessionTabFromDelegate(const SyncedTabDelegate& tab_delegate,
273 base::Time mtime, 257 base::Time mtime,
274 sessions::SessionTab* session_tab); 258 sessions::SessionTab* session_tab);
275 259
276 // Sets |variation_ids| field of |session_tab| with the ids of the currently 260 // Sets |variation_ids| field of |session_tab| with the ids of the currently
277 // assigned variations which should be sent to sync. 261 // assigned variations which should be sent to sync.
278 static void SetVariationIds(sessions::SessionTab* session_tab); 262 static void SetVariationIds(sessions::SessionTab* session_tab);
279 263
280 // Populates |specifics| based on the data in |tab_delegate|. 264 // Populates |specifics| based on the data in |tab_delegate|.
265 // Returns true on success, false on failure.
maxbogue 2016/11/10 06:43:26 Still looks void to me. This from an earlier revis
Nicolas Zea 2016/11/10 18:25:36 Woops, yes, removed.
281 void LocalTabDelegateToSpecifics(const SyncedTabDelegate& tab_delegate, 266 void LocalTabDelegateToSpecifics(const SyncedTabDelegate& tab_delegate,
282 sync_pb::SessionSpecifics* specifics); 267 sync_pb::SessionSpecifics* specifics);
283 268
284 // It's possible that when we associate windows, tabs aren't all loaded 269 // It's possible that when we associate windows, tabs aren't all loaded
285 // into memory yet (e.g on android) and we don't have a WebContents. In this 270 // into memory yet (e.g on android) and we don't have a WebContents. In this
286 // case we can't do a full association, but we still want to update tab IDs 271 // case we can't do a full association, but we still want to update tab IDs
287 // as they may have changed after a session was restored. This method 272 // as they may have changed after a session was restored. This method
288 // compares new_tab_id and new_window_id against the previously persisted tab 273 // compares new_tab_id and new_window_id against the previously persisted tab
289 // ID and window ID (from our TabNodePool) and updates them if either differs. 274 // ID and window ID (from our TabNodePool) and updates them if either differs.
290 // |restored_tabs| is a filtered tab-only subset of initial sync data, if
291 // available (during MergeDataAndStartSyncing). It can be used to obtain
292 // baseline SessionSpecifics for tabs we can't fully associate any other
293 // way because they don't yet have a WebContents.
294 // TODO(tim): Bug 98892. We should be able to test this for this on android
295 // even though we didn't have tests for old API-based sessions sync.
296 void AssociateRestoredPlaceholderTab( 275 void AssociateRestoredPlaceholderTab(
297 const SyncedTabDelegate& tab_delegate, 276 const SyncedTabDelegate& tab_delegate,
298 SessionID::id_type new_tab_id, 277 SessionID::id_type new_tab_id,
299 SessionID::id_type new_window_id, 278 SessionID::id_type new_window_id,
300 const syncer::SyncDataList& restored_tabs,
301 syncer::SyncChangeList* change_output); 279 syncer::SyncChangeList* change_output);
302 280
303 // Stops and re-starts syncing to rebuild association mappings. 281 // Stops and re-starts syncing to rebuild association mappings.
304 // See |local_tab_pool_out_of_sync_|. 282 // See |local_tab_pool_out_of_sync_|.
305 void RebuildAssociations(); 283 void RebuildAssociations();
306 284
307 // Validates the content of a SessionHeader protobuf. 285 // Validates the content of a SessionHeader protobuf.
308 // Returns false if validation fails. 286 // Returns false if validation fails.
309 static bool IsValidSessionHeader(const sync_pb::SessionHeader& header); 287 static bool IsValidSessionHeader(const sync_pb::SessionHeader& header);
310 288
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 354
377 // Callback to inform sync that a sync data refresh is requested. 355 // Callback to inform sync that a sync data refresh is requested.
378 base::Closure datatype_refresh_callback_; 356 base::Closure datatype_refresh_callback_;
379 357
380 DISALLOW_COPY_AND_ASSIGN(SessionsSyncManager); 358 DISALLOW_COPY_AND_ASSIGN(SessionsSyncManager);
381 }; 359 };
382 360
383 } // namespace sync_sessions 361 } // namespace sync_sessions
384 362
385 #endif // COMPONENTS_SYNC_SESSIONS_SESSIONS_SYNC_MANAGER_H_ 363 #endif // COMPONENTS_SYNC_SESSIONS_SESSIONS_SYNC_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698