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

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

Issue 74653002: sync: Add --enable-sync-sessions-v2 and necessary plumbing to use SessionsSyncManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 1 month 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/time/time.h" 16 #include "base/time/time.h"
17 #include "chrome/browser/sessions/session_id.h" 17 #include "chrome/browser/sessions/session_id.h"
18 #include "chrome/browser/sessions/session_types.h" 18 #include "chrome/browser/sessions/session_types.h"
19 #include "chrome/browser/sync/glue/device_info.h" 19 #include "chrome/browser/sync/glue/device_info.h"
20 #include "chrome/browser/sync/glue/favicon_cache.h" 20 #include "chrome/browser/sync/glue/favicon_cache.h"
21 #include "chrome/browser/sync/glue/synced_session.h" 21 #include "chrome/browser/sync/glue/synced_session.h"
22 #include "chrome/browser/sync/glue/synced_session_tracker.h" 22 #include "chrome/browser/sync/glue/synced_session_tracker.h"
23 #include "chrome/browser/sync/open_tabs_ui_delegate.h"
23 #include "chrome/browser/sync/sessions2/tab_node_pool2.h" 24 #include "chrome/browser/sync/sessions2/tab_node_pool2.h"
24 #include "chrome/browser/sync/sync_prefs.h" 25 #include "chrome/browser/sync/sync_prefs.h"
25 #include "sync/api/syncable_service.h" 26 #include "sync/api/syncable_service.h"
26 27
27 class Profile; 28 class Profile;
28 29
29 namespace syncer { 30 namespace syncer {
30 class SyncErrorFactory; 31 class SyncErrorFactory;
31 } 32 }
32 33
33 namespace sync_pb { 34 namespace sync_pb {
34 class SessionHeader; 35 class SessionHeader;
35 class SessionSpecifics; 36 class SessionSpecifics;
36 class SessionTab; 37 class SessionTab;
37 class SessionWindow; 38 class SessionWindow;
38 class TabNavigation; 39 class TabNavigation;
39 } // namespace sync_pb 40 } // namespace sync_pb
40 41
41 namespace browser_sync { 42 namespace browser_sync {
42 43
43 class DataTypeErrorHandler; 44 class DataTypeErrorHandler;
44 class SyncedTabDelegate; 45 class SyncedTabDelegate;
45 class SyncedWindowDelegate; 46 class SyncedWindowDelegate;
46 47
47 // Contains all logic for associating the Chrome sessions model and 48 // Contains all logic for associating the Chrome sessions model and
48 // the sync sessions model. 49 // the sync sessions model.
49 class SessionsSyncManager : public syncer::SyncableService { 50 class SessionsSyncManager : public syncer::SyncableService,
51 public OpenTabsUIDelegate {
50 public: 52 public:
51 // Isolates SessionsSyncManager from having to depend on sync internals. 53 // Isolates SessionsSyncManager from having to depend on sync internals.
52 class SyncInternalApiDelegate { 54 class SyncInternalApiDelegate {
53 public: 55 public:
54 // Returns sync's representation of the local device info. 56 // Returns sync's representation of the local device info.
55 // Return value is an empty scoped_ptr if the device info is unavailable. 57 // Return value is an empty scoped_ptr if the device info is unavailable.
56 virtual scoped_ptr<DeviceInfo> GetLocalDeviceInfo() const = 0; 58 virtual scoped_ptr<DeviceInfo> GetLocalDeviceInfo() const = 0;
57 59
58 // Used for creation of the machine tag for this local session. 60 // Used for creation of the machine tag for this local session.
59 virtual std::string GetCacheGuid() const = 0; 61 virtual std::string GetLocalSyncCacheGUID() const = 0;
60 }; 62 };
61 63
62 SessionsSyncManager(Profile* profile, 64 SessionsSyncManager(Profile* profile,
63 scoped_ptr<SyncPrefs> sync_prefs,
64 SyncInternalApiDelegate* delegate); 65 SyncInternalApiDelegate* delegate);
65 virtual ~SessionsSyncManager(); 66 virtual ~SessionsSyncManager();
66 67
67 // A local navigation event took place that affects the synced session 68 // A local navigation event took place that affects the synced session
68 // for this instance of Chrome. 69 // for this instance of Chrome.
69 void OnLocalTabModified(const SyncedTabDelegate& modified_tab, 70 void OnLocalTabModified(const SyncedTabDelegate& modified_tab,
70 syncer::SyncError* error); 71 syncer::SyncError* error);
71 72
72 // When a Browser window is opened, we want to know so we can make sure our 73 // When a Browser window is opened, we want to know so we can make sure our
73 // bookkeeping of open windows / sessions on this device is up-to-date. 74 // bookkeeping of open windows / sessions on this device is up-to-date.
74 void OnBrowserOpened(); 75 void OnBrowserOpened();
75 76
76 // A local navigation occurred that triggered updates to favicon data for 77 // A local navigation occurred that triggered updates to favicon data for
77 // each URL in |updated_page_urls|. This is routed through Sessions Sync so 78 // each URL in |updated_page_urls|. This is routed through Sessions Sync so
78 // that we can filter (exclude) favicon updates for pages that aren't 79 // that we can filter (exclude) favicon updates for pages that aren't
79 // currently part of the set of local open tabs, and pass relevant updates 80 // currently part of the set of local open tabs, and pass relevant updates
80 // on to FaviconCache for out-of-band favicon syncing. 81 // on to FaviconCache for out-of-band favicon syncing.
81 void ForwardRelevantFaviconUpdatesToFaviconCache( 82 void ForwardRelevantFaviconUpdatesToFaviconCache(
82 const std::set<GURL>& updated_favicon_page_urls); 83 const std::set<GURL>& updated_favicon_page_urls);
83 84
84 // Returns the tag used to uniquely identify this machine's session in the 85 // Returns the tag used to uniquely identify this machine's session in the
85 // sync model. 86 // sync model.
86 const std::string& current_machine_tag() const { 87 const std::string& current_machine_tag() const {
87 DCHECK(!current_machine_tag_.empty()); 88 DCHECK(!current_machine_tag_.empty());
88 return current_machine_tag_; 89 return current_machine_tag_;
89 } 90 }
90 91
91 // Builds a list of all foreign sessions. Caller does NOT own SyncedSession
92 // objects.
93 // Returns true if foreign sessions were found, false otherwise.
94 bool GetAllForeignSessions(std::vector<const SyncedSession*>* sessions);
95
96 // If a valid favicon for the page at |url| is found, fills |favicon_png| with
97 // the png-encoded image and returns true. Else, returns false.
98 bool GetSyncedFaviconForPageURL(
99 const std::string& page_url,
100 scoped_refptr<base::RefCountedMemory>* favicon_png) const;
101
102 // syncer::SyncableService implementation. 92 // syncer::SyncableService implementation.
103 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( 93 virtual syncer::SyncMergeResult MergeDataAndStartSyncing(
104 syncer::ModelType type, 94 syncer::ModelType type,
105 const syncer::SyncDataList& initial_sync_data, 95 const syncer::SyncDataList& initial_sync_data,
106 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 96 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
107 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; 97 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE;
108 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; 98 virtual void StopSyncing(syncer::ModelType type) OVERRIDE;
109 virtual syncer::SyncDataList GetAllSyncData( 99 virtual syncer::SyncDataList GetAllSyncData(
110 syncer::ModelType type) const OVERRIDE; 100 syncer::ModelType type) const OVERRIDE;
111 virtual syncer::SyncError ProcessSyncChanges( 101 virtual syncer::SyncError ProcessSyncChanges(
112 const tracked_objects::Location& from_here, 102 const tracked_objects::Location& from_here,
113 const syncer::SyncChangeList& change_list) OVERRIDE; 103 const syncer::SyncChangeList& change_list) OVERRIDE;
114 104
115 // Return the virtual URL of the current tab, even if it's pending. 105 // Return the virtual URL of the current tab, even if it's pending.
116 static GURL GetCurrentVirtualURL(const SyncedTabDelegate& tab_delegate); 106 static GURL GetCurrentVirtualURL(const SyncedTabDelegate& tab_delegate);
117 107
118 // Return the favicon url of the current tab, even if it's pending. 108 // Return the favicon url of the current tab, even if it's pending.
119 static GURL GetCurrentFaviconURL(const SyncedTabDelegate& tab_delegate); 109 static GURL GetCurrentFaviconURL(const SyncedTabDelegate& tab_delegate);
120 110
111 FaviconCache* GetFaviconCache();
112
113 // OpenTabsUIDelegate implementation.
114 virtual bool GetSyncedFaviconForPageURL(
115 const std::string& pageurl,
116 scoped_refptr<base::RefCountedMemory>* favicon_png) const OVERRIDE;
117 virtual bool GetAllForeignSessions(
118 std::vector<const SyncedSession*>* sessions) OVERRIDE;
119 virtual bool GetForeignSession(
120 const std::string& tag,
121 std::vector<const SessionWindow*>* windows) OVERRIDE;
122 virtual bool GetForeignTab(const std::string& tag,
123 const SessionID::id_type tab_id,
124 const SessionTab** tab) OVERRIDE;
125 virtual void DeleteForeignSession(const std::string& tag) OVERRIDE;
126
121 private: 127 private:
122 // Keep all the links to local tab data in one place. A tab_node_id and tab 128 // Keep all the links to local tab data in one place. A tab_node_id and tab
123 // must be passed at creation. The tab_node_id is not mutable, although 129 // must be passed at creation. The tab_node_id is not mutable, although
124 // all other fields are. 130 // all other fields are.
125 class TabLink { 131 class TabLink {
126 public: 132 public:
127 TabLink(int tab_node_id, const SyncedTabDelegate* tab) 133 TabLink(int tab_node_id, const SyncedTabDelegate* tab)
128 : tab_node_id_(tab_node_id), 134 : tab_node_id_(tab_node_id),
129 tab_(tab) {} 135 tab_(tab) {}
130 136
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // Removes a foreign session from our internal bookkeeping. 199 // Removes a foreign session from our internal bookkeeping.
194 // Returns true if the session was found and deleted, false if no data was 200 // Returns true if the session was found and deleted, false if no data was
195 // found for that session. This will *NOT* trigger sync deletions. See 201 // found for that session. This will *NOT* trigger sync deletions. See
196 // DeleteForeignSession below. 202 // DeleteForeignSession below.
197 bool DisassociateForeignSession(const std::string& foreign_session_tag); 203 bool DisassociateForeignSession(const std::string& foreign_session_tag);
198 204
199 // Delete a foreign session and all its sync data. 205 // Delete a foreign session and all its sync data.
200 // |change_output| *must* be provided as a link to the SyncChange pipeline 206 // |change_output| *must* be provided as a link to the SyncChange pipeline
201 // that exists in the caller's context. This function will append necessary 207 // that exists in the caller's context. This function will append necessary
202 // changes for processing later. 208 // changes for processing later.
203 void DeleteForeignSession(const std::string& tag, 209 void DeleteForeignSessionInternal(const std::string& tag,
204 syncer::SyncChangeList* change_output); 210 syncer::SyncChangeList* change_output);
205 211
206 // Used to populate a session header from the session specifics header 212 // Used to populate a session header from the session specifics header
207 // provided. 213 // provided.
208 static void PopulateSessionHeaderFromSpecifics( 214 static void PopulateSessionHeaderFromSpecifics(
209 const sync_pb::SessionHeader& header_specifics, 215 const sync_pb::SessionHeader& header_specifics,
210 base::Time mtime, 216 base::Time mtime,
211 SyncedSession* session_header); 217 SyncedSession* session_header);
212 218
213 // Builds |session_window| from the session specifics window 219 // Builds |session_window| from the session specifics window
214 // provided and updates the SessionTracker with foreign session data created. 220 // provided and updates the SessionTracker with foreign session data created.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 282
277 // Mapping of current open (local) tabs to their sync identifiers. 283 // Mapping of current open (local) tabs to their sync identifiers.
278 TabLinksMap local_tab_map_; 284 TabLinksMap local_tab_map_;
279 285
280 SyncedSessionTracker session_tracker_; 286 SyncedSessionTracker session_tracker_;
281 FaviconCache favicon_cache_; 287 FaviconCache favicon_cache_;
282 288
283 // Pool of used/available sync nodes associated with local tabs. 289 // Pool of used/available sync nodes associated with local tabs.
284 TabNodePool2 local_tab_pool_; 290 TabNodePool2 local_tab_pool_;
285 291
286 scoped_ptr<SyncPrefs> sync_prefs_; 292 SyncPrefs sync_prefs_;
287 293
288 const Profile* const profile_; 294 const Profile* const profile_;
289 295
290 scoped_ptr<syncer::SyncErrorFactory> error_handler_; 296 scoped_ptr<syncer::SyncErrorFactory> error_handler_;
291 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; 297 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
292 298
293 const SyncInternalApiDelegate* const delegate_; 299 const SyncInternalApiDelegate* const delegate_;
294 300
295 // Unique client tag. 301 // Unique client tag.
296 std::string current_machine_tag_; 302 std::string current_machine_tag_;
297 303
298 // User-visible machine name. 304 // User-visible machine name.
299 std::string current_session_name_; 305 std::string current_session_name_;
300 306
301 // SyncID for the sync node containing all the window information for this 307 // SyncID for the sync node containing all the window information for this
302 // client. 308 // client.
303 int local_session_header_node_id_; 309 int local_session_header_node_id_;
304 310
305 DISALLOW_COPY_AND_ASSIGN(SessionsSyncManager); 311 DISALLOW_COPY_AND_ASSIGN(SessionsSyncManager);
306 }; 312 };
307 313
308 } // namespace browser_sync 314 } // namespace browser_sync
309 315
310 #endif // CHROME_BROWSER_SYNC_SESSIONS2_SESSIONS_SYNC_MANAGER_H_ 316 #endif // CHROME_BROWSER_SYNC_SESSIONS2_SESSIONS_SYNC_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/sessions2/session_data_type_controller2.cc ('k') | chrome/browser/sync/sessions2/sessions_sync_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698