| 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 COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_MODEL_ASSOCIATOR_H_ | 5 #ifndef COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_MODEL_ASSOCIATOR_H_ |
| 6 #define COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_MODEL_ASSOCIATOR_H_ | 6 #define COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_MODEL_ASSOCIATOR_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 class GURL; | 29 class GURL; |
| 30 | 30 |
| 31 namespace bookmarks { | 31 namespace bookmarks { |
| 32 class BookmarkModel; | 32 class BookmarkModel; |
| 33 class BookmarkNode; | 33 class BookmarkNode; |
| 34 } | 34 } |
| 35 | 35 |
| 36 namespace syncer { | 36 namespace syncer { |
| 37 class BaseNode; | 37 class BaseNode; |
| 38 class BaseTransaction; | 38 class BaseTransaction; |
| 39 class SyncClient; |
| 40 class WriteTransaction; |
| 39 struct UserShare; | 41 struct UserShare; |
| 40 class WriteTransaction; | |
| 41 } | |
| 42 | |
| 43 namespace sync_driver { | |
| 44 class SyncClient; | |
| 45 } | 42 } |
| 46 | 43 |
| 47 namespace sync_bookmarks { | 44 namespace sync_bookmarks { |
| 48 | 45 |
| 49 // Contains all model association related logic: | 46 // Contains all model association related logic: |
| 50 // * Algorithm to associate bookmark model and sync model. | 47 // * Algorithm to associate bookmark model and sync model. |
| 51 // * Methods to get a bookmark node for a given sync node and vice versa. | 48 // * Methods to get a bookmark node for a given sync node and vice versa. |
| 52 // * Persisting model associations and loading them back. | 49 // * Persisting model associations and loading them back. |
| 53 class BookmarkModelAssociator | 50 class BookmarkModelAssociator |
| 54 : public sync_driver:: | 51 : public syncer::PerDataTypeAssociatorInterface<bookmarks::BookmarkNode, |
| 55 PerDataTypeAssociatorInterface<bookmarks::BookmarkNode, int64_t> { | 52 int64_t> { |
| 56 public: | 53 public: |
| 57 static syncer::ModelType model_type() { return syncer::BOOKMARKS; } | 54 static syncer::ModelType model_type() { return syncer::BOOKMARKS; } |
| 58 // |expect_mobile_bookmarks_folder| controls whether or not we | 55 // |expect_mobile_bookmarks_folder| controls whether or not we |
| 59 // expect the mobile bookmarks permanent folder to be created. | 56 // expect the mobile bookmarks permanent folder to be created. |
| 60 // Should be set to true only by mobile clients. | 57 // Should be set to true only by mobile clients. |
| 61 BookmarkModelAssociator( | 58 BookmarkModelAssociator( |
| 62 bookmarks::BookmarkModel* bookmark_model, | 59 bookmarks::BookmarkModel* bookmark_model, |
| 63 sync_driver::SyncClient* sync_client, | 60 syncer::SyncClient* sync_client, |
| 64 syncer::UserShare* user_share, | 61 syncer::UserShare* user_share, |
| 65 std::unique_ptr<syncer::DataTypeErrorHandler> unrecoverable_error_handler, | 62 std::unique_ptr<syncer::DataTypeErrorHandler> unrecoverable_error_handler, |
| 66 bool expect_mobile_bookmarks_folder); | 63 bool expect_mobile_bookmarks_folder); |
| 67 ~BookmarkModelAssociator() override; | 64 ~BookmarkModelAssociator() override; |
| 68 | 65 |
| 69 // AssociatorInterface implementation. | 66 // AssociatorInterface implementation. |
| 70 // | 67 // |
| 71 // AssociateModels iterates through both the sync and the browser | 68 // AssociateModels iterates through both the sync and the browser |
| 72 // bookmark model, looking for matched pairs of items. For any pairs it | 69 // bookmark model, looking for matched pairs of items. For any pairs it |
| 73 // finds, it will call AssociateSyncID. For any unmatched items, | 70 // finds, it will call AssociateSyncID. For any unmatched items, |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 int RemoveSyncNodeHierarchy(syncer::WriteTransaction* trans, int64_t sync_id); | 283 int RemoveSyncNodeHierarchy(syncer::WriteTransaction* trans, int64_t sync_id); |
| 287 | 284 |
| 288 // Check whether bookmark model and sync model are synced by comparing | 285 // Check whether bookmark model and sync model are synced by comparing |
| 289 // their transaction versions. | 286 // their transaction versions. |
| 290 // Returns a PERSISTENCE_ERROR if a transaction mismatch was detected where | 287 // Returns a PERSISTENCE_ERROR if a transaction mismatch was detected where |
| 291 // the native model has a newer transaction verison. | 288 // the native model has a newer transaction verison. |
| 292 syncer::SyncError CheckModelSyncState(Context* context) const; | 289 syncer::SyncError CheckModelSyncState(Context* context) const; |
| 293 | 290 |
| 294 base::ThreadChecker thread_checker_; | 291 base::ThreadChecker thread_checker_; |
| 295 bookmarks::BookmarkModel* bookmark_model_; | 292 bookmarks::BookmarkModel* bookmark_model_; |
| 296 sync_driver::SyncClient* sync_client_; | 293 syncer::SyncClient* sync_client_; |
| 297 syncer::UserShare* user_share_; | 294 syncer::UserShare* user_share_; |
| 298 std::unique_ptr<syncer::DataTypeErrorHandler> unrecoverable_error_handler_; | 295 std::unique_ptr<syncer::DataTypeErrorHandler> unrecoverable_error_handler_; |
| 299 const bool expect_mobile_bookmarks_folder_; | 296 const bool expect_mobile_bookmarks_folder_; |
| 300 BookmarkIdToSyncIdMap id_map_; | 297 BookmarkIdToSyncIdMap id_map_; |
| 301 SyncIdToBookmarkNodeMap id_map_inverse_; | 298 SyncIdToBookmarkNodeMap id_map_inverse_; |
| 302 // Stores sync ids for dirty associations. | 299 // Stores sync ids for dirty associations. |
| 303 DirtyAssociationsSyncIds dirty_associations_sync_ids_; | 300 DirtyAssociationsSyncIds dirty_associations_sync_ids_; |
| 304 | 301 |
| 305 // Used to post PersistAssociation tasks to the current message loop and | 302 // Used to post PersistAssociation tasks to the current message loop and |
| 306 // guarantees no invocations can occur if |this| has been deleted. (This | 303 // guarantees no invocations can occur if |this| has been deleted. (This |
| 307 // allows this class to be non-refcounted). | 304 // allows this class to be non-refcounted). |
| 308 base::WeakPtrFactory<BookmarkModelAssociator> weak_factory_; | 305 base::WeakPtrFactory<BookmarkModelAssociator> weak_factory_; |
| 309 | 306 |
| 310 DISALLOW_COPY_AND_ASSIGN(BookmarkModelAssociator); | 307 DISALLOW_COPY_AND_ASSIGN(BookmarkModelAssociator); |
| 311 }; | 308 }; |
| 312 | 309 |
| 313 } // namespace sync_bookmarks | 310 } // namespace sync_bookmarks |
| 314 | 311 |
| 315 #endif // COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_MODEL_ASSOCIATOR_H_ | 312 #endif // COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_MODEL_ASSOCIATOR_H_ |
| OLD | NEW |