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

Side by Side 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 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 12 matching lines...) Expand all
23 #include "components/sync/base/sync_prefs.h" 23 #include "components/sync/base/sync_prefs.h"
24 #include "components/sync/device_info/device_info.h" 24 #include "components/sync/device_info/device_info.h"
25 #include "components/sync/model/syncable_service.h" 25 #include "components/sync/model/syncable_service.h"
26 #include "components/sync_sessions/favicon_cache.h" 26 #include "components/sync_sessions/favicon_cache.h"
27 #include "components/sync_sessions/local_session_event_router.h" 27 #include "components/sync_sessions/local_session_event_router.h"
28 #include "components/sync_sessions/lost_navigations_recorder.h" 28 #include "components/sync_sessions/lost_navigations_recorder.h"
29 #include "components/sync_sessions/open_tabs_ui_delegate.h" 29 #include "components/sync_sessions/open_tabs_ui_delegate.h"
30 #include "components/sync_sessions/revisit/page_revisit_broadcaster.h" 30 #include "components/sync_sessions/revisit/page_revisit_broadcaster.h"
31 #include "components/sync_sessions/synced_session.h" 31 #include "components/sync_sessions/synced_session.h"
32 #include "components/sync_sessions/synced_session_tracker.h" 32 #include "components/sync_sessions/synced_session_tracker.h"
33 #include "components/sync_sessions/tab_node_pool.h"
33 34
34 namespace syncer { 35 namespace syncer {
35 class LocalDeviceInfoProvider; 36 class LocalDeviceInfoProvider;
36 class SyncErrorFactory; 37 class SyncErrorFactory;
37 class SyncPrefs; 38 class SyncPrefs;
38 } // namespace syncer 39 } // namespace syncer
39 40
40 namespace sync_pb { 41 namespace sync_pb {
41 class SessionHeader; 42 class SessionHeader;
42 class SessionSpecifics; 43 class SessionSpecifics;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 } 111 }
111 112
112 FaviconCache* GetFaviconCache(); 113 FaviconCache* GetFaviconCache();
113 114
114 // Triggers garbage collection of stale sessions (as defined by 115 // Triggers garbage collection of stale sessions (as defined by
115 // |stale_session_threshold_days_|). This is called every time we see new 116 // |stale_session_threshold_days_|). This is called every time we see new
116 // sessions data downloaded (sync cycles complete). 117 // sessions data downloaded (sync cycles complete).
117 void DoGarbageCollection(); 118 void DoGarbageCollection();
118 119
119 private: 120 private:
121 // Keep all the links to local tab data in one place. A tab_node_id and tab
122 // must be passed at creation. The tab_node_id is not mutable, although
123 // all other fields are.
124 class TabLink {
125 public:
126 TabLink(int tab_node_id, const SyncedTabDelegate* tab)
127 : tab_node_id_(tab_node_id), tab_(tab) {}
128
129 void set_tab(const SyncedTabDelegate* tab) { tab_ = tab; }
130 void set_url(const GURL& url) { url_ = url; }
131
132 int tab_node_id() const { return tab_node_id_; }
133 const SyncedTabDelegate* tab() const { return tab_; }
134 const GURL& url() const { return url_; }
135
136 private:
137 // The id for the sync node this tab is stored in.
138 const int tab_node_id_;
139
140 // The tab object itself.
141 const SyncedTabDelegate* tab_;
142
143 // The currently visible url of the tab (used for syncing favicons).
144 GURL url_;
145
146 DISALLOW_COPY_AND_ASSIGN(TabLink);
147 };
148
149 // Container for accessing local tab data by tab id.
150 typedef std::map<SessionID::id_type, linked_ptr<TabLink>> TabLinksMap;
151
120 friend class extensions::ExtensionSessionsTest; 152 friend class extensions::ExtensionSessionsTest;
121 friend class SessionsSyncManagerTest; 153 friend class SessionsSyncManagerTest;
122 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, PopulateSessionHeader); 154 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, PopulateSessionHeader);
123 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, PopulateSessionWindow); 155 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, PopulateSessionWindow);
124 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, ValidTabs); 156 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, ValidTabs);
125 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, SetSessionTabFromDelegate); 157 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, SetSessionTabFromDelegate);
126 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, 158 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest,
127 SetSessionTabFromDelegateNavigationIndex); 159 SetSessionTabFromDelegateNavigationIndex);
128 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, 160 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest,
129 SetSessionTabFromDelegateCurrentInvalid); 161 SetSessionTabFromDelegateCurrentInvalid);
(...skipping 13 matching lines...) Expand all
143 CheckPrerenderedWebContentsSwap); 175 CheckPrerenderedWebContentsSwap);
144 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, 176 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest,
145 AssociateWindowsDontReloadTabs); 177 AssociateWindowsDontReloadTabs);
146 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, SwappedOutOnRestore); 178 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, SwappedOutOnRestore);
147 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, 179 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest,
148 ProcessRemoteDeleteOfLocalSession); 180 ProcessRemoteDeleteOfLocalSession);
149 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, SetVariationIds); 181 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, SetVariationIds);
150 182
151 void InitializeCurrentMachineTag(const std::string& cache_guid); 183 void InitializeCurrentMachineTag(const std::string& cache_guid);
152 184
153 // Load and add window or tab data from synced specifics to our internal 185 // Load and add window or tab data for a foreign session to our internal
154 // tracking. 186 // tracking.
155 void UpdateTrackerWithSpecifics(const sync_pb::SessionSpecifics& specifics, 187 void UpdateTrackerWithForeignSession(
156 const base::Time& modification_time); 188 const sync_pb::SessionSpecifics& specifics,
189 const base::Time& modification_time);
157 190
158 // Returns true if |sync_data| contained a header node for the current 191 // Returns true if |sync_data| contained a header node for the current
159 // machine, false otherwise. |new_changes| is a link to the SyncChange 192 // machine, false otherwise. |restored_tabs| is a filtered tab-only
160 // pipeline that exists in the caller's context. This function will append 193 // subset of |sync_data| returned by this function for convenience.
161 // necessary changes for processing later. 194 // |new_changes| is a link to the SyncChange pipeline that exists in the
195 // caller's context. This function will append necessary changes for
196 // processing later.
162 bool InitFromSyncModel(const syncer::SyncDataList& sync_data, 197 bool InitFromSyncModel(const syncer::SyncDataList& sync_data,
198 syncer::SyncDataList* restored_tabs,
163 syncer::SyncChangeList* new_changes); 199 syncer::SyncChangeList* new_changes);
164 200
165 // Helper to construct a deletion SyncChange for a *tab node*. 201 // Helper to construct a deletion SyncChange for a *tab node*.
166 // Caller should check IsValid() on the returned change, as it's possible 202 // Caller should check IsValid() on the returned change, as it's possible
167 // this node could not be deleted. 203 // this node could not be deleted.
168 syncer::SyncChange TombstoneTab(const sync_pb::SessionSpecifics& tab); 204 syncer::SyncChange TombstoneTab(const sync_pb::SessionSpecifics& tab);
169 205
170 // Helper method to load the favicon data from the tab specifics. If the 206 // Helper method to load the favicon data from the tab specifics. If the
171 // favicon is valid, stores the favicon data into the favicon cache. 207 // favicon is valid, stores the favicon data into the favicon cache.
172 void RefreshFaviconVisitTimesFromForeignTab( 208 void RefreshFaviconVisitTimesFromForeignTab(
(...skipping 28 matching lines...) Expand all
201 sessions::SessionWindow* session_window); 237 sessions::SessionWindow* session_window);
202 238
203 // Resync local window information. Updates the local sessions header node 239 // Resync local window information. Updates the local sessions header node
204 // with the status of open windows and the order of tabs they contain. Should 240 // with the status of open windows and the order of tabs they contain. Should
205 // only be called for changes that affect a window, not a change within a 241 // only be called for changes that affect a window, not a change within a
206 // single tab. 242 // single tab.
207 // 243 //
208 // RELOAD_TABS will additionally cause a resync of all tabs (same as calling 244 // RELOAD_TABS will additionally cause a resync of all tabs (same as calling
209 // AssociateTabs with a vector of all tabs). 245 // AssociateTabs with a vector of all tabs).
210 // 246 //
247 // |restored_tabs| is a filtered tab-only subset of initial sync data, if
248 // available (during MergeDataAndStartSyncing). It can be used to obtain
249 // baseline SessionSpecifics for tabs we can't fully associate any other
250 // way because they don't yet have a WebContents.
251 //
211 // Returns: false if the local session's sync nodes were deleted and 252 // Returns: false if the local session's sync nodes were deleted and
212 // reassociation is necessary, true otherwise. 253 // reassociation is necessary, true otherwise.
213 // 254 //
214 // |change_output| *must* be provided as a link to the SyncChange pipeline 255 // |change_output| *must* be provided as a link to the SyncChange pipeline
215 // that exists in the caller's context. This function will append necessary 256 // that exists in the caller's context. This function will append necessary
216 // changes for processing later. 257 // changes for processing later.
217 enum ReloadTabsOption { RELOAD_TABS, DONT_RELOAD_TABS }; 258 enum ReloadTabsOption { RELOAD_TABS, DONT_RELOAD_TABS };
218 void AssociateWindows(ReloadTabsOption option, 259 void AssociateWindows(ReloadTabsOption option,
260 const syncer::SyncDataList& restored_tabs,
219 syncer::SyncChangeList* change_output); 261 syncer::SyncChangeList* change_output);
220 262
221 // Loads and reassociates the local tabs referenced in |tabs|. 263 // Loads and reassociates the local tabs referenced in |tabs|.
222 // |change_output| *must* be provided as a link to the SyncChange pipeline 264 // |change_output| *must* be provided as a link to the SyncChange pipeline
223 // that exists in the caller's context. This function will append necessary 265 // that exists in the caller's context. This function will append necessary
224 // changes for processing later. 266 // changes for processing later.
225 void AssociateTab(SyncedTabDelegate* const tab, 267 void AssociateTab(SyncedTabDelegate* const tab,
226 syncer::SyncChangeList* change_output); 268 syncer::SyncChangeList* change_output);
227 269
228 // Set |session_tab| from |tab_delegate| and |mtime|. 270 // Set |session_tab| from |tab_delegate| and |mtime|.
229 void SetSessionTabFromDelegate(const SyncedTabDelegate& tab_delegate, 271 void SetSessionTabFromDelegate(const SyncedTabDelegate& tab_delegate,
230 base::Time mtime, 272 base::Time mtime,
231 sessions::SessionTab* session_tab); 273 sessions::SessionTab* session_tab);
232 274
233 // Sets |variation_ids| field of |session_tab| with the ids of the currently 275 // Sets |variation_ids| field of |session_tab| with the ids of the currently
234 // assigned variations which should be sent to sync. 276 // assigned variations which should be sent to sync.
235 static void SetVariationIds(sessions::SessionTab* session_tab); 277 static void SetVariationIds(sessions::SessionTab* session_tab);
236 278
237 // Populates |specifics| based on the data in |tab_delegate|. 279 // Populates |specifics| based on the data in |tab_delegate|.
238 void LocalTabDelegateToSpecifics(const SyncedTabDelegate& tab_delegate, 280 void LocalTabDelegateToSpecifics(const SyncedTabDelegate& tab_delegate,
239 sync_pb::SessionSpecifics* specifics); 281 sync_pb::SessionSpecifics* specifics);
240 282
241 // It's possible that when we associate windows, tabs aren't all loaded 283 // It's possible that when we associate windows, tabs aren't all loaded
242 // into memory yet (e.g on android) and we don't have a WebContents. In this 284 // into memory yet (e.g on android) and we don't have a WebContents. In this
243 // case we can't do a full association, but we still want to update tab IDs 285 // case we can't do a full association, but we still want to update tab IDs
244 // as they may have changed after a session was restored. This method 286 // as they may have changed after a session was restored. This method
245 // compares new_tab_id and new_window_id against the previously persisted tab 287 // compares new_tab_id and new_window_id against the previously persisted tab
246 // ID and window ID (from our TabNodePool) and updates them if either differs. 288 // ID and window ID (from our TabNodePool) and updates them if either differs.
289 // |restored_tabs| is a filtered tab-only subset of initial sync data, if
290 // available (during MergeDataAndStartSyncing). It can be used to obtain
291 // baseline SessionSpecifics for tabs we can't fully associate any other
292 // way because they don't yet have a WebContents.
293 // TODO(tim): Bug 98892. We should be able to test this for this on android
294 // even though we didn't have tests for old API-based sessions sync.
247 void AssociateRestoredPlaceholderTab( 295 void AssociateRestoredPlaceholderTab(
248 const SyncedTabDelegate& tab_delegate, 296 const SyncedTabDelegate& tab_delegate,
249 SessionID::id_type new_tab_id, 297 SessionID::id_type new_tab_id,
250 SessionID::id_type new_window_id, 298 SessionID::id_type new_window_id,
299 const syncer::SyncDataList& restored_tabs,
251 syncer::SyncChangeList* change_output); 300 syncer::SyncChangeList* change_output);
252 301
253 // Stops and re-starts syncing to rebuild association mappings. Returns true 302 // Stops and re-starts syncing to rebuild association mappings. Returns true
254 // when re-starting succeeds. 303 // when re-starting succeeds.
255 // See |local_tab_pool_out_of_sync_|. 304 // See |local_tab_pool_out_of_sync_|.
256 bool RebuildAssociations(); 305 bool RebuildAssociations();
257 306
258 // Validates the content of a SessionHeader protobuf. 307 // Validates the content of a SessionHeader protobuf.
259 // Returns false if validation fails. 308 // Returns false if validation fails.
260 static bool IsValidSessionHeader(const sync_pb::SessionHeader& header); 309 static bool IsValidSessionHeader(const sync_pb::SessionHeader& header);
261 310
262 // Calculates the tag hash from a specifics object. Calculating the hash is 311 // Calculates the tag hash from a specifics object. Calculating the hash is
263 // something we typically want to avoid doing in the model type like this. 312 // something we typically want to avoid doing in the model type like this.
264 // However, the only place that understands how to generate a tag from the 313 // However, the only place that understands how to generate a tag from the
265 // specifics is the model type, ie us. We need to generate the tag because it 314 // specifics is the model type, ie us. We need to generate the tag because it
266 // is not passed over the wire for remote data. The use case this function was 315 // is not passed over the wire for remote data. The use case this function was
267 // created for is detecting bad tag hashes from remote data, see 316 // created for is detecting bad tag hashes from remote data, see
268 // crbug.com/604657. 317 // crbug.com/604657.
269 static std::string TagHashFromSpecifics( 318 static std::string TagHashFromSpecifics(
270 const sync_pb::SessionSpecifics& specifics); 319 const sync_pb::SessionSpecifics& specifics);
271 320
272 SyncedWindowDelegatesGetter* synced_window_delegates_getter() const; 321 SyncedWindowDelegatesGetter* synced_window_delegates_getter() const;
273 322
274 // The client of this sync sessions datatype. 323 // The client of this sync sessions datatype.
275 SyncSessionsClient* const sessions_client_; 324 SyncSessionsClient* const sessions_client_;
276 325
326 // Mapping of current open (local) tabs to their sync identifiers.
327 TabLinksMap local_tab_map_;
328
277 SyncedSessionTracker session_tracker_; 329 SyncedSessionTracker session_tracker_;
278 FaviconCache favicon_cache_; 330 FaviconCache favicon_cache_;
279 331
332 // Pool of used/available sync nodes associated with local tabs.
333 TabNodePool local_tab_pool_;
334
280 // Tracks whether our local representation of which sync nodes map to what 335 // Tracks whether our local representation of which sync nodes map to what
281 // tabs (belonging to the current local session) is inconsistent. This can 336 // tabs (belonging to the current local session) is inconsistent. This can
282 // happen if a foreign client deems our session as "stale" and decides to 337 // happen if a foreign client deems our session as "stale" and decides to
283 // delete it. Rather than respond by bullishly re-creating our nodes 338 // delete it. Rather than respond by bullishly re-creating our nodes
284 // immediately, which could lead to ping-pong sequences, we give the benefit 339 // immediately, which could lead to ping-pong sequences, we give the benefit
285 // of the doubt and hold off until another local navigation occurs, which 340 // of the doubt and hold off until another local navigation occurs, which
286 // proves that we are still relevant. 341 // proves that we are still relevant.
287 bool local_tab_pool_out_of_sync_; 342 bool local_tab_pool_out_of_sync_;
288 343
289 syncer::SyncPrefs* sync_prefs_; 344 syncer::SyncPrefs* sync_prefs_;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 377
323 // Callback to inform sync that a sync data refresh is requested. 378 // Callback to inform sync that a sync data refresh is requested.
324 base::Closure datatype_refresh_callback_; 379 base::Closure datatype_refresh_callback_;
325 380
326 DISALLOW_COPY_AND_ASSIGN(SessionsSyncManager); 381 DISALLOW_COPY_AND_ASSIGN(SessionsSyncManager);
327 }; 382 };
328 383
329 } // namespace sync_sessions 384 } // namespace sync_sessions
330 385
331 #endif // COMPONENTS_SYNC_SESSIONS_SESSIONS_SYNC_MANAGER_H_ 386 #endif // COMPONENTS_SYNC_SESSIONS_SESSIONS_SYNC_MANAGER_H_
OLDNEW
« 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