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

Side by Side Diff: chrome/browser/sync/sessions2/sessions_sync_manager.h

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

Powered by Google App Engine
This is Rietveld 408576698