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 #include <stdint.h> |
9 | 10 |
10 #include <map> | 11 #include <map> |
11 #include <memory> | 12 #include <memory> |
12 #include <set> | 13 #include <set> |
13 #include <string> | 14 #include <string> |
14 #include <vector> | 15 #include <vector> |
15 | 16 |
16 #include "base/callback_forward.h" | 17 #include "base/callback_forward.h" |
17 #include "base/gtest_prod_util.h" | 18 #include "base/gtest_prod_util.h" |
18 #include "base/macros.h" | 19 #include "base/macros.h" |
19 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
21 #include "components/sessions/core/session_id.h" | 22 #include "components/sessions/core/session_id.h" |
22 #include "components/sessions/core/session_types.h" | 23 #include "components/sessions/core/session_types.h" |
23 #include "components/sync/base/sync_prefs.h" | 24 #include "components/sync/base/sync_prefs.h" |
24 #include "components/sync/device_info/device_info.h" | 25 #include "components/sync/device_info/device_info.h" |
25 #include "components/sync/model/syncable_service.h" | 26 #include "components/sync/model/syncable_service.h" |
| 27 #include "components/sync/user_events/global_id_mapper.h" |
26 #include "components/sync_sessions/favicon_cache.h" | 28 #include "components/sync_sessions/favicon_cache.h" |
27 #include "components/sync_sessions/local_session_event_router.h" | 29 #include "components/sync_sessions/local_session_event_router.h" |
28 #include "components/sync_sessions/lost_navigations_recorder.h" | 30 #include "components/sync_sessions/lost_navigations_recorder.h" |
29 #include "components/sync_sessions/open_tabs_ui_delegate.h" | 31 #include "components/sync_sessions/open_tabs_ui_delegate.h" |
30 #include "components/sync_sessions/revisit/page_revisit_broadcaster.h" | 32 #include "components/sync_sessions/revisit/page_revisit_broadcaster.h" |
31 #include "components/sync_sessions/synced_session.h" | 33 #include "components/sync_sessions/synced_session.h" |
32 #include "components/sync_sessions/synced_session_tracker.h" | 34 #include "components/sync_sessions/synced_session_tracker.h" |
33 #include "components/sync_sessions/task_tracker.h" | 35 #include "components/sync_sessions/task_tracker.h" |
34 | 36 |
35 namespace syncer { | 37 namespace syncer { |
(...skipping 15 matching lines...) Expand all Loading... |
51 | 53 |
52 namespace sync_sessions { | 54 namespace sync_sessions { |
53 | 55 |
54 class SyncedTabDelegate; | 56 class SyncedTabDelegate; |
55 class SyncedWindowDelegatesGetter; | 57 class SyncedWindowDelegatesGetter; |
56 | 58 |
57 // Contains all logic for associating the Chrome sessions model and | 59 // Contains all logic for associating the Chrome sessions model and |
58 // the sync sessions model. | 60 // the sync sessions model. |
59 class SessionsSyncManager : public syncer::SyncableService, | 61 class SessionsSyncManager : public syncer::SyncableService, |
60 public OpenTabsUIDelegate, | 62 public OpenTabsUIDelegate, |
61 public LocalSessionEventHandler { | 63 public LocalSessionEventHandler, |
| 64 public syncer::GlobalIdMapper { |
62 public: | 65 public: |
63 SessionsSyncManager(SyncSessionsClient* sessions_client, | 66 SessionsSyncManager(SyncSessionsClient* sessions_client, |
64 syncer::SyncPrefs* sync_prefs, | 67 syncer::SyncPrefs* sync_prefs, |
65 syncer::LocalDeviceInfoProvider* local_device, | 68 syncer::LocalDeviceInfoProvider* local_device, |
66 LocalSessionEventRouter* router, | 69 LocalSessionEventRouter* router, |
67 const base::Closure& sessions_updated_callback, | 70 const base::Closure& sessions_updated_callback, |
68 const base::Closure& datatype_refresh_callback); | 71 const base::Closure& datatype_refresh_callback); |
69 ~SessionsSyncManager() override; | 72 ~SessionsSyncManager() override; |
70 | 73 |
71 // syncer::SyncableService implementation. | 74 // syncer::SyncableService implementation. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 return current_machine_tag_; | 113 return current_machine_tag_; |
111 } | 114 } |
112 | 115 |
113 FaviconCache* GetFaviconCache(); | 116 FaviconCache* GetFaviconCache(); |
114 | 117 |
115 // Triggers garbage collection of stale sessions (as defined by | 118 // Triggers garbage collection of stale sessions (as defined by |
116 // |stale_session_threshold_days_|). This is called every time we see new | 119 // |stale_session_threshold_days_|). This is called every time we see new |
117 // sessions data downloaded (sync cycles complete). | 120 // sessions data downloaded (sync cycles complete). |
118 void DoGarbageCollection(); | 121 void DoGarbageCollection(); |
119 | 122 |
| 123 // GlobalIdMapper implementation. |
| 124 void AddGlobalIdChangeObserver(syncer::GlobalIdChange callback) override; |
| 125 int64_t GetLatestGlobalId(int64_t global_id) override; |
| 126 |
120 private: | 127 private: |
121 friend class extensions::ExtensionSessionsTest; | 128 friend class extensions::ExtensionSessionsTest; |
122 friend class SessionsSyncManagerTest; | 129 friend class SessionsSyncManagerTest; |
123 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, PopulateSyncedSession); | 130 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, PopulateSyncedSession); |
124 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, PopulateSessionWindow); | 131 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, PopulateSessionWindow); |
125 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, ValidTabs); | 132 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, ValidTabs); |
126 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, SetSessionTabFromDelegate); | 133 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, SetSessionTabFromDelegate); |
127 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, | 134 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, |
128 SetSessionTabFromDelegateNavigationIndex); | 135 SetSessionTabFromDelegateNavigationIndex); |
129 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, | 136 FRIEND_TEST_ALL_PREFIXES(SessionsSyncManagerTest, |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 // However, the only place that understands how to generate a tag from the | 281 // However, the only place that understands how to generate a tag from the |
275 // specifics is the model type, ie us. We need to generate the tag because it | 282 // specifics is the model type, ie us. We need to generate the tag because it |
276 // is not passed over the wire for remote data. The use case this function was | 283 // is not passed over the wire for remote data. The use case this function was |
277 // created for is detecting bad tag hashes from remote data, see | 284 // created for is detecting bad tag hashes from remote data, see |
278 // crbug.com/604657. | 285 // crbug.com/604657. |
279 static std::string TagHashFromSpecifics( | 286 static std::string TagHashFromSpecifics( |
280 const sync_pb::SessionSpecifics& specifics); | 287 const sync_pb::SessionSpecifics& specifics); |
281 | 288 |
282 SyncedWindowDelegatesGetter* synced_window_delegates_getter() const; | 289 SyncedWindowDelegatesGetter* synced_window_delegates_getter() const; |
283 | 290 |
| 291 void TrackNavigationIds(const sessions::SerializedNavigationEntry& current); |
| 292 |
| 293 void CleanupNavigationTracking(); |
| 294 |
284 // The client of this sync sessions datatype. | 295 // The client of this sync sessions datatype. |
285 SyncSessionsClient* const sessions_client_; | 296 SyncSessionsClient* const sessions_client_; |
286 | 297 |
287 SyncedSessionTracker session_tracker_; | 298 SyncedSessionTracker session_tracker_; |
288 FaviconCache favicon_cache_; | 299 FaviconCache favicon_cache_; |
289 | 300 |
290 // Tracks whether our local representation of which sync nodes map to what | 301 // Tracks whether our local representation of which sync nodes map to what |
291 // tabs (belonging to the current local session) is inconsistent. This can | 302 // tabs (belonging to the current local session) is inconsistent. This can |
292 // happen if a foreign client deems our session as "stale" and decides to | 303 // happen if a foreign client deems our session as "stale" and decides to |
293 // delete it. Rather than respond by bullishly re-creating our nodes | 304 // delete it. Rather than respond by bullishly re-creating our nodes |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 // Callback to inform interested observer that new sessions data has arrived. | 341 // Callback to inform interested observer that new sessions data has arrived. |
331 base::Closure sessions_updated_callback_; | 342 base::Closure sessions_updated_callback_; |
332 | 343 |
333 // Callback to inform sync that a sync data refresh is requested. | 344 // Callback to inform sync that a sync data refresh is requested. |
334 base::Closure datatype_refresh_callback_; | 345 base::Closure datatype_refresh_callback_; |
335 | 346 |
336 // Tracks Chrome Tasks, which associates navigations, with tab and navigation | 347 // Tracks Chrome Tasks, which associates navigations, with tab and navigation |
337 // changes of current session. | 348 // changes of current session. |
338 std::unique_ptr<TaskTracker> task_tracker_; | 349 std::unique_ptr<TaskTracker> task_tracker_; |
339 | 350 |
| 351 // Used to track global_ids that should be used when referencing various |
| 352 // pieces of sessions data, and notify observer when things have changed. |
| 353 std::map<int64_t, int> global_to_unique_; |
| 354 std::map<int, int64_t> unique_to_current_global_; |
| 355 std::vector<syncer::GlobalIdChange> global_id_change_observers_; |
| 356 |
340 DISALLOW_COPY_AND_ASSIGN(SessionsSyncManager); | 357 DISALLOW_COPY_AND_ASSIGN(SessionsSyncManager); |
341 }; | 358 }; |
342 | 359 |
343 } // namespace sync_sessions | 360 } // namespace sync_sessions |
344 | 361 |
345 #endif // COMPONENTS_SYNC_SESSIONS_SESSIONS_SYNC_MANAGER_H_ | 362 #endif // COMPONENTS_SYNC_SESSIONS_SESSIONS_SYNC_MANAGER_H_ |
OLD | NEW |