| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <set> | 10 #include <set> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "sync/internal_api/public/syncable/model_type.h" | 33 #include "sync/internal_api/public/syncable/model_type.h" |
| 34 | 34 |
| 35 class Prefservice; | 35 class Prefservice; |
| 36 class Profile; | 36 class Profile; |
| 37 class ProfileSyncService; | 37 class ProfileSyncService; |
| 38 | 38 |
| 39 namespace content { | 39 namespace content { |
| 40 class NavigationEntry; | 40 class NavigationEntry; |
| 41 } // namespace content | 41 } // namespace content |
| 42 | 42 |
| 43 namespace csync { | 43 namespace syncer { |
| 44 class BaseTransaction; | 44 class BaseTransaction; |
| 45 class ReadNode; | 45 class ReadNode; |
| 46 class WriteTransaction; | 46 class WriteTransaction; |
| 47 } // namespace csync | 47 } // namespace syncer |
| 48 | 48 |
| 49 namespace sync_pb { | 49 namespace sync_pb { |
| 50 class SessionHeader; | 50 class SessionHeader; |
| 51 class SessionSpecifics; | 51 class SessionSpecifics; |
| 52 class SessionTab; | 52 class SessionTab; |
| 53 class SessionWindow; | 53 class SessionWindow; |
| 54 class TabNavigation; | 54 class TabNavigation; |
| 55 } // namespace sync_pb | 55 } // namespace sync_pb |
| 56 | 56 |
| 57 namespace browser_sync { | 57 namespace browser_sync { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 79 | 79 |
| 80 // AssociatorInterface and PerDataTypeAssociator Interface implementation. | 80 // AssociatorInterface and PerDataTypeAssociator Interface implementation. |
| 81 virtual void AbortAssociation() OVERRIDE { | 81 virtual void AbortAssociation() OVERRIDE { |
| 82 // No implementation needed, this associator runs on the main thread. | 82 // No implementation needed, this associator runs on the main thread. |
| 83 } | 83 } |
| 84 | 84 |
| 85 // See ModelAssociator interface. | 85 // See ModelAssociator interface. |
| 86 virtual bool CryptoReadyIfNecessary() OVERRIDE; | 86 virtual bool CryptoReadyIfNecessary() OVERRIDE; |
| 87 | 87 |
| 88 // Returns sync id for the given chrome model id. | 88 // Returns sync id for the given chrome model id. |
| 89 // Returns csync::kInvalidId if the sync node is not found for the given | 89 // Returns syncer::kInvalidId if the sync node is not found for the given |
| 90 // chrome id. | 90 // chrome id. |
| 91 virtual int64 GetSyncIdFromChromeId(const size_t& id) OVERRIDE; | 91 virtual int64 GetSyncIdFromChromeId(const size_t& id) OVERRIDE; |
| 92 | 92 |
| 93 // Returns sync id for the given session tag. | 93 // Returns sync id for the given session tag. |
| 94 // Returns csync::kInvalidId if the sync node is not found for the given | 94 // Returns syncer::kInvalidId if the sync node is not found for the given |
| 95 // tag | 95 // tag |
| 96 virtual int64 GetSyncIdFromSessionTag(const std::string& tag); | 96 virtual int64 GetSyncIdFromSessionTag(const std::string& tag); |
| 97 | 97 |
| 98 // Not used. | 98 // Not used. |
| 99 virtual const SyncedTabDelegate* GetChromeNodeFromSyncId(int64 sync_id) | 99 virtual const SyncedTabDelegate* GetChromeNodeFromSyncId(int64 sync_id) |
| 100 OVERRIDE; | 100 OVERRIDE; |
| 101 | 101 |
| 102 // Not used. | 102 // Not used. |
| 103 virtual bool InitSyncNodeFromChromeId(const size_t& id, | 103 virtual bool InitSyncNodeFromChromeId(const size_t& id, |
| 104 csync::BaseNode* sync_node) OVERRIDE; | 104 syncer::BaseNode* sync_node) OVERRIDE; |
| 105 | 105 |
| 106 // Not used. | 106 // Not used. |
| 107 virtual void Associate(const SyncedTabDelegate* tab, int64 sync_id) OVERRIDE; | 107 virtual void Associate(const SyncedTabDelegate* tab, int64 sync_id) OVERRIDE; |
| 108 | 108 |
| 109 // Not used. | 109 // Not used. |
| 110 virtual void Disassociate(int64 sync_id) OVERRIDE; | 110 virtual void Disassociate(int64 sync_id) OVERRIDE; |
| 111 | 111 |
| 112 // Resync local window information. Updates the local sessions header node | 112 // Resync local window information. Updates the local sessions header node |
| 113 // with the status of open windows and the order of tabs they contain. Should | 113 // with the status of open windows and the order of tabs they contain. Should |
| 114 // only be called for changes that affect a window, not a change within a | 114 // only be called for changes that affect a window, not a change within a |
| 115 // single tab. | 115 // single tab. |
| 116 // | 116 // |
| 117 // If |reload_tabs| is true, will also resync all tabs (same as calling | 117 // If |reload_tabs| is true, will also resync all tabs (same as calling |
| 118 // AssociateTabs with a vector of all tabs). | 118 // AssociateTabs with a vector of all tabs). |
| 119 // |error| gets set if any association error occurred. | 119 // |error| gets set if any association error occurred. |
| 120 // Returns: false if the local session's sync nodes were deleted and | 120 // Returns: false if the local session's sync nodes were deleted and |
| 121 // reassociation is necessary, true otherwise. | 121 // reassociation is necessary, true otherwise. |
| 122 bool AssociateWindows(bool reload_tabs, csync::SyncError* error); | 122 bool AssociateWindows(bool reload_tabs, syncer::SyncError* error); |
| 123 | 123 |
| 124 // Loads and reassociates the local tabs referenced in |tabs|. | 124 // Loads and reassociates the local tabs referenced in |tabs|. |
| 125 // |error| gets set if any association error occurred. | 125 // |error| gets set if any association error occurred. |
| 126 // Returns: false if the local session's sync nodes were deleted and | 126 // Returns: false if the local session's sync nodes were deleted and |
| 127 // reassociation is necessary, true otherwise. | 127 // reassociation is necessary, true otherwise. |
| 128 bool AssociateTabs(const std::vector<SyncedTabDelegate*>& tabs, | 128 bool AssociateTabs(const std::vector<SyncedTabDelegate*>& tabs, |
| 129 csync::SyncError* error); | 129 syncer::SyncError* error); |
| 130 | 130 |
| 131 // Reassociates a single tab with the sync model. Will check if the tab | 131 // Reassociates a single tab with the sync model. Will check if the tab |
| 132 // already is associated with a sync node and allocate one if necessary. | 132 // already is associated with a sync node and allocate one if necessary. |
| 133 // |error| gets set if any association error occurred. | 133 // |error| gets set if any association error occurred. |
| 134 // Returns: false if the local session's sync nodes were deleted and | 134 // Returns: false if the local session's sync nodes were deleted and |
| 135 // reassociation is necessary, true otherwise. | 135 // reassociation is necessary, true otherwise. |
| 136 bool AssociateTab(const SyncedTabDelegate& tab, | 136 bool AssociateTab(const SyncedTabDelegate& tab, |
| 137 csync::SyncError* error); | 137 syncer::SyncError* error); |
| 138 | 138 |
| 139 // Load any foreign session info stored in sync db and update the sync db | 139 // Load any foreign session info stored in sync db and update the sync db |
| 140 // with local client data. Processes/reuses any sync nodes owned by this | 140 // with local client data. Processes/reuses any sync nodes owned by this |
| 141 // client and creates any further sync nodes needed to store local header and | 141 // client and creates any further sync nodes needed to store local header and |
| 142 // tab info. | 142 // tab info. |
| 143 virtual csync::SyncError AssociateModels() OVERRIDE; | 143 virtual syncer::SyncError AssociateModels() OVERRIDE; |
| 144 | 144 |
| 145 // Initializes the given sync node from the given chrome node id. | 145 // Initializes the given sync node from the given chrome node id. |
| 146 // Returns false if no sync node was found for the given chrome node id or | 146 // Returns false if no sync node was found for the given chrome node id or |
| 147 // if the initialization of sync node fails. | 147 // if the initialization of sync node fails. |
| 148 virtual bool InitSyncNodeFromChromeId(const std::string& id, | 148 virtual bool InitSyncNodeFromChromeId(const std::string& id, |
| 149 csync::BaseNode* sync_node); | 149 syncer::BaseNode* sync_node); |
| 150 | 150 |
| 151 // Clear local sync data buffers. Does not delete sync nodes to avoid | 151 // Clear local sync data buffers. Does not delete sync nodes to avoid |
| 152 // tombstones. TODO(zea): way to eventually delete orphaned nodes. | 152 // tombstones. TODO(zea): way to eventually delete orphaned nodes. |
| 153 virtual csync::SyncError DisassociateModels() OVERRIDE; | 153 virtual syncer::SyncError DisassociateModels() OVERRIDE; |
| 154 | 154 |
| 155 // Returns the tag used to uniquely identify this machine's session in the | 155 // Returns the tag used to uniquely identify this machine's session in the |
| 156 // sync model. | 156 // sync model. |
| 157 const std::string& GetCurrentMachineTag() const { | 157 const std::string& GetCurrentMachineTag() const { |
| 158 DCHECK(!current_machine_tag_.empty()); | 158 DCHECK(!current_machine_tag_.empty()); |
| 159 return current_machine_tag_; | 159 return current_machine_tag_; |
| 160 } | 160 } |
| 161 | 161 |
| 162 // Load and associate window and tab data for a foreign session. | 162 // Load and associate window and tab data for a foreign session. |
| 163 void AssociateForeignSpecifics(const sync_pb::SessionSpecifics& specifics, | 163 void AssociateForeignSpecifics(const sync_pb::SessionSpecifics& specifics, |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 // Add a previously allocated tab sync node to our pool. Increases the size | 305 // Add a previously allocated tab sync node to our pool. Increases the size |
| 306 // of tab_syncid_pool_ by one and marks the new tab node as free. | 306 // of tab_syncid_pool_ by one and marks the new tab node as free. |
| 307 // Note: this should only be called when we discover tab sync nodes from | 307 // Note: this should only be called when we discover tab sync nodes from |
| 308 // previous sessions, not for freeing tab nodes we created through | 308 // previous sessions, not for freeing tab nodes we created through |
| 309 // GetFreeTabNode (use FreeTabNode below for that). | 309 // GetFreeTabNode (use FreeTabNode below for that). |
| 310 void AddTabNode(int64 sync_id); | 310 void AddTabNode(int64 sync_id); |
| 311 | 311 |
| 312 // Returns the sync_id for the next free tab node. If none are available, | 312 // Returns the sync_id for the next free tab node. If none are available, |
| 313 // creates a new tab node. | 313 // creates a new tab node. |
| 314 // Note: We make use of the following "id's" | 314 // Note: We make use of the following "id's" |
| 315 // - a sync_id: an int64 used in |csync::InitByIdLookup| | 315 // - a sync_id: an int64 used in |syncer::InitByIdLookup| |
| 316 // - a tab_id: created by session service, unique to this client | 316 // - a tab_id: created by session service, unique to this client |
| 317 // - a tab_node_id: the id for a particular sync tab node. This is used | 317 // - a tab_node_id: the id for a particular sync tab node. This is used |
| 318 // to generate the sync tab node tag through: | 318 // to generate the sync tab node tag through: |
| 319 // tab_tag = StringPrintf("%s_%ui", local_session_tag, tab_node_id); | 319 // tab_tag = StringPrintf("%s_%ui", local_session_tag, tab_node_id); |
| 320 // tab_node_id and sync_id are both unique to a particular sync node. The | 320 // tab_node_id and sync_id are both unique to a particular sync node. The |
| 321 // difference is that tab_node_id is controlled by the model associator and | 321 // difference is that tab_node_id is controlled by the model associator and |
| 322 // is used when creating a new sync node, which returns the sync_id, created | 322 // is used when creating a new sync node, which returns the sync_id, created |
| 323 // by the sync db. | 323 // by the sync db. |
| 324 int64 GetFreeTabNode(); | 324 int64 GetFreeTabNode(); |
| 325 | 325 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 static bool ShouldSyncWindow(const SyncedWindowDelegate* window); | 380 static bool ShouldSyncWindow(const SyncedWindowDelegate* window); |
| 381 | 381 |
| 382 // Build a sync tag from tab_node_id. | 382 // Build a sync tag from tab_node_id. |
| 383 static std::string TabIdToTag( | 383 static std::string TabIdToTag( |
| 384 const std::string machine_tag, | 384 const std::string machine_tag, |
| 385 size_t tab_node_id) { | 385 size_t tab_node_id) { |
| 386 return base::StringPrintf("%s %"PRIuS"", machine_tag.c_str(), tab_node_id); | 386 return base::StringPrintf("%s %"PRIuS"", machine_tag.c_str(), tab_node_id); |
| 387 } | 387 } |
| 388 | 388 |
| 389 // Initializes the tag corresponding to this machine. | 389 // Initializes the tag corresponding to this machine. |
| 390 void InitializeCurrentMachineTag(csync::WriteTransaction* trans); | 390 void InitializeCurrentMachineTag(syncer::WriteTransaction* trans); |
| 391 | 391 |
| 392 // Initializes the user visible name for this session | 392 // Initializes the user visible name for this session |
| 393 void InitializeCurrentSessionName(); | 393 void InitializeCurrentSessionName(); |
| 394 | 394 |
| 395 // Updates the server data based upon the current client session. If no node | 395 // Updates the server data based upon the current client session. If no node |
| 396 // corresponding to this machine exists in the sync model, one is created. | 396 // corresponding to this machine exists in the sync model, one is created. |
| 397 // Returns true on success, false if association failed. | 397 // Returns true on success, false if association failed. |
| 398 bool UpdateSyncModelDataFromClient(csync::SyncError* error); | 398 bool UpdateSyncModelDataFromClient(syncer::SyncError* error); |
| 399 | 399 |
| 400 // Pulls the current sync model from the sync database and returns true upon | 400 // Pulls the current sync model from the sync database and returns true upon |
| 401 // update of the client model. Will associate any foreign sessions as well as | 401 // update of the client model. Will associate any foreign sessions as well as |
| 402 // keep track of any local tab nodes, adding them to our free tab node pool. | 402 // keep track of any local tab nodes, adding them to our free tab node pool. |
| 403 bool UpdateAssociationsFromSyncModel(const csync::ReadNode& root, | 403 bool UpdateAssociationsFromSyncModel(const syncer::ReadNode& root, |
| 404 csync::WriteTransaction* trans, | 404 syncer::WriteTransaction* trans, |
| 405 csync::SyncError* error); | 405 syncer::SyncError* error); |
| 406 | 406 |
| 407 // Fills a tab sync node with data from a WebContents object. Updates | 407 // Fills a tab sync node with data from a WebContents object. Updates |
| 408 // |tab_link| with the current url if it's valid and triggers a favicon | 408 // |tab_link| with the current url if it's valid and triggers a favicon |
| 409 // load if the url has changed. | 409 // load if the url has changed. |
| 410 // Returns true on success, false if we need to reassociate due to corruption. | 410 // Returns true on success, false if we need to reassociate due to corruption. |
| 411 bool WriteTabContentsToSyncModel(TabLink* tab_link, | 411 bool WriteTabContentsToSyncModel(TabLink* tab_link, |
| 412 csync::SyncError* error); | 412 syncer::SyncError* error); |
| 413 | 413 |
| 414 // Decrements the favicon usage counters for the favicon used by |page_url|. | 414 // Decrements the favicon usage counters for the favicon used by |page_url|. |
| 415 // Deletes the favicon and associated pages from the favicon usage maps | 415 // Deletes the favicon and associated pages from the favicon usage maps |
| 416 // if no page is found to be referring to the favicon anymore. | 416 // if no page is found to be referring to the favicon anymore. |
| 417 void DecrementAndCleanFaviconForURL(const std::string& page_url); | 417 void DecrementAndCleanFaviconForURL(const std::string& page_url); |
| 418 | 418 |
| 419 // Helper method to build sync's tab specifics from a newly modified | 419 // Helper method to build sync's tab specifics from a newly modified |
| 420 // tab, window, and the locally stored previous tab data. After completing, | 420 // tab, window, and the locally stored previous tab data. After completing, |
| 421 // |prev_tab| will be updated to reflect the current data, |sync_tab| will | 421 // |prev_tab| will be updated to reflect the current data, |sync_tab| will |
| 422 // be filled with the tab data (preserving old timestamps as necessary), and | 422 // be filled with the tab data (preserving old timestamps as necessary), and |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 std::map<std::string, linked_ptr<SyncedFaviconInfo> > synced_favicons_; | 559 std::map<std::string, linked_ptr<SyncedFaviconInfo> > synced_favicons_; |
| 560 // Map of page URL -> favicon url. | 560 // Map of page URL -> favicon url. |
| 561 std::map<std::string, std::string> synced_favicon_pages_; | 561 std::map<std::string, std::string> synced_favicon_pages_; |
| 562 | 562 |
| 563 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); | 563 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); |
| 564 }; | 564 }; |
| 565 | 565 |
| 566 } // namespace browser_sync | 566 } // namespace browser_sync |
| 567 | 567 |
| 568 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ | 568 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ |
| OLD | NEW |