OLD | NEW |
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 | 113 |
114 FaviconCache* GetFaviconCache(); | 114 FaviconCache* GetFaviconCache(); |
115 | 115 |
116 // Triggers garbage collection of stale sessions (as defined by | 116 // Triggers garbage collection of stale sessions (as defined by |
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 // Track links between a tab id and it's sync tab node id and url. The tab | 122 // Keep all the links to local tab data in one place. A tab_node_id and tab |
123 // node id is not mutable, as the entity backing a tab should never change | 123 // must be passed at creation. The tab_node_id is not mutable, although |
124 // during runtime. The url can be updated as navigations are performed. | 124 // all other fields are. |
125 class TabLink { | 125 class TabLink { |
126 public: | 126 public: |
127 explicit TabLink(int tab_node_id) : tab_node_id_(tab_node_id) {} | 127 TabLink(int tab_node_id, const SyncedTabDelegate* tab) |
| 128 : tab_node_id_(tab_node_id), tab_(tab) {} |
128 | 129 |
| 130 void set_tab(const SyncedTabDelegate* tab) { tab_ = tab; } |
129 void set_url(const GURL& url) { url_ = url; } | 131 void set_url(const GURL& url) { url_ = url; } |
130 | 132 |
131 int tab_node_id() const { return tab_node_id_; } | 133 int tab_node_id() const { return tab_node_id_; } |
| 134 const SyncedTabDelegate* tab() const { return tab_; } |
132 const GURL& url() const { return url_; } | 135 const GURL& url() const { return url_; } |
133 | 136 |
134 private: | 137 private: |
135 // The id for the sync node this tab is stored in. | 138 // The id for the sync node this tab is stored in. |
136 const int tab_node_id_; | 139 const int tab_node_id_; |
137 | 140 |
| 141 // The tab object itself. |
| 142 const SyncedTabDelegate* tab_; |
| 143 |
138 // The currently visible url of the tab (used for syncing favicons). | 144 // The currently visible url of the tab (used for syncing favicons). |
139 GURL url_; | 145 GURL url_; |
140 | 146 |
141 DISALLOW_COPY_AND_ASSIGN(TabLink); | 147 DISALLOW_COPY_AND_ASSIGN(TabLink); |
142 }; | 148 }; |
143 | 149 |
144 // Container for accessing local tab data by tab id. | 150 // Container for accessing local tab data by tab id. |
145 typedef std::map<SessionID::id_type, linked_ptr<TabLink>> TabLinksMap; | 151 typedef std::map<SessionID::id_type, linked_ptr<TabLink>> TabLinksMap; |
146 | 152 |
147 friend class extensions::ExtensionSessionsTest; | 153 friend class extensions::ExtensionSessionsTest; |
(...skipping 22 matching lines...) Expand all Loading... |
170 CheckPrerenderedWebContentsSwap); | 176 CheckPrerenderedWebContentsSwap); |
171 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, | 177 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, |
172 AssociateWindowsDontReloadTabs); | 178 AssociateWindowsDontReloadTabs); |
173 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, SwappedOutOnRestore); | 179 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, SwappedOutOnRestore); |
174 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, | 180 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, |
175 ProcessRemoteDeleteOfLocalSession); | 181 ProcessRemoteDeleteOfLocalSession); |
176 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, SetVariationIds); | 182 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, SetVariationIds); |
177 | 183 |
178 void InitializeCurrentMachineTag(); | 184 void InitializeCurrentMachineTag(); |
179 | 185 |
180 // Load and add window or tab data from synced specifics to our internal | 186 // Load and add window or tab data for a foreign session to our internal |
181 // tracking. | 187 // tracking. |
182 void UpdateTrackerWithSpecifics(const sync_pb::SessionSpecifics& specifics, | 188 void UpdateTrackerWithForeignSession( |
183 const base::Time& modification_time); | 189 const sync_pb::SessionSpecifics& specifics, |
| 190 const base::Time& modification_time); |
184 | 191 |
185 // Returns true if |sync_data| contained a header node for the current | 192 // Returns true if |sync_data| contained a header node for the current |
186 // machine, false otherwise. |new_changes| is a link to the SyncChange | 193 // machine, false otherwise. |restored_tabs| is a filtered tab-only |
187 // pipeline that exists in the caller's context. This function will append | 194 // subset of |sync_data| returned by this function for convenience. |
188 // necessary changes for processing later. | 195 // |new_changes| is a link to the SyncChange pipeline that exists in the |
| 196 // caller's context. This function will append necessary changes for |
| 197 // processing later. |
189 bool InitFromSyncModel(const syncer::SyncDataList& sync_data, | 198 bool InitFromSyncModel(const syncer::SyncDataList& sync_data, |
| 199 syncer::SyncDataList* restored_tabs, |
190 syncer::SyncChangeList* new_changes); | 200 syncer::SyncChangeList* new_changes); |
191 | 201 |
192 // Helper to construct a deletion SyncChange for a *tab node*. | 202 // Helper to construct a deletion SyncChange for a *tab node*. |
193 // Caller should check IsValid() on the returned change, as it's possible | 203 // Caller should check IsValid() on the returned change, as it's possible |
194 // this node could not be deleted. | 204 // this node could not be deleted. |
195 syncer::SyncChange TombstoneTab(const sync_pb::SessionSpecifics& tab); | 205 syncer::SyncChange TombstoneTab(const sync_pb::SessionSpecifics& tab); |
196 | 206 |
197 // Helper method to load the favicon data from the tab specifics. If the | 207 // Helper method to load the favicon data from the tab specifics. If the |
198 // favicon is valid, stores the favicon data into the favicon cache. | 208 // favicon is valid, stores the favicon data into the favicon cache. |
199 void RefreshFaviconVisitTimesFromForeignTab( | 209 void RefreshFaviconVisitTimesFromForeignTab( |
(...skipping 28 matching lines...) Expand all Loading... |
228 sessions::SessionWindow* session_window); | 238 sessions::SessionWindow* session_window); |
229 | 239 |
230 // Resync local window information. Updates the local sessions header node | 240 // Resync local window information. Updates the local sessions header node |
231 // with the status of open windows and the order of tabs they contain. Should | 241 // with the status of open windows and the order of tabs they contain. Should |
232 // only be called for changes that affect a window, not a change within a | 242 // only be called for changes that affect a window, not a change within a |
233 // single tab. | 243 // single tab. |
234 // | 244 // |
235 // RELOAD_TABS will additionally cause a resync of all tabs (same as calling | 245 // RELOAD_TABS will additionally cause a resync of all tabs (same as calling |
236 // AssociateTabs with a vector of all tabs). | 246 // AssociateTabs with a vector of all tabs). |
237 // | 247 // |
| 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 // |
238 // Returns: false if the local session's sync nodes were deleted and | 253 // Returns: false if the local session's sync nodes were deleted and |
239 // reassociation is necessary, true otherwise. | 254 // reassociation is necessary, true otherwise. |
240 // | 255 // |
241 // |change_output| *must* be provided as a link to the SyncChange pipeline | 256 // |change_output| *must* be provided as a link to the SyncChange pipeline |
242 // that exists in the caller's context. This function will append necessary | 257 // that exists in the caller's context. This function will append necessary |
243 // changes for processing later. | 258 // changes for processing later. |
244 enum ReloadTabsOption { RELOAD_TABS, DONT_RELOAD_TABS }; | 259 enum ReloadTabsOption { RELOAD_TABS, DONT_RELOAD_TABS }; |
245 void AssociateWindows(ReloadTabsOption option, | 260 void AssociateWindows(ReloadTabsOption option, |
| 261 const syncer::SyncDataList& restored_tabs, |
246 syncer::SyncChangeList* change_output); | 262 syncer::SyncChangeList* change_output); |
247 | 263 |
248 // Loads and reassociates the local tabs referenced in |tabs|. | 264 // Loads and reassociates the local tabs referenced in |tabs|. |
249 // |change_output| *must* be provided as a link to the SyncChange pipeline | 265 // |change_output| *must* be provided as a link to the SyncChange pipeline |
250 // that exists in the caller's context. This function will append necessary | 266 // that exists in the caller's context. This function will append necessary |
251 // changes for processing later. | 267 // changes for processing later. |
252 void AssociateTab(SyncedTabDelegate* const tab, | 268 void AssociateTab(SyncedTabDelegate* const tab, |
253 syncer::SyncChangeList* change_output); | 269 syncer::SyncChangeList* change_output); |
254 | 270 |
255 // Set |session_tab| from |tab_delegate| and |mtime|. | 271 // Set |session_tab| from |tab_delegate| and |mtime|. |
256 void SetSessionTabFromDelegate(const SyncedTabDelegate& tab_delegate, | 272 void SetSessionTabFromDelegate(const SyncedTabDelegate& tab_delegate, |
257 base::Time mtime, | 273 base::Time mtime, |
258 sessions::SessionTab* session_tab); | 274 sessions::SessionTab* session_tab); |
259 | 275 |
260 // Sets |variation_ids| field of |session_tab| with the ids of the currently | 276 // Sets |variation_ids| field of |session_tab| with the ids of the currently |
261 // assigned variations which should be sent to sync. | 277 // assigned variations which should be sent to sync. |
262 static void SetVariationIds(sessions::SessionTab* session_tab); | 278 static void SetVariationIds(sessions::SessionTab* session_tab); |
263 | 279 |
264 // Populates |specifics| based on the data in |tab_delegate|. | 280 // Populates |specifics| based on the data in |tab_delegate|. |
265 void LocalTabDelegateToSpecifics(const SyncedTabDelegate& tab_delegate, | 281 void LocalTabDelegateToSpecifics(const SyncedTabDelegate& tab_delegate, |
266 sync_pb::SessionSpecifics* specifics); | 282 sync_pb::SessionSpecifics* specifics); |
267 | 283 |
268 // It's possible that when we associate windows, tabs aren't all loaded | 284 // It's possible that when we associate windows, tabs aren't all loaded |
269 // into memory yet (e.g on android) and we don't have a WebContents. In this | 285 // into memory yet (e.g on android) and we don't have a WebContents. In this |
270 // case we can't do a full association, but we still want to update tab IDs | 286 // case we can't do a full association, but we still want to update tab IDs |
271 // as they may have changed after a session was restored. This method | 287 // as they may have changed after a session was restored. This method |
272 // compares new_tab_id and new_window_id against the previously persisted tab | 288 // compares new_tab_id and new_window_id against the previously persisted tab |
273 // ID and window ID (from our TabNodePool) and updates them if either differs. | 289 // 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. |
274 void AssociateRestoredPlaceholderTab( | 296 void AssociateRestoredPlaceholderTab( |
275 const SyncedTabDelegate& tab_delegate, | 297 const SyncedTabDelegate& tab_delegate, |
276 SessionID::id_type new_tab_id, | 298 SessionID::id_type new_tab_id, |
277 SessionID::id_type new_window_id, | 299 SessionID::id_type new_window_id, |
| 300 const syncer::SyncDataList& restored_tabs, |
278 syncer::SyncChangeList* change_output); | 301 syncer::SyncChangeList* change_output); |
279 | 302 |
280 // Stops and re-starts syncing to rebuild association mappings. | 303 // Stops and re-starts syncing to rebuild association mappings. |
281 // See |local_tab_pool_out_of_sync_|. | 304 // See |local_tab_pool_out_of_sync_|. |
282 void RebuildAssociations(); | 305 void RebuildAssociations(); |
283 | 306 |
284 // Validates the content of a SessionHeader protobuf. | 307 // Validates the content of a SessionHeader protobuf. |
285 // Returns false if validation fails. | 308 // Returns false if validation fails. |
286 static bool IsValidSessionHeader(const sync_pb::SessionHeader& header); | 309 static bool IsValidSessionHeader(const sync_pb::SessionHeader& header); |
287 | 310 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 376 |
354 // Callback to inform sync that a sync data refresh is requested. | 377 // Callback to inform sync that a sync data refresh is requested. |
355 base::Closure datatype_refresh_callback_; | 378 base::Closure datatype_refresh_callback_; |
356 | 379 |
357 DISALLOW_COPY_AND_ASSIGN(SessionsSyncManager); | 380 DISALLOW_COPY_AND_ASSIGN(SessionsSyncManager); |
358 }; | 381 }; |
359 | 382 |
360 } // namespace sync_sessions | 383 } // namespace sync_sessions |
361 | 384 |
362 #endif // COMPONENTS_SYNC_SESSIONS_SESSIONS_SYNC_MANAGER_H_ | 385 #endif // COMPONENTS_SYNC_SESSIONS_SESSIONS_SYNC_MANAGER_H_ |
OLD | NEW |