OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROME_BROWSER_SYNC_SESSIONS2_SESSIONS_SYNC_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_SESSIONS2_SESSIONS_SYNC_MANAGER_H_ |
6 #define CHROME_BROWSER_SYNC_SESSIONS2_SESSIONS_SYNC_MANAGER_H_ | 6 #define CHROME_BROWSER_SYNC_SESSIONS2_SESSIONS_SYNC_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
16 #include "base/memory/weak_ptr.h" | |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "chrome/browser/sessions/session_id.h" | 18 #include "chrome/browser/sessions/session_id.h" |
18 #include "chrome/browser/sessions/session_types.h" | 19 #include "chrome/browser/sessions/session_types.h" |
19 #include "chrome/browser/sync/glue/device_info.h" | 20 #include "chrome/browser/sync/glue/device_info.h" |
20 #include "chrome/browser/sync/glue/favicon_cache.h" | 21 #include "chrome/browser/sync/glue/favicon_cache.h" |
21 #include "chrome/browser/sync/glue/synced_session.h" | 22 #include "chrome/browser/sync/glue/synced_session.h" |
22 #include "chrome/browser/sync/glue/synced_session_tracker.h" | 23 #include "chrome/browser/sync/glue/synced_session_tracker.h" |
23 #include "chrome/browser/sync/open_tabs_ui_delegate.h" | 24 #include "chrome/browser/sync/open_tabs_ui_delegate.h" |
24 #include "chrome/browser/sync/sessions2/tab_node_pool2.h" | 25 #include "chrome/browser/sync/sessions2/tab_node_pool2.h" |
25 #include "chrome/browser/sync/sync_prefs.h" | 26 #include "chrome/browser/sync/sync_prefs.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
38 class SessionWindow; | 39 class SessionWindow; |
39 class TabNavigation; | 40 class TabNavigation; |
40 } // namespace sync_pb | 41 } // namespace sync_pb |
41 | 42 |
42 namespace browser_sync { | 43 namespace browser_sync { |
43 | 44 |
44 class DataTypeErrorHandler; | 45 class DataTypeErrorHandler; |
45 class SyncedTabDelegate; | 46 class SyncedTabDelegate; |
46 class SyncedWindowDelegate; | 47 class SyncedWindowDelegate; |
47 | 48 |
49 // An interface defining the ways in which local open tab events can interact | |
50 // with session sync. All local tab events flow to sync via this interface. | |
51 // In that way it is analogous to sync changes flowing to the local model | |
52 // via ProcessSyncChanges, just with a more granular breakdown. | |
53 class LocalSessionEventHandler { | |
54 public: | |
55 // A local navigation event took place that affects the synced session | |
56 // for this instance of Chrome. | |
57 virtual void OnLocalTabModified(SyncedTabDelegate* modified_tab) = 0; | |
58 | |
59 // When a Browser window is opened, we want to know so we can make sure our | |
60 // bookkeeping of open windows / sessions on this device is up-to-date. | |
61 virtual void OnBrowserOpened() = 0; | |
Nicolas Zea
2013/11/21 02:34:52
Is this necessary? We always reassociate windows a
tim (not reviewing)
2013/11/21 21:38:59
I could maybe change it to OnBrowserModified(Synce
Nicolas Zea
2013/11/22 23:34:51
How about two methods, with the second method bein
tim (not reviewing)
2013/11/25 18:12:08
As discussed, went ahead and removed OnBrowserOpen
| |
62 | |
63 // A local navigation occurred that triggered updates to favicon data for | |
64 // each URL in |updated_page_urls|. This is routed through Sessions Sync so | |
65 // that we can filter (exclude) favicon updates for pages that aren't | |
66 // currently part of the set of local open tabs, and pass relevant updates | |
67 // on to FaviconCache for out-of-band favicon syncing. | |
68 virtual void OnFaviconPageUrlsUpdated( | |
69 const std::set<GURL>& updated_page_urls) = 0; | |
70 }; | |
71 | |
48 // Contains all logic for associating the Chrome sessions model and | 72 // Contains all logic for associating the Chrome sessions model and |
49 // the sync sessions model. | 73 // the sync sessions model. |
50 class SessionsSyncManager : public syncer::SyncableService, | 74 class SessionsSyncManager : public syncer::SyncableService, |
51 public OpenTabsUIDelegate { | 75 public OpenTabsUIDelegate, |
76 public LocalSessionEventHandler { | |
52 public: | 77 public: |
53 // Isolates SessionsSyncManager from having to depend on sync internals. | 78 // Isolates SessionsSyncManager from having to depend on sync internals. |
54 class SyncInternalApiDelegate { | 79 class SyncInternalApiDelegate { |
55 public: | 80 public: |
81 virtual ~SyncInternalApiDelegate() {} | |
Nicolas Zea
2013/11/21 02:34:52
nit: newline after
tim (not reviewing)
2013/11/21 21:38:59
Done.
| |
56 // Returns sync's representation of the local device info. | 82 // Returns sync's representation of the local device info. |
57 // Return value is an empty scoped_ptr if the device info is unavailable. | 83 // Return value is an empty scoped_ptr if the device info is unavailable. |
58 virtual scoped_ptr<DeviceInfo> GetLocalDeviceInfo() const = 0; | 84 virtual scoped_ptr<DeviceInfo> GetLocalDeviceInfo() const = 0; |
59 | 85 |
60 // Used for creation of the machine tag for this local session. | 86 // Used for creation of the machine tag for this local session. |
61 virtual std::string GetLocalSyncCacheGUID() const = 0; | 87 virtual std::string GetLocalSyncCacheGUID() const = 0; |
62 }; | 88 }; |
63 | 89 |
90 // The LocalEventRouter is responsible for hooking itself up to various | |
91 // notification sources in the browser process and forwarding relevant | |
92 // events to a handler as defined in the LocalSessionEventHandler contract. | |
93 class LocalEventRouter { | |
94 public: | |
95 virtual ~LocalEventRouter() {} | |
96 virtual void StartRoutingTo(LocalSessionEventHandler* handler) = 0; | |
97 virtual void Stop() = 0; | |
98 }; | |
99 | |
64 SessionsSyncManager(Profile* profile, | 100 SessionsSyncManager(Profile* profile, |
65 SyncInternalApiDelegate* delegate); | 101 SyncInternalApiDelegate* delegate, |
102 scoped_ptr<LocalEventRouter> router); | |
66 virtual ~SessionsSyncManager(); | 103 virtual ~SessionsSyncManager(); |
67 | 104 |
68 // A local navigation event took place that affects the synced session | |
69 // for this instance of Chrome. | |
70 void OnLocalTabModified(const SyncedTabDelegate& modified_tab, | |
71 syncer::SyncError* error); | |
72 | |
73 // When a Browser window is opened, we want to know so we can make sure our | |
74 // bookkeeping of open windows / sessions on this device is up-to-date. | |
75 void OnBrowserOpened(); | |
76 | |
77 // A local navigation occurred that triggered updates to favicon data for | |
78 // each URL in |updated_page_urls|. This is routed through Sessions Sync so | |
79 // that we can filter (exclude) favicon updates for pages that aren't | |
80 // currently part of the set of local open tabs, and pass relevant updates | |
81 // on to FaviconCache for out-of-band favicon syncing. | |
82 void ForwardRelevantFaviconUpdatesToFaviconCache( | |
83 const std::set<GURL>& updated_favicon_page_urls); | |
84 | |
85 // Returns the tag used to uniquely identify this machine's session in the | |
86 // sync model. | |
87 const std::string& current_machine_tag() const { | |
88 DCHECK(!current_machine_tag_.empty()); | |
89 return current_machine_tag_; | |
90 } | |
91 | |
92 // syncer::SyncableService implementation. | 105 // syncer::SyncableService implementation. |
93 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( | 106 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
94 syncer::ModelType type, | 107 syncer::ModelType type, |
95 const syncer::SyncDataList& initial_sync_data, | 108 const syncer::SyncDataList& initial_sync_data, |
96 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 109 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
97 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; | 110 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; |
98 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; | 111 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; |
99 virtual syncer::SyncDataList GetAllSyncData( | 112 virtual syncer::SyncDataList GetAllSyncData( |
100 syncer::ModelType type) const OVERRIDE; | 113 syncer::ModelType type) const OVERRIDE; |
101 virtual syncer::SyncError ProcessSyncChanges( | 114 virtual syncer::SyncError ProcessSyncChanges( |
102 const tracked_objects::Location& from_here, | 115 const tracked_objects::Location& from_here, |
103 const syncer::SyncChangeList& change_list) OVERRIDE; | 116 const syncer::SyncChangeList& change_list) OVERRIDE; |
104 | 117 |
105 // Return the virtual URL of the current tab, even if it's pending. | |
106 static GURL GetCurrentVirtualURL(const SyncedTabDelegate& tab_delegate); | |
107 | |
108 // Return the favicon url of the current tab, even if it's pending. | |
109 static GURL GetCurrentFaviconURL(const SyncedTabDelegate& tab_delegate); | |
110 | |
111 FaviconCache* GetFaviconCache(); | |
112 | |
113 // OpenTabsUIDelegate implementation. | 118 // OpenTabsUIDelegate implementation. |
114 virtual bool GetSyncedFaviconForPageURL( | 119 virtual bool GetSyncedFaviconForPageURL( |
115 const std::string& pageurl, | 120 const std::string& pageurl, |
116 scoped_refptr<base::RefCountedMemory>* favicon_png) const OVERRIDE; | 121 scoped_refptr<base::RefCountedMemory>* favicon_png) const OVERRIDE; |
117 virtual bool GetAllForeignSessions( | 122 virtual bool GetAllForeignSessions( |
118 std::vector<const SyncedSession*>* sessions) OVERRIDE; | 123 std::vector<const SyncedSession*>* sessions) OVERRIDE; |
119 virtual bool GetForeignSession( | 124 virtual bool GetForeignSession( |
120 const std::string& tag, | 125 const std::string& tag, |
121 std::vector<const SessionWindow*>* windows) OVERRIDE; | 126 std::vector<const SessionWindow*>* windows) OVERRIDE; |
122 virtual bool GetForeignTab(const std::string& tag, | 127 virtual bool GetForeignTab(const std::string& tag, |
123 const SessionID::id_type tab_id, | 128 const SessionID::id_type tab_id, |
124 const SessionTab** tab) OVERRIDE; | 129 const SessionTab** tab) OVERRIDE; |
125 virtual void DeleteForeignSession(const std::string& tag) OVERRIDE; | 130 virtual void DeleteForeignSession(const std::string& tag) OVERRIDE; |
126 | 131 |
132 // LocalSessionEventHandler implementation. | |
133 virtual void OnLocalTabModified(SyncedTabDelegate* modified_tab) OVERRIDE; | |
134 virtual void OnBrowserOpened() OVERRIDE; | |
135 virtual void OnFaviconPageUrlsUpdated( | |
136 const std::set<GURL>& updated_favicon_page_urls) OVERRIDE; | |
137 | |
138 // Returns the tag used to uniquely identify this machine's session in the | |
139 // sync model. | |
140 const std::string& current_machine_tag() const { | |
141 DCHECK(!current_machine_tag_.empty()); | |
142 return current_machine_tag_; | |
143 } | |
144 | |
145 // Return the virtual URL of the current tab, even if it's pending. | |
146 static GURL GetCurrentVirtualURL(const SyncedTabDelegate& tab_delegate); | |
147 | |
148 // Return the favicon url of the current tab, even if it's pending. | |
149 static GURL GetCurrentFaviconURL(const SyncedTabDelegate& tab_delegate); | |
150 | |
151 FaviconCache* GetFaviconCache(); | |
152 | |
127 private: | 153 private: |
128 // Keep all the links to local tab data in one place. A tab_node_id and tab | 154 // Keep all the links to local tab data in one place. A tab_node_id and tab |
129 // must be passed at creation. The tab_node_id is not mutable, although | 155 // must be passed at creation. The tab_node_id is not mutable, although |
130 // all other fields are. | 156 // all other fields are. |
131 class TabLink { | 157 class TabLink { |
132 public: | 158 public: |
133 TabLink(int tab_node_id, const SyncedTabDelegate* tab) | 159 TabLink(int tab_node_id, const SyncedTabDelegate* tab) |
134 : tab_node_id_(tab_node_id), | 160 : tab_node_id_(tab_node_id), |
135 tab_(tab) {} | 161 tab_(tab) {} |
136 | 162 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 // Unique client tag. | 327 // Unique client tag. |
302 std::string current_machine_tag_; | 328 std::string current_machine_tag_; |
303 | 329 |
304 // User-visible machine name. | 330 // User-visible machine name. |
305 std::string current_session_name_; | 331 std::string current_session_name_; |
306 | 332 |
307 // SyncID for the sync node containing all the window information for this | 333 // SyncID for the sync node containing all the window information for this |
308 // client. | 334 // client. |
309 int local_session_header_node_id_; | 335 int local_session_header_node_id_; |
310 | 336 |
337 scoped_ptr<LocalEventRouter> local_event_router_; | |
338 | |
311 DISALLOW_COPY_AND_ASSIGN(SessionsSyncManager); | 339 DISALLOW_COPY_AND_ASSIGN(SessionsSyncManager); |
312 }; | 340 }; |
313 | 341 |
314 } // namespace browser_sync | 342 } // namespace browser_sync |
315 | 343 |
316 #endif // CHROME_BROWSER_SYNC_SESSIONS2_SESSIONS_SYNC_MANAGER_H_ | 344 #endif // CHROME_BROWSER_SYNC_SESSIONS2_SESSIONS_SYNC_MANAGER_H_ |
OLD | NEW |