| 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_BOOKMARK_MODEL_ASSOCIATOR_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_ |
| 6 #define CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 namespace browser_sync { | 29 namespace browser_sync { |
| 30 | 30 |
| 31 // Contains all model association related logic: | 31 // Contains all model association related logic: |
| 32 // * Algorithm to associate bookmark model and sync model. | 32 // * Algorithm to associate bookmark model and sync model. |
| 33 // * Methods to get a bookmark node for a given sync node and vice versa. | 33 // * Methods to get a bookmark node for a given sync node and vice versa. |
| 34 // * Persisting model associations and loading them back. | 34 // * Persisting model associations and loading them back. |
| 35 class BookmarkModelAssociator | 35 class BookmarkModelAssociator |
| 36 : public PerDataTypeAssociatorInterface<BookmarkNode, int64> { | 36 : public PerDataTypeAssociatorInterface<BookmarkNode, int64> { |
| 37 public: | 37 public: |
| 38 static syncable::ModelType model_type() { return syncable::BOOKMARKS; } | 38 static syncable::ModelType model_type() { return syncable::BOOKMARKS; } |
| 39 // |expect_mobile_bookmarks_folder| controls whether or not we |
| 40 // expect the mobile bookmarks permanent folder to be created. |
| 41 // Should be set to true only by mobile clients. |
| 39 BookmarkModelAssociator( | 42 BookmarkModelAssociator( |
| 40 BookmarkModel* bookmark_model, | 43 BookmarkModel* bookmark_model, |
| 41 sync_api::UserShare* user_share, | 44 sync_api::UserShare* user_share, |
| 42 DataTypeErrorHandler* unrecoverable_error_handler); | 45 DataTypeErrorHandler* unrecoverable_error_handler, |
| 46 bool expect_mobile_bookmarks_folder); |
| 43 virtual ~BookmarkModelAssociator(); | 47 virtual ~BookmarkModelAssociator(); |
| 44 | 48 |
| 45 // Updates the visibility of the permanents node in the BookmarkModel. | 49 // Updates the visibility of the permanents node in the BookmarkModel. |
| 46 void UpdatePermanentNodeVisibility(); | 50 void UpdatePermanentNodeVisibility(); |
| 47 | 51 |
| 48 // AssociatorInterface implementation. | 52 // AssociatorInterface implementation. |
| 49 // | 53 // |
| 50 // AssociateModels iterates through both the sync and the browser | 54 // AssociateModels iterates through both the sync and the browser |
| 51 // bookmark model, looking for matched pairs of items. For any pairs it | 55 // bookmark model, looking for matched pairs of items. For any pairs it |
| 52 // finds, it will call AssociateSyncID. For any unmatched items, | 56 // finds, it will call AssociateSyncID. For any unmatched items, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 bool AssociateTaggedPermanentNode(const BookmarkNode* permanent_node, | 127 bool AssociateTaggedPermanentNode(const BookmarkNode* permanent_node, |
| 124 const std::string& tag) WARN_UNUSED_RESULT; | 128 const std::string& tag) WARN_UNUSED_RESULT; |
| 125 | 129 |
| 126 // Compare the properties of a pair of nodes from either domain. | 130 // Compare the properties of a pair of nodes from either domain. |
| 127 bool NodesMatch(const BookmarkNode* bookmark, | 131 bool NodesMatch(const BookmarkNode* bookmark, |
| 128 const sync_api::BaseNode* sync_node) const; | 132 const sync_api::BaseNode* sync_node) const; |
| 129 | 133 |
| 130 BookmarkModel* bookmark_model_; | 134 BookmarkModel* bookmark_model_; |
| 131 sync_api::UserShare* user_share_; | 135 sync_api::UserShare* user_share_; |
| 132 DataTypeErrorHandler* unrecoverable_error_handler_; | 136 DataTypeErrorHandler* unrecoverable_error_handler_; |
| 137 const bool expect_mobile_bookmarks_folder_; |
| 133 BookmarkIdToSyncIdMap id_map_; | 138 BookmarkIdToSyncIdMap id_map_; |
| 134 SyncIdToBookmarkNodeMap id_map_inverse_; | 139 SyncIdToBookmarkNodeMap id_map_inverse_; |
| 135 // Stores sync ids for dirty associations. | 140 // Stores sync ids for dirty associations. |
| 136 DirtyAssociationsSyncIds dirty_associations_sync_ids_; | 141 DirtyAssociationsSyncIds dirty_associations_sync_ids_; |
| 137 | 142 |
| 138 // Used to post PersistAssociation tasks to the current message loop and | 143 // Used to post PersistAssociation tasks to the current message loop and |
| 139 // guarantees no invocations can occur if |this| has been deleted. (This | 144 // guarantees no invocations can occur if |this| has been deleted. (This |
| 140 // allows this class to be non-refcounted). | 145 // allows this class to be non-refcounted). |
| 141 base::WeakPtrFactory<BookmarkModelAssociator> weak_factory_; | 146 base::WeakPtrFactory<BookmarkModelAssociator> weak_factory_; |
| 142 | 147 |
| 143 int number_of_new_sync_nodes_created_at_association_; | 148 int number_of_new_sync_nodes_created_at_association_; |
| 144 | 149 |
| 145 DISALLOW_COPY_AND_ASSIGN(BookmarkModelAssociator); | 150 DISALLOW_COPY_AND_ASSIGN(BookmarkModelAssociator); |
| 146 }; | 151 }; |
| 147 | 152 |
| 148 } // namespace browser_sync | 153 } // namespace browser_sync |
| 149 | 154 |
| 150 #endif // CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_ | 155 #endif // CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_ |
| OLD | NEW |