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