| 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 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "chrome/browser/sync/glue/data_type_controller.h" | 15 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 16 #include "chrome/browser/sync/glue/data_type_error_handler.h" | 16 #include "chrome/browser/sync/glue/data_type_error_handler.h" |
| 17 #include "chrome/browser/sync/glue/model_associator.h" | 17 #include "chrome/browser/sync/glue/model_associator.h" |
| 18 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" | 18 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" |
| 19 | 19 |
| 20 class BookmarkModel; | 20 class BookmarkModel; |
| 21 class BookmarkNode; | 21 class BookmarkNode; |
| 22 class Profile; |
| 22 | 23 |
| 23 namespace syncer { | 24 namespace syncer { |
| 24 class BaseNode; | 25 class BaseNode; |
| 25 class BaseTransaction; | 26 class BaseTransaction; |
| 26 struct UserShare; | 27 struct UserShare; |
| 27 } | 28 } |
| 28 | 29 |
| 29 namespace browser_sync { | 30 namespace browser_sync { |
| 30 | 31 |
| 31 // Contains all model association related logic: | 32 // Contains all model association related logic: |
| 32 // * Algorithm to associate bookmark model and sync model. | 33 // * Algorithm to associate bookmark model and sync model. |
| 33 // * Methods to get a bookmark node for a given sync node and vice versa. | 34 // * Methods to get a bookmark node for a given sync node and vice versa. |
| 34 // * Persisting model associations and loading them back. | 35 // * Persisting model associations and loading them back. |
| 35 class BookmarkModelAssociator | 36 class BookmarkModelAssociator |
| 36 : public PerDataTypeAssociatorInterface<BookmarkNode, int64> { | 37 : public PerDataTypeAssociatorInterface<BookmarkNode, int64> { |
| 37 public: | 38 public: |
| 38 static syncer::ModelType model_type() { return syncer::BOOKMARKS; } | 39 static syncer::ModelType model_type() { return syncer::BOOKMARKS; } |
| 39 // |expect_mobile_bookmarks_folder| controls whether or not we | 40 // |expect_mobile_bookmarks_folder| controls whether or not we |
| 40 // expect the mobile bookmarks permanent folder to be created. | 41 // expect the mobile bookmarks permanent folder to be created. |
| 41 // Should be set to true only by mobile clients. | 42 // Should be set to true only by mobile clients. |
| 42 BookmarkModelAssociator( | 43 BookmarkModelAssociator( |
| 43 BookmarkModel* bookmark_model, | 44 BookmarkModel* bookmark_model, |
| 45 Profile* profile_, |
| 44 syncer::UserShare* user_share, | 46 syncer::UserShare* user_share, |
| 45 DataTypeErrorHandler* unrecoverable_error_handler, | 47 DataTypeErrorHandler* unrecoverable_error_handler, |
| 46 bool expect_mobile_bookmarks_folder); | 48 bool expect_mobile_bookmarks_folder); |
| 47 virtual ~BookmarkModelAssociator(); | 49 virtual ~BookmarkModelAssociator(); |
| 48 | 50 |
| 49 // Updates the visibility of the permanents node in the BookmarkModel. | 51 // Updates the visibility of the permanents node in the BookmarkModel. |
| 50 void UpdatePermanentNodeVisibility(); | 52 void UpdatePermanentNodeVisibility(); |
| 51 | 53 |
| 52 // AssociatorInterface implementation. | 54 // AssociatorInterface implementation. |
| 53 // | 55 // |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 137 |
| 136 // Compare the properties of a pair of nodes from either domain. | 138 // Compare the properties of a pair of nodes from either domain. |
| 137 bool NodesMatch(const BookmarkNode* bookmark, | 139 bool NodesMatch(const BookmarkNode* bookmark, |
| 138 const syncer::BaseNode* sync_node) const; | 140 const syncer::BaseNode* sync_node) const; |
| 139 | 141 |
| 140 // Check whether bookmark model and sync model are synced by comparing | 142 // Check whether bookmark model and sync model are synced by comparing |
| 141 // their transaction versions. | 143 // their transaction versions. |
| 142 void CheckModelSyncState() const; | 144 void CheckModelSyncState() const; |
| 143 | 145 |
| 144 BookmarkModel* bookmark_model_; | 146 BookmarkModel* bookmark_model_; |
| 147 Profile* profile_; |
| 145 syncer::UserShare* user_share_; | 148 syncer::UserShare* user_share_; |
| 146 DataTypeErrorHandler* unrecoverable_error_handler_; | 149 DataTypeErrorHandler* unrecoverable_error_handler_; |
| 147 const bool expect_mobile_bookmarks_folder_; | 150 const bool expect_mobile_bookmarks_folder_; |
| 148 BookmarkIdToSyncIdMap id_map_; | 151 BookmarkIdToSyncIdMap id_map_; |
| 149 SyncIdToBookmarkNodeMap id_map_inverse_; | 152 SyncIdToBookmarkNodeMap id_map_inverse_; |
| 150 // Stores sync ids for dirty associations. | 153 // Stores sync ids for dirty associations. |
| 151 DirtyAssociationsSyncIds dirty_associations_sync_ids_; | 154 DirtyAssociationsSyncIds dirty_associations_sync_ids_; |
| 152 | 155 |
| 153 // Used to post PersistAssociation tasks to the current message loop and | 156 // Used to post PersistAssociation tasks to the current message loop and |
| 154 // guarantees no invocations can occur if |this| has been deleted. (This | 157 // guarantees no invocations can occur if |this| has been deleted. (This |
| 155 // allows this class to be non-refcounted). | 158 // allows this class to be non-refcounted). |
| 156 base::WeakPtrFactory<BookmarkModelAssociator> weak_factory_; | 159 base::WeakPtrFactory<BookmarkModelAssociator> weak_factory_; |
| 157 | 160 |
| 158 DISALLOW_COPY_AND_ASSIGN(BookmarkModelAssociator); | 161 DISALLOW_COPY_AND_ASSIGN(BookmarkModelAssociator); |
| 159 }; | 162 }; |
| 160 | 163 |
| 161 } // namespace browser_sync | 164 } // namespace browser_sync |
| 162 | 165 |
| 163 #endif // CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_ | 166 #endif // CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_ |
| OLD | NEW |