| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_DRIVER_MODEL_ASSOCIATOR_H_ | 5 #ifndef COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATOR_H_ |
| 6 #define COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATOR_H_ | 6 #define COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATOR_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "components/sync/api/sync_error.h" | 11 #include "components/sync/api/sync_error.h" |
| 12 #include "components/sync/base/model_type.h" | 12 #include "components/sync/base/model_type.h" |
| 13 | 13 |
| 14 namespace syncer { | 14 namespace syncer { |
| 15 | |
| 16 class BaseNode; | 15 class BaseNode; |
| 17 class SyncMergeResult; | 16 class SyncMergeResult; |
| 17 } |
| 18 |
| 19 namespace sync_driver { |
| 18 | 20 |
| 19 // This represents the fundamental operations used for model association that | 21 // This represents the fundamental operations used for model association that |
| 20 // are common to all ModelAssociators and do not depend on types of the models | 22 // are common to all ModelAssociators and do not depend on types of the models |
| 21 // being associated. | 23 // being associated. |
| 22 class AssociatorInterface { | 24 class AssociatorInterface { |
| 23 public: | 25 public: |
| 24 virtual ~AssociatorInterface() {} | 26 virtual ~AssociatorInterface() {} |
| 25 | 27 |
| 26 // Iterates through both the sync and the chrome model looking for | 28 // Iterates through both the sync and the chrome model looking for |
| 27 // matched pairs of items. After successful completion, the models | 29 // matched pairs of items. After successful completion, the models |
| 28 // should be identical and corresponding. Returns true on | 30 // should be identical and corresponding. Returns true on |
| 29 // success. On failure of this step, we should abort the sync | 31 // success. On failure of this step, we should abort the sync |
| 30 // operation and report an error to the user. | 32 // operation and report an error to the user. |
| 31 virtual SyncError AssociateModels(SyncMergeResult* local_merge_result, | 33 virtual syncer::SyncError AssociateModels( |
| 32 SyncMergeResult* syncer_merge_result) = 0; | 34 syncer::SyncMergeResult* local_merge_result, |
| 35 syncer::SyncMergeResult* syncer_merge_result) = 0; |
| 33 | 36 |
| 34 // Clears all the associations between the chrome and sync models. | 37 // Clears all the associations between the chrome and sync models. |
| 35 virtual SyncError DisassociateModels() = 0; | 38 virtual syncer::SyncError DisassociateModels() = 0; |
| 36 | 39 |
| 37 // The has_nodes out parameter is set to true if the sync model has | 40 // The has_nodes out parameter is set to true if the sync model has |
| 38 // nodes other than the permanent tagged nodes. The method may | 41 // nodes other than the permanent tagged nodes. The method may |
| 39 // return false if an error occurred. | 42 // return false if an error occurred. |
| 40 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes) = 0; | 43 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes) = 0; |
| 41 | 44 |
| 42 // Calling this method while AssociateModels() is in progress will | 45 // Calling this method while AssociateModels() is in progress will |
| 43 // cause the method to exit early with a "false" return value. This | 46 // cause the method to exit early with a "false" return value. This |
| 44 // is useful for aborting model associations for shutdown. This | 47 // is useful for aborting model associations for shutdown. This |
| 45 // method is only implemented for model associators that are invoked | 48 // method is only implemented for model associators that are invoked |
| (...skipping 13 matching lines...) Expand all Loading... |
| 59 // interface that encapsulates everything you need to implement to have a model | 62 // interface that encapsulates everything you need to implement to have a model |
| 60 // associator for a specific data type. | 63 // associator for a specific data type. |
| 61 // This template is appropriate for data types where a Node* makes sense for | 64 // This template is appropriate for data types where a Node* makes sense for |
| 62 // referring to a particular item. If we encounter a type that does not fit | 65 // referring to a particular item. If we encounter a type that does not fit |
| 63 // in this world, we may want to have several PerDataType templates. | 66 // in this world, we may want to have several PerDataType templates. |
| 64 template <class Node, class IDType> | 67 template <class Node, class IDType> |
| 65 class PerDataTypeAssociatorInterface : public AssociatorInterface { | 68 class PerDataTypeAssociatorInterface : public AssociatorInterface { |
| 66 public: | 69 public: |
| 67 virtual ~PerDataTypeAssociatorInterface() {} | 70 virtual ~PerDataTypeAssociatorInterface() {} |
| 68 // Returns sync id for the given chrome model id. | 71 // Returns sync id for the given chrome model id. |
| 69 // Returns kInvalidId if the sync node is not found for the given | 72 // Returns syncer::kInvalidId if the sync node is not found for the given |
| 70 // chrome id. | 73 // chrome id. |
| 71 virtual int64_t GetSyncIdFromChromeId(const IDType& id) = 0; | 74 virtual int64_t GetSyncIdFromChromeId(const IDType& id) = 0; |
| 72 | 75 |
| 73 // Returns the chrome node for the given sync id. | 76 // Returns the chrome node for the given sync id. |
| 74 // Returns NULL if no node is found for the given sync id. | 77 // Returns NULL if no node is found for the given sync id. |
| 75 virtual const Node* GetChromeNodeFromSyncId(int64_t sync_id) = 0; | 78 virtual const Node* GetChromeNodeFromSyncId(int64_t sync_id) = 0; |
| 76 | 79 |
| 77 // Initializes the given sync node from the given chrome node id. | 80 // Initializes the given sync node from the given chrome node id. |
| 78 // Returns false if no sync node was found for the given chrome node id or | 81 // Returns false if no sync node was found for the given chrome node id or |
| 79 // if the initialization of sync node fails. | 82 // if the initialization of sync node fails. |
| 80 virtual bool InitSyncNodeFromChromeId(const IDType& node_id, | 83 virtual bool InitSyncNodeFromChromeId(const IDType& node_id, |
| 81 BaseNode* sync_node) = 0; | 84 syncer::BaseNode* sync_node) = 0; |
| 82 | 85 |
| 83 // Associates the given chrome node with the given sync node. | 86 // Associates the given chrome node with the given sync node. |
| 84 virtual void Associate(const Node* node, const BaseNode& sync_node) = 0; | 87 virtual void Associate(const Node* node, |
| 88 const syncer::BaseNode& sync_node) = 0; |
| 85 | 89 |
| 86 // Remove the association that corresponds to the given sync id. | 90 // Remove the association that corresponds to the given sync id. |
| 87 virtual void Disassociate(int64_t sync_id) = 0; | 91 virtual void Disassociate(int64_t sync_id) = 0; |
| 88 }; | 92 }; |
| 89 | 93 |
| 90 } // namespace syncer | 94 } // namespace sync_driver |
| 91 | 95 |
| 92 #endif // COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATOR_H_ | 96 #endif // COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATOR_H_ |
| OLD | NEW |