OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_GLUE_SESSION_MODEL_ASSOCIATOR_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ |
6 #define CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
| 9 #include <map> |
9 #include <string> | 10 #include <string> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
13 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
14 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
15 #include "base/scoped_vector.h" | 16 #include "base/scoped_vector.h" |
| 17 #include "base/string_util.h" |
16 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
| 19 #include "base/utf_string_conversions.h" |
| 20 #include "chrome/browser/browser_window.h" |
| 21 #include "chrome/browser/sessions/session_id.h" |
17 #include "chrome/browser/sessions/session_service.h" | 22 #include "chrome/browser/sessions/session_service.h" |
18 #include "chrome/browser/sessions/session_types.h" | 23 #include "chrome/browser/sessions/session_types.h" |
19 #include "chrome/browser/sync/engine/syncapi.h" | 24 #include "chrome/browser/sync/engine/syncapi.h" |
| 25 #include "chrome/browser/sync/glue/foreign_session_tracker.h" |
20 #include "chrome/browser/sync/glue/model_associator.h" | 26 #include "chrome/browser/sync/glue/model_associator.h" |
21 #include "chrome/browser/sync/protocol/session_specifics.pb.h" | 27 #include "chrome/browser/sync/protocol/session_specifics.pb.h" |
22 #include "chrome/browser/sync/syncable/model_type.h" | 28 #include "chrome/browser/sync/syncable/model_type.h" |
| 29 #include "chrome/browser/tab_contents/tab_contents.h" |
23 #include "chrome/common/notification_registrar.h" | 30 #include "chrome/common/notification_registrar.h" |
24 | 31 |
25 class Profile; | 32 class Profile; |
26 class ProfileSyncService; | 33 class ProfileSyncService; |
27 | 34 |
28 namespace sync_api { | 35 namespace sync_api { |
29 class ReadNode; | 36 class ReadNode; |
30 class WriteNode; | 37 class WriteNode; |
31 class WriteTransaction; | 38 class WriteTransaction; |
32 } // namespace sync_api | 39 } // namespace sync_api |
33 | 40 |
34 namespace sync_pb { | 41 namespace sync_pb { |
35 class SessionSpecifics; | 42 class SessionSpecifics; |
36 } // namespace sync_pb | 43 } // namespace sync_pb |
37 | 44 |
38 namespace browser_sync { | 45 namespace browser_sync { |
39 | 46 |
40 static const char kSessionsTag[] = "google_chrome_sessions"; | 47 static const char kSessionsTag[] = "google_chrome_sessions"; |
41 | 48 |
42 // Contains all logic for associating the Chrome sessions model and | 49 // Contains all logic for associating the Chrome sessions model and |
43 // the sync sessions model. | 50 // the sync sessions model. |
44 // In the case of sessions, our local model is nothing but a buffer (specifics_) | |
45 // that gets overwritten everytime there is an update. From it, we build a new | |
46 // foreign session windows list each time |GetSessionData| is called by the | |
47 // ForeignSessionHandler. | |
48 class SessionModelAssociator | 51 class SessionModelAssociator |
49 : public PerDataTypeAssociatorInterface<sync_pb::SessionSpecifics, | 52 : public PerDataTypeAssociatorInterface<TabContents, size_t>, |
50 std::string>, | |
51 public base::NonThreadSafe { | 53 public base::NonThreadSafe { |
52 public: | 54 public: |
53 | |
54 // Does not take ownership of sync_service. | 55 // Does not take ownership of sync_service. |
55 explicit SessionModelAssociator(ProfileSyncService* sync_service); | 56 explicit SessionModelAssociator(ProfileSyncService* sync_service); |
56 virtual ~SessionModelAssociator(); | 57 virtual ~SessionModelAssociator(); |
57 | 58 |
| 59 // The has_nodes out parameter is set to true if the sync model has |
| 60 // nodes other than the permanent tagged nodes. The method may |
| 61 // return false if an error occurred. |
| 62 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); |
| 63 |
58 // AssociatorInterface and PerDataTypeAssociator Interface implementation. | 64 // AssociatorInterface and PerDataTypeAssociator Interface implementation. |
59 virtual void AbortAssociation() { | 65 virtual void AbortAssociation() { |
60 // No implementation needed, this associator runs on the main | 66 // No implementation needed, this associator runs on the main thread. |
61 // thread. | 67 } |
62 } | |
63 | |
64 // Dummy method, we do everything all-at-once in UpdateFromSyncModel. | |
65 virtual void Associate(const sync_pb::SessionSpecifics* specifics, | |
66 int64 sync_id) { | |
67 } | |
68 | |
69 // Updates the sync model with the local client data. (calls | |
70 // UpdateFromSyncModel) | |
71 virtual bool AssociateModels(); | |
72 | |
73 // The has_nodes out parameter is set to true if the chrome model | |
74 // has user-created nodes. The method may return false if an error | |
75 // occurred. | |
76 virtual bool ChromeModelHasUserCreatedNodes(bool* has_nodes); | |
77 | |
78 // Dummy method, we do everything all-at-once in UpdateFromSyncModel. | |
79 virtual void Disassociate(int64 sync_id) { | |
80 } | |
81 | |
82 // Clear specifics_ buffer and notify foreign session handlers. | |
83 virtual bool DisassociateModels(); | |
84 | |
85 // Returns the chrome session specifics for the given sync id. | |
86 // Returns NULL if no specifics are found for the given sync id. | |
87 virtual const sync_pb::SessionSpecifics* GetChromeNodeFromSyncId( | |
88 int64 sync_id); | |
89 | |
90 // Returns whether a node with the given permanent tag was found and update | |
91 // |sync_id| with that node's id. | |
92 virtual bool GetSyncIdForTaggedNode(const std::string* tag, int64* sync_id); | |
93 | 68 |
94 // Returns sync id for the given chrome model id. | 69 // Returns sync id for the given chrome model id. |
95 // Returns sync_api::kInvalidId if the sync node is not found for the given | 70 // Returns sync_api::kInvalidId if the sync node is not found for the given |
96 // chrome id. | 71 // chrome id. |
97 virtual int64 GetSyncIdFromChromeId(const std::string& id); | 72 virtual int64 GetSyncIdFromChromeId(const size_t& id); |
98 | 73 |
| 74 // Returns sync id for the given session tag. |
| 75 // Returns sync_api::kInvalidId if the sync node is not found for the given |
| 76 // tag |
| 77 virtual int64 GetSyncIdFromSessionTag(const std::string& tag); |
| 78 |
| 79 // Not used. |
| 80 virtual const TabContents* GetChromeNodeFromSyncId(int64 sync_id) { |
| 81 NOTREACHED(); |
| 82 return NULL; |
| 83 } |
| 84 |
| 85 // Not used. |
| 86 bool InitSyncNodeFromChromeId(const size_t& id, |
| 87 sync_api::BaseNode* sync_node) { |
| 88 NOTREACHED(); |
| 89 return false; |
| 90 } |
| 91 |
| 92 // Resync local window information. Updates the local sessions header node |
| 93 // with the status of open windows and the order of tabs they contain. Should |
| 94 // only be called for changes that affect a window, not a change within a |
| 95 // single tab. |
| 96 // |
| 97 // If |reload_tabs| is true, will also resync all tabs (same as calling |
| 98 // ReassociateTabs with a vector of all tabs). |
| 99 void ReassociateWindows(bool reload_tabs); |
| 100 |
| 101 // Loads and reassociates the local tabs referenced in |tabs|. |
| 102 void ReassociateTabs(const std::vector<TabContents*>& tabs); |
| 103 |
| 104 // Reassociates a single tab with the sync model. Will check if the tab |
| 105 // already is associated with a sync node and allocate one if necessary. |
| 106 void ReassociateTab(const TabContents& tab); |
| 107 |
| 108 // Associate a local tab and it's sync node. Will overwrite the contents of |
| 109 // the sync node with new specifics built from the tab. |
| 110 virtual void Associate(const TabContents* tab, int64 sync_id); |
| 111 |
| 112 // Looks up the specified sync node, and marks that tab as closed, then marks |
| 113 // the node as free and deletes association. |
| 114 virtual void Disassociate(int64 sync_id); |
| 115 |
| 116 // Load any foreign session info stored in sync db and update the sync db |
| 117 // with local client data. Processes/reuses any sync nodes owned by this |
| 118 // client and creates any further sync nodes needed to store local header and |
| 119 // tab info. |
| 120 virtual bool AssociateModels(); |
99 | 121 |
100 // Initializes the given sync node from the given chrome node id. | 122 // Initializes the given sync node from the given chrome node id. |
101 // Returns false if no sync node was found for the given chrome node id or | 123 // Returns false if no sync node was found for the given chrome node id or |
102 // if the initialization of sync node fails. | 124 // if the initialization of sync node fails. |
103 virtual bool InitSyncNodeFromChromeId(const std::string& id, | 125 virtual bool InitSyncNodeFromChromeId(const std::string& id, |
104 sync_api::BaseNode* sync_node); | 126 sync_api::BaseNode* sync_node); |
105 | 127 |
106 // The has_nodes out parameter is set to true if the sync model has | 128 // Clear local sync data buffers. Does not delete sync nodes to avoid |
107 // nodes other than the permanent tagged nodes. The method may | 129 // tombstones. TODO(zea): way to eventually delete orphaned nodes. |
108 // return false if an error occurred. | 130 virtual bool DisassociateModels(); |
109 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); | |
110 | 131 |
111 // Returns the tag used to uniquely identify this machine's session in the | 132 // Returns the tag used to uniquely identify this machine's session in the |
112 // sync model. | 133 // sync model. |
113 std::string GetCurrentMachineTag(); | 134 inline const std::string& GetCurrentMachineTag() { |
| 135 DCHECK(!current_machine_tag_.empty()); |
| 136 return current_machine_tag_; |
| 137 } |
| 138 |
| 139 // Load and associate window and tab data for a foreign session |
| 140 bool AssociateForeignSpecifics(const sync_pb::SessionSpecifics& specifics, |
| 141 int64 modification_time); |
| 142 |
| 143 // Removes a foreign session from our internal bookkeeping. |
| 144 void DisassociateForeignSession(const std::string& foreign_session_tag); |
| 145 |
| 146 // Builds a list of all foreign sessions. |
| 147 // Caller does NOT own ForeignSession objects. |
| 148 bool GetAllForeignSessions(std::vector<const ForeignSession*>* sessions); |
| 149 |
| 150 // Loads all windows for foreign session with session tag |tag|. |
| 151 // Caller does NOT own ForeignSession objects. |
| 152 bool GetForeignSession(const std::string& tag, |
| 153 std::vector<SessionWindow*>* windows); |
| 154 |
| 155 // Looks up the foreign tab identified by |tab_id| and belonging to foreign |
| 156 // session |tag|. |
| 157 // Caller does NOT own the SessionTab object. |
| 158 bool GetForeignTab(const std::string& tag, |
| 159 const SessionID::id_type tab_id, |
| 160 const SessionTab** tab); |
| 161 |
| 162 // Specifies whether the window has tabs to sync. The new tab page does not |
| 163 // count. If no tabs to sync, it returns true, otherwise false; |
| 164 static bool SessionWindowHasNoTabsToSync(const SessionWindow& window); |
| 165 |
| 166 // Control which local tabs we're interested in syncing. |
| 167 // Ensures the profile matches sync's profile and that the tab has at least |
| 168 // one navigation entry and is not an empty tab. |
| 169 bool IsValidTab(const TabContents& tab); |
| 170 |
| 171 // Control which foreign tabs we're interested in displaying. |
| 172 // Checks that the tab has navigations and is not a new tab. |
| 173 // Note: a new tab page with back/forward history is valid. |
| 174 static bool IsValidSessionTab(const SessionTab& tab); |
| 175 |
| 176 // Returns the syncable model type. |
| 177 static syncable::ModelType model_type() { return syncable::SESSIONS; } |
| 178 |
| 179 private: |
| 180 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, WriteSessionToNode); |
| 181 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, |
| 182 WriteFilledSessionToNode); |
| 183 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, |
| 184 WriteForeignSessionToNode); |
| 185 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, TabNodePoolEmpty); |
| 186 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, TabNodePoolNonEmpty); |
| 187 FRIEND_TEST_ALL_PREFIXES(SessionModelAssociatorTest, PopulateSessionWindow); |
| 188 FRIEND_TEST_ALL_PREFIXES(SessionModelAssociatorTest, PopulateSessionTab); |
| 189 |
| 190 // Keep all the links to local tab data in one place. |
| 191 class TabLinks { |
| 192 public: |
| 193 // To support usage as second value in maps we need default and copy |
| 194 // constructors. |
| 195 TabLinks() |
| 196 : sync_id_(0), |
| 197 session_tab_(NULL), |
| 198 tab_(NULL) {} |
| 199 |
| 200 // We only ever have either a SessionTab (for foreign tabs), or a |
| 201 // TabContents (for local tabs). |
| 202 TabLinks(int64 sync_id, const TabContents* tab) |
| 203 : sync_id_(sync_id), |
| 204 session_tab_(NULL) { |
| 205 tab_ = const_cast<TabContents*>(tab); |
| 206 } |
| 207 TabLinks(int64 sync_id, const SessionTab* session_tab) |
| 208 : sync_id_(sync_id), |
| 209 tab_(NULL) { |
| 210 session_tab_ = const_cast<SessionTab*>(session_tab); |
| 211 } |
| 212 |
| 213 inline const int64 sync_id() const { return sync_id_; } |
| 214 inline const SessionTab* session_tab() const { return session_tab_; } |
| 215 inline const TabContents* tab() const { return tab_; } |
| 216 private: |
| 217 int64 sync_id_; |
| 218 SessionTab* session_tab_; |
| 219 TabContents* tab_; |
| 220 }; |
| 221 |
| 222 // A pool for managing free/used tab sync nodes. Performs lazy creation |
| 223 // of sync nodes when necessary. |
| 224 class TabNodePool { |
| 225 public: |
| 226 explicit TabNodePool(ProfileSyncService* sync_service); |
| 227 |
| 228 // Add a previously allocated tab sync node to our pool. Increases the size |
| 229 // of tab_syncid_pool_ by one and marks the new tab node as free. |
| 230 // Note: this should only be called when we discover tab sync nodes from |
| 231 // previous sessions, not for freeing tab nodes we created through |
| 232 // GetFreeTabNode (use FreeTabNode below for that). |
| 233 void AddTabNode(int64 sync_id); |
| 234 |
| 235 // Returns the sync_id for the next free tab node. If none are available, |
| 236 // creates a new tab node. |
| 237 // Note: We make use of the following "id's" |
| 238 // - a sync_id: an int64 used in |sync_api::InitByIdLookup| |
| 239 // - a tab_id: created by session service, unique to this client |
| 240 // - a tab_node_id: the id for a particular sync tab node. This is used |
| 241 // to generate the sync tab node tag through: |
| 242 // tab_tag = StringPrintf("%s_%ui", local_session_tag, tab_node_id); |
| 243 // tab_node_id and sync_id are both unique to a particular sync node. The |
| 244 // difference is that tab_node_id is controlled by the model associator and |
| 245 // is used when creating a new sync node, which returns the sync_id, created |
| 246 // by the sync db. |
| 247 int64 GetFreeTabNode(); |
| 248 |
| 249 // Return a tab node to our free pool. |
| 250 // Note: the difference between FreeTabNode and AddTabNode is that |
| 251 // FreeTabNode does not modify the size of |tab_syncid_pool_|, while |
| 252 // AddTabNode increases it by one. In the case of FreeTabNode, the size of |
| 253 // the |tab_syncid_pool_| should always be equal to the amount of tab nodes |
| 254 // associated with this machine. |
| 255 void FreeTabNode(int64 sync_id); |
| 256 |
| 257 // Clear tab pool. |
| 258 inline void clear() { tab_syncid_pool_.clear(); } |
| 259 |
| 260 // Return the number of tab nodes this client currently has allocated |
| 261 // (including both free and used nodes) |
| 262 inline size_t capacity() const { return tab_syncid_pool_.size(); } |
| 263 |
| 264 // Return empty status (all tab nodes are in use). |
| 265 inline bool empty() const { return tab_pool_fp_ == -1; } |
| 266 |
| 267 // Return full status (no tab nodes are in use). |
| 268 inline bool full() { |
| 269 return tab_pool_fp_ == static_cast<int64>(tab_syncid_pool_.size())-1; |
| 270 } |
| 271 |
| 272 inline void set_machine_tag(const std::string& machine_tag) { |
| 273 machine_tag_ = machine_tag; |
| 274 } |
| 275 private: |
| 276 // Pool of all available syncid's for tab's we have created. |
| 277 std::vector<int64> tab_syncid_pool_; |
| 278 |
| 279 // Free pointer for tab pool. Only those node id's, up to and including the |
| 280 // one indexed by the free pointer, are valid and free. The rest of the |
| 281 // |tab_syncid_pool_| is invalid because the nodes are in use. |
| 282 // To get the next free node, use tab_syncid_pool_[tab_pool_fp_--]. |
| 283 int64 tab_pool_fp_; |
| 284 |
| 285 // The machiine tag associated with this tab pool. Used in the title of new |
| 286 // sync nodes. |
| 287 std::string machine_tag_; |
| 288 |
| 289 // Our sync service profile (for making changes to the sync db) |
| 290 ProfileSyncService* sync_service_; |
| 291 |
| 292 DISALLOW_COPY_AND_ASSIGN(TabNodePool); |
| 293 }; |
| 294 |
| 295 // Datatypes for accessing local tab data. |
| 296 typedef std::map<SessionID::id_type, TabLinks> TabLinksMap; |
| 297 |
| 298 // Delete all foreign session/window/tab objects allocated dynamically. |
| 299 // This is comprised of ForeignSession*, IDToSessionTabMap*, and any orphaned |
| 300 // SessionTab*'s. |
| 301 void DeleteForeignSessions(); |
| 302 |
| 303 // Determine if a window is of a type we're interested in syncing. |
| 304 static bool ShouldSyncWindowType(const Browser::Type& type); |
| 305 |
| 306 // Build a sync tag from tab_node_id. |
| 307 static inline std::string TabIdToTag( |
| 308 const std::string machine_tag, |
| 309 size_t tab_node_id) { |
| 310 return StringPrintf("%s %lu", |
| 311 machine_tag.c_str(), static_cast<unsigned long>(tab_node_id)); |
| 312 } |
| 313 |
| 314 // Initializes the tag corresponding to this machine. |
| 315 void InitializeCurrentMachineTag(sync_api::WriteTransaction* trans); |
114 | 316 |
115 // Updates the server data based upon the current client session. If no node | 317 // Updates the server data based upon the current client session. If no node |
116 // corresponding to this machine exists in the sync model, one is created. | 318 // corresponding to this machine exists in the sync model, one is created. |
117 void UpdateSyncModelDataFromClient(); | 319 void UpdateSyncModelDataFromClient(); |
118 | 320 |
119 // Pulls the current sync model from the sync database and returns true upon | 321 // Pulls the current sync model from the sync database and returns true upon |
120 // update of the client model. Called by SessionChangeProcessor. | 322 // update of the client model. Will associate any foreign sessions as well as |
121 // Note that the specifics_ vector is reset and built from scratch each time. | 323 // keep track of any local tab nodes, adding them to our free tab node pool. |
122 bool UpdateFromSyncModel(const sync_api::BaseTransaction* trans); | 324 bool UpdateAssociationsFromSyncModel(const sync_api::ReadNode& root, |
123 | 325 const sync_api::BaseTransaction* trans); |
124 // Helper for UpdateFromSyncModel. Appends sync data to a vector of specifics. | 326 |
125 bool QuerySyncModel(const sync_api::BaseTransaction* trans, | 327 // Fills a tab sync node with data from a TabContents object. |
126 std::vector<const sync_pb::SessionSpecifics*>& specifics); | 328 // (from a local navigation event) |
127 | 329 bool WriteTabContentsToSyncModel(const TabContents& tab, |
128 // Builds sessions from buffered specifics data | 330 const int64 sync_id, |
129 bool GetSessionData(std::vector<ForeignSession*>* sessions); | 331 sync_api::WriteTransaction* trans); |
130 | 332 |
131 // Helper method to generate session specifics from session windows. | 333 // Used to populate a session window from the session specifics window |
132 void FillSpecificsFromSessions(std::vector<SessionWindow*>* windows, | 334 // provided. Tracks any foreign session data created through |tracker|. |
133 sync_pb::SessionSpecifics* session); | 335 static void PopulateSessionWindowFromSpecifics( |
134 | 336 std::string foreign_session_tag, |
135 // Helper method for converting session specifics to windows. | 337 const sync_pb::SessionWindow& window, |
136 void AppendForeignSessionFromSpecifics( | 338 const int64 mtime, |
137 const sync_pb::SessionSpecifics* specifics, | 339 SessionWindow* session_window, |
138 std::vector<ForeignSession*>* session); | 340 ForeignSessionTracker* tracker); |
139 | 341 |
140 // Fills the given empty vector with foreign session windows to restore. | 342 // Used to populate a session tab from the session specifics tab provided. |
141 // If the vector is returned empty, then the session data could not be | 343 static void PopulateSessionTabFromSpecifics(const sync_pb::SessionTab& tab, |
142 // converted back into windows. | 344 const int64 mtime, |
143 void AppendForeignSessionWithID(int64 id, | 345 SessionTab* session_tab); |
144 std::vector<ForeignSession*>* session, | 346 |
145 sync_api::BaseTransaction* trans); | 347 // Used to populate a session tab from the session specifics tab provided. |
146 | 348 static void AppendSessionTabNavigation( |
147 // Returns the syncable model type. | 349 const sync_pb::TabNavigation& navigation, |
148 static syncable::ModelType model_type() { return syncable::SESSIONS; } | 350 std::vector<TabNavigation>* navigations); |
149 | 351 |
150 private: | 352 // Populates the navigation portion of the session specifics. |
151 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, WriteSessionToNode); | 353 static void PopulateSessionSpecificsNavigation( |
152 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, | 354 const TabNavigation* navigation, |
153 WriteForeignSessionToNode); | 355 sync_pb::TabNavigation* tab_navigation); |
154 | 356 |
155 // Returns the session service from |sync_service_|. | 357 // Returns the session service from |sync_service_|. |
156 SessionService* GetSessionService(); | 358 SessionService* GetSessionService(); |
157 | 359 |
158 // Initializes the tag corresponding to this machine. | |
159 // Note: creates a syncable::BaseTransaction. | |
160 void InitializeCurrentMachineTag(); | |
161 | |
162 // Populates the navigation portion of the session specifics. | |
163 void PopulateSessionSpecificsNavigation(const TabNavigation* navigation, | |
164 sync_pb::TabNavigation* tab_navigation); | |
165 | |
166 // Populates the tab portion of the session specifics. | |
167 void PopulateSessionSpecificsTab(const SessionTab* tab, | |
168 sync_pb::SessionTab* session_tab); | |
169 | |
170 // Populates the window portion of the session specifics. | |
171 void PopulateSessionSpecificsWindow(const SessionWindow* window, | |
172 sync_pb::SessionWindow* session_window); | |
173 | |
174 // Specifies whether the window has tabs to sync. The new tab page does not | |
175 // count. If no tabs to sync, it returns true, otherwise false; | |
176 bool WindowHasNoTabsToSync(const SessionWindow* window); | |
177 | |
178 // Internal method used in the callback to obtain the current session. | 360 // Internal method used in the callback to obtain the current session. |
179 // We don't own |windows|. | 361 // We don't own |windows|. |
180 void OnGotSession(int handle, std::vector<SessionWindow*>* windows); | 362 void OnGotSession(int handle, std::vector<SessionWindow*>* windows); |
181 | 363 |
182 // Used to populate a session tab from the session specifics tab provided. | 364 // Populate a session specifics header from a list of SessionWindows |
183 void AppendSessionTabNavigation(std::vector<TabNavigation>* navigations, | 365 void PopulateSessionSpecificsHeader( |
184 const sync_pb::TabNavigation* navigation); | 366 const std::vector<SessionWindow*>& windows, |
185 | 367 sync_pb::SessionHeader* header_s); |
186 // Used to populate a session tab from the session specifics tab provided. | 368 |
187 void PopulateSessionTabFromSpecifics(SessionTab* session_tab, | 369 // Populates the window portion of the session specifics. |
188 const sync_pb::SessionTab* tab, SessionID id); | 370 void PopulateSessionSpecificsWindow(const SessionWindow& window, |
189 | 371 sync_pb::SessionWindow* session_window); |
190 // Used to populate a session window from the session specifics window | 372 |
191 // provided. | 373 // Syncs all the tabs in |window| with the local sync db. Will allocate tab |
192 void PopulateSessionWindowFromSpecifics(SessionWindow* session_window, | 374 // nodes if needed. |
193 const sync_pb::SessionWindow* window); | 375 bool SyncLocalWindowToSyncModel(const SessionWindow& window); |
194 | 376 |
195 // Updates the current session on the server. Creates a node for this machine | 377 // Fills a tab sync node with data from a SessionTab object. |
196 // if there is not one already. | 378 // (from ReadCurrentSessions) |
197 bool UpdateSyncModel(sync_pb::SessionSpecifics* session_data, | 379 bool WriteSessionTabToSyncModel(const SessionTab& tab, |
198 sync_api::WriteTransaction* trans, | 380 const int64 sync_id, |
199 const sync_api::ReadNode* root); | 381 sync_api::WriteTransaction* trans); |
200 // Stores the machine tag. | 382 |
| 383 // Populates the tab portion of the session specifics. |
| 384 void PopulateSessionSpecificsTab(const SessionTab& tab, |
| 385 sync_pb::SessionTab* session_tab); |
| 386 |
| 387 // Local client name. |
201 std::string current_machine_tag_; | 388 std::string current_machine_tag_; |
202 | 389 |
203 // Stores the current set of foreign session specifics. | 390 // Pool of all used/available sync nodes associated with tabs. |
204 // Used by ForeignSessionHandler through |GetSessionData|. | 391 TabNodePool tab_pool_; |
205 // Built by |QuerySyncModel| via |UpdateFromSyncModel|. | 392 |
206 std::vector<const sync_pb::SessionSpecifics*> specifics_; | 393 // SyncID for the sync node containing all the window information for this |
| 394 // client. |
| 395 int64 local_session_syncid_; |
| 396 |
| 397 // Mapping of current open (local) tabs to their sync identifiers. |
| 398 TabLinksMap tab_map_; |
| 399 |
| 400 ForeignSessionTracker foreign_session_tracker_; |
207 | 401 |
208 // Weak pointer. | 402 // Weak pointer. |
209 ProfileSyncService* sync_service_; | 403 ProfileSyncService* sync_service_; |
210 | 404 |
211 // Consumer used to obtain the current session. | 405 // Consumer used to obtain the current session. |
212 CancelableRequestConsumer consumer_; | 406 CancelableRequestConsumer consumer_; |
213 | 407 |
214 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); | 408 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); |
215 }; | 409 }; |
216 | 410 |
217 } // namespace browser_sync | 411 } // namespace browser_sync |
218 | 412 |
219 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ | 413 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ |
OLD | NEW |