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 // A local navigation occurred that triggered updates to favicon data for | |
60 // each URL in |updated_page_urls|. This is routed through Sessions Sync so | |
61 // that we can filter (exclude) favicon updates for pages that aren't | |
62 // currently part of the set of local open tabs, and pass relevant updates | |
63 // on to FaviconCache for out-of-band favicon syncing. | |
64 virtual void OnFaviconPageUrlsUpdated( | |
65 const std::set<GURL>& updated_page_urls) = 0; | |
66 }; | |
67 | |
68 // The LocalSessionEventRouter is responsible for hooking itself up to various | |
69 // notification sources in the browser process and forwarding relevant | |
70 // events to a handler as defined in the LocalSessionEventHandler contract. | |
71 class LocalSessionEventRouter { | |
72 public: | |
73 virtual ~LocalSessionEventRouter(); | |
74 virtual void StartRoutingTo(LocalSessionEventHandler* handler) = 0; | |
75 virtual void Stop() = 0; | |
76 }; | |
77 | |
48 // Contains all logic for associating the Chrome sessions model and | 78 // Contains all logic for associating the Chrome sessions model and |
49 // the sync sessions model. | 79 // the sync sessions model. |
50 class SessionsSyncManager : public syncer::SyncableService, | 80 class SessionsSyncManager : public syncer::SyncableService, |
51 public OpenTabsUIDelegate { | 81 public OpenTabsUIDelegate, |
82 public LocalSessionEventHandler { | |
52 public: | 83 public: |
53 // Isolates SessionsSyncManager from having to depend on sync internals. | 84 // Isolates SessionsSyncManager from having to depend on sync internals. |
54 class SyncInternalApiDelegate { | 85 class SyncInternalApiDelegate { |
55 public: | 86 public: |
87 virtual ~SyncInternalApiDelegate() {} | |
Nicolas Zea
2013/12/02 21:41:33
nit: newline after
tim (not reviewing)
2013/12/02 23:01:45
Done.
| |
56 // Returns sync's representation of the local device info. | 88 // Returns sync's representation of the local device info. |
57 // Return value is an empty scoped_ptr if the device info is unavailable. | 89 // Return value is an empty scoped_ptr if the device info is unavailable. |
58 virtual scoped_ptr<DeviceInfo> GetLocalDeviceInfo() const = 0; | 90 virtual scoped_ptr<DeviceInfo> GetLocalDeviceInfo() const = 0; |
59 | 91 |
60 // Used for creation of the machine tag for this local session. | 92 // Used for creation of the machine tag for this local session. |
61 virtual std::string GetLocalSyncCacheGUID() const = 0; | 93 virtual std::string GetLocalSyncCacheGUID() const = 0; |
62 }; | 94 }; |
63 | 95 |
64 SessionsSyncManager(Profile* profile, | 96 SessionsSyncManager(Profile* profile, |
65 SyncInternalApiDelegate* delegate); | 97 SyncInternalApiDelegate* delegate, |
98 scoped_ptr<LocalSessionEventRouter> router); | |
66 virtual ~SessionsSyncManager(); | 99 virtual ~SessionsSyncManager(); |
67 | 100 |
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. | 101 // syncer::SyncableService implementation. |
93 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( | 102 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
94 syncer::ModelType type, | 103 syncer::ModelType type, |
95 const syncer::SyncDataList& initial_sync_data, | 104 const syncer::SyncDataList& initial_sync_data, |
96 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 105 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
97 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; | 106 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; |
98 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; | 107 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; |
99 virtual syncer::SyncDataList GetAllSyncData( | 108 virtual syncer::SyncDataList GetAllSyncData( |
100 syncer::ModelType type) const OVERRIDE; | 109 syncer::ModelType type) const OVERRIDE; |
101 virtual syncer::SyncError ProcessSyncChanges( | 110 virtual syncer::SyncError ProcessSyncChanges( |
102 const tracked_objects::Location& from_here, | 111 const tracked_objects::Location& from_here, |
103 const syncer::SyncChangeList& change_list) OVERRIDE; | 112 const syncer::SyncChangeList& change_list) OVERRIDE; |
104 | 113 |
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. | 114 // OpenTabsUIDelegate implementation. |
114 virtual bool GetSyncedFaviconForPageURL( | 115 virtual bool GetSyncedFaviconForPageURL( |
115 const std::string& pageurl, | 116 const std::string& pageurl, |
116 scoped_refptr<base::RefCountedMemory>* favicon_png) const OVERRIDE; | 117 scoped_refptr<base::RefCountedMemory>* favicon_png) const OVERRIDE; |
117 virtual bool GetAllForeignSessions( | 118 virtual bool GetAllForeignSessions( |
118 std::vector<const SyncedSession*>* sessions) OVERRIDE; | 119 std::vector<const SyncedSession*>* sessions) OVERRIDE; |
119 virtual bool GetForeignSession( | 120 virtual bool GetForeignSession( |
120 const std::string& tag, | 121 const std::string& tag, |
121 std::vector<const SessionWindow*>* windows) OVERRIDE; | 122 std::vector<const SessionWindow*>* windows) OVERRIDE; |
122 virtual bool GetForeignTab(const std::string& tag, | 123 virtual bool GetForeignTab(const std::string& tag, |
123 const SessionID::id_type tab_id, | 124 const SessionID::id_type tab_id, |
124 const SessionTab** tab) OVERRIDE; | 125 const SessionTab** tab) OVERRIDE; |
125 virtual void DeleteForeignSession(const std::string& tag) OVERRIDE; | 126 virtual void DeleteForeignSession(const std::string& tag) OVERRIDE; |
126 | 127 |
128 // LocalSessionEventHandler implementation. | |
129 virtual void OnLocalTabModified(SyncedTabDelegate* modified_tab) OVERRIDE; | |
130 virtual void OnFaviconPageUrlsUpdated( | |
131 const std::set<GURL>& updated_favicon_page_urls) OVERRIDE; | |
132 | |
133 // Returns the tag used to uniquely identify this machine's session in the | |
134 // sync model. | |
135 const std::string& current_machine_tag() const { | |
136 DCHECK(!current_machine_tag_.empty()); | |
137 return current_machine_tag_; | |
138 } | |
139 | |
140 // Return the virtual URL of the current tab, even if it's pending. | |
141 static GURL GetCurrentVirtualURL(const SyncedTabDelegate& tab_delegate); | |
142 | |
143 // Return the favicon url of the current tab, even if it's pending. | |
144 static GURL GetCurrentFaviconURL(const SyncedTabDelegate& tab_delegate); | |
145 | |
146 FaviconCache* GetFaviconCache(); | |
147 | |
127 private: | 148 private: |
128 // Keep all the links to local tab data in one place. A tab_node_id and tab | 149 // 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 | 150 // must be passed at creation. The tab_node_id is not mutable, although |
130 // all other fields are. | 151 // all other fields are. |
131 class TabLink { | 152 class TabLink { |
132 public: | 153 public: |
133 TabLink(int tab_node_id, const SyncedTabDelegate* tab) | 154 TabLink(int tab_node_id, const SyncedTabDelegate* tab) |
134 : tab_node_id_(tab_node_id), | 155 : tab_node_id_(tab_node_id), |
135 tab_(tab) {} | 156 tab_(tab) {} |
136 | 157 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 // Unique client tag. | 322 // Unique client tag. |
302 std::string current_machine_tag_; | 323 std::string current_machine_tag_; |
303 | 324 |
304 // User-visible machine name. | 325 // User-visible machine name. |
305 std::string current_session_name_; | 326 std::string current_session_name_; |
306 | 327 |
307 // SyncID for the sync node containing all the window information for this | 328 // SyncID for the sync node containing all the window information for this |
308 // client. | 329 // client. |
309 int local_session_header_node_id_; | 330 int local_session_header_node_id_; |
310 | 331 |
332 scoped_ptr<LocalSessionEventRouter> local_event_router_; | |
333 | |
311 DISALLOW_COPY_AND_ASSIGN(SessionsSyncManager); | 334 DISALLOW_COPY_AND_ASSIGN(SessionsSyncManager); |
312 }; | 335 }; |
313 | 336 |
314 } // namespace browser_sync | 337 } // namespace browser_sync |
315 | 338 |
316 #endif // CHROME_BROWSER_SYNC_SESSIONS2_SESSIONS_SYNC_MANAGER_H_ | 339 #endif // CHROME_BROWSER_SYNC_SESSIONS2_SESSIONS_SYNC_MANAGER_H_ |
OLD | NEW |