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