| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 // first. | 184 // first. |
| 185 void BlockUntilLocalChangeForTest(int64 timeout_milli); | 185 void BlockUntilLocalChangeForTest(int64 timeout_milli); |
| 186 private: | 186 private: |
| 187 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, WriteSessionToNode); | 187 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, WriteSessionToNode); |
| 188 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, | 188 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, |
| 189 WriteFilledSessionToNode); | 189 WriteFilledSessionToNode); |
| 190 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, | 190 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, |
| 191 WriteForeignSessionToNode); | 191 WriteForeignSessionToNode); |
| 192 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, TabNodePoolEmpty); | 192 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, TabNodePoolEmpty); |
| 193 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, TabNodePoolNonEmpty); | 193 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, TabNodePoolNonEmpty); |
| 194 FRIEND_TEST_ALL_PREFIXES(SessionModelAssociatorTest, PopulateSessionHeader); |
| 194 FRIEND_TEST_ALL_PREFIXES(SessionModelAssociatorTest, PopulateSessionWindow); | 195 FRIEND_TEST_ALL_PREFIXES(SessionModelAssociatorTest, PopulateSessionWindow); |
| 195 FRIEND_TEST_ALL_PREFIXES(SessionModelAssociatorTest, PopulateSessionTab); | 196 FRIEND_TEST_ALL_PREFIXES(SessionModelAssociatorTest, PopulateSessionTab); |
| 197 FRIEND_TEST_ALL_PREFIXES(SessionModelAssociatorTest, |
| 198 InitializeCurrentMachineName); |
| 196 | 199 |
| 197 // Keep all the links to local tab data in one place. | 200 // Keep all the links to local tab data in one place. |
| 198 class TabLinks { | 201 class TabLinks { |
| 199 public: | 202 public: |
| 200 // To support usage as second value in maps we need default and copy | 203 // To support usage as second value in maps we need default and copy |
| 201 // constructors. | 204 // constructors. |
| 202 TabLinks() | 205 TabLinks() |
| 203 : sync_id_(0), | 206 : sync_id_(0), |
| 204 session_tab_(NULL), | 207 session_tab_(NULL), |
| 205 tab_(NULL) {} | 208 tab_(NULL) {} |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 // Build a sync tag from tab_node_id. | 317 // Build a sync tag from tab_node_id. |
| 315 static inline std::string TabIdToTag( | 318 static inline std::string TabIdToTag( |
| 316 const std::string machine_tag, | 319 const std::string machine_tag, |
| 317 size_t tab_node_id) { | 320 size_t tab_node_id) { |
| 318 return base::StringPrintf("%s %"PRIuS"", machine_tag.c_str(), tab_node_id); | 321 return base::StringPrintf("%s %"PRIuS"", machine_tag.c_str(), tab_node_id); |
| 319 } | 322 } |
| 320 | 323 |
| 321 // Initializes the tag corresponding to this machine. | 324 // Initializes the tag corresponding to this machine. |
| 322 void InitializeCurrentMachineTag(sync_api::WriteTransaction* trans); | 325 void InitializeCurrentMachineTag(sync_api::WriteTransaction* trans); |
| 323 | 326 |
| 327 // Initializes the user visible name for this machine |
| 328 static void InitializeCurrentMachineName(); |
| 329 |
| 324 // Updates the server data based upon the current client session. If no node | 330 // Updates the server data based upon the current client session. If no node |
| 325 // corresponding to this machine exists in the sync model, one is created. | 331 // corresponding to this machine exists in the sync model, one is created. |
| 326 void UpdateSyncModelDataFromClient(); | 332 void UpdateSyncModelDataFromClient(); |
| 327 | 333 |
| 328 // Pulls the current sync model from the sync database and returns true upon | 334 // Pulls the current sync model from the sync database and returns true upon |
| 329 // update of the client model. Will associate any foreign sessions as well as | 335 // update of the client model. Will associate any foreign sessions as well as |
| 330 // keep track of any local tab nodes, adding them to our free tab node pool. | 336 // keep track of any local tab nodes, adding them to our free tab node pool. |
| 331 bool UpdateAssociationsFromSyncModel(const sync_api::ReadNode& root, | 337 bool UpdateAssociationsFromSyncModel(const sync_api::ReadNode& root, |
| 332 const sync_api::BaseTransaction* trans); | 338 const sync_api::BaseTransaction* trans); |
| 333 | 339 |
| 334 // Fills a tab sync node with data from a TabContents object. | 340 // Fills a tab sync node with data from a TabContents object. |
| 335 // (from a local navigation event) | 341 // (from a local navigation event) |
| 336 bool WriteTabContentsToSyncModel(const SyncedWindowDelegate& window, | 342 bool WriteTabContentsToSyncModel(const SyncedWindowDelegate& window, |
| 337 const SyncedTabDelegate& tab, | 343 const SyncedTabDelegate& tab, |
| 338 const int64 sync_id, | 344 const int64 sync_id, |
| 339 sync_api::WriteTransaction* trans); | 345 sync_api::WriteTransaction* trans); |
| 340 | 346 |
| 347 // Used to populate a session header from the session specifics header |
| 348 // provided. |
| 349 static void PopulateSessionHeaderFromSpecifics( |
| 350 const sync_pb::SessionHeader& header_specifics, |
| 351 SyncedSession* session_header); |
| 352 |
| 341 // Used to populate a session window from the session specifics window | 353 // Used to populate a session window from the session specifics window |
| 342 // provided. Tracks any foreign session data created through |tracker|. | 354 // provided. Tracks any foreign session data created through |tracker|. |
| 343 static void PopulateSessionWindowFromSpecifics( | 355 static void PopulateSessionWindowFromSpecifics( |
| 344 const std::string& foreign_session_tag, | 356 const std::string& foreign_session_tag, |
| 345 const sync_pb::SessionWindow& window, | 357 const sync_pb::SessionWindow& window, |
| 346 const int64 mtime, | 358 const int64 mtime, |
| 347 SessionWindow* session_window, | 359 SessionWindow* session_window, |
| 348 SyncedSessionTracker* tracker); | 360 SyncedSessionTracker* tracker); |
| 349 | 361 |
| 350 // Used to populate a session tab from the session specifics tab provided. | 362 // Used to populate a session tab from the session specifics tab provided. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 const int64 sync_id, | 400 const int64 sync_id, |
| 389 sync_api::WriteTransaction* trans); | 401 sync_api::WriteTransaction* trans); |
| 390 | 402 |
| 391 // Populates the tab portion of the session specifics. | 403 // Populates the tab portion of the session specifics. |
| 392 void PopulateSessionSpecificsTab(const SessionTab& tab, | 404 void PopulateSessionSpecificsTab(const SessionTab& tab, |
| 393 sync_pb::SessionTab* session_tab); | 405 sync_pb::SessionTab* session_tab); |
| 394 | 406 |
| 395 // For testing only. | 407 // For testing only. |
| 396 void QuitLoopForTest(); | 408 void QuitLoopForTest(); |
| 397 | 409 |
| 398 // Local client name. | 410 // Unique client tag. |
| 399 std::string current_machine_tag_; | 411 std::string current_machine_tag_; |
| 400 | 412 |
| 413 // User-visible machine name. |
| 414 static std::string current_machine_name_; |
| 415 |
| 401 // Pool of all used/available sync nodes associated with tabs. | 416 // Pool of all used/available sync nodes associated with tabs. |
| 402 TabNodePool tab_pool_; | 417 TabNodePool tab_pool_; |
| 403 | 418 |
| 404 // SyncID for the sync node containing all the window information for this | 419 // SyncID for the sync node containing all the window information for this |
| 405 // client. | 420 // client. |
| 406 int64 local_session_syncid_; | 421 int64 local_session_syncid_; |
| 407 | 422 |
| 408 // Mapping of current open (local) tabs to their sync identifiers. | 423 // Mapping of current open (local) tabs to their sync identifiers. |
| 409 TabLinksMap tab_map_; | 424 TabLinksMap tab_map_; |
| 410 | 425 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 423 // is made. | 438 // is made. |
| 424 bool waiting_for_change_; | 439 bool waiting_for_change_; |
| 425 ScopedRunnableMethodFactory<SessionModelAssociator> test_method_factory_; | 440 ScopedRunnableMethodFactory<SessionModelAssociator> test_method_factory_; |
| 426 | 441 |
| 427 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); | 442 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); |
| 428 }; | 443 }; |
| 429 | 444 |
| 430 } // namespace browser_sync | 445 } // namespace browser_sync |
| 431 | 446 |
| 432 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ | 447 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ |
| OLD | NEW |