| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATOR_H_ | |
| 6 #define COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATOR_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include "base/synchronization/lock.h" | |
| 11 #include "components/sync/api/sync_error.h" | |
| 12 #include "components/sync/base/model_type.h" | |
| 13 | |
| 14 namespace syncer { | |
| 15 class BaseNode; | |
| 16 class SyncMergeResult; | |
| 17 } | |
| 18 | |
| 19 namespace sync_driver { | |
| 20 | |
| 21 // 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 | |
| 23 // being associated. | |
| 24 class AssociatorInterface { | |
| 25 public: | |
| 26 virtual ~AssociatorInterface() {} | |
| 27 | |
| 28 // Iterates through both the sync and the chrome model looking for | |
| 29 // matched pairs of items. After successful completion, the models | |
| 30 // should be identical and corresponding. Returns true on | |
| 31 // success. On failure of this step, we should abort the sync | |
| 32 // operation and report an error to the user. | |
| 33 virtual syncer::SyncError AssociateModels( | |
| 34 syncer::SyncMergeResult* local_merge_result, | |
| 35 syncer::SyncMergeResult* syncer_merge_result) = 0; | |
| 36 | |
| 37 // Clears all the associations between the chrome and sync models. | |
| 38 virtual syncer::SyncError DisassociateModels() = 0; | |
| 39 | |
| 40 // 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 | |
| 42 // return false if an error occurred. | |
| 43 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes) = 0; | |
| 44 | |
| 45 // Calling this method while AssociateModels() is in progress will | |
| 46 // cause the method to exit early with a "false" return value. This | |
| 47 // is useful for aborting model associations for shutdown. This | |
| 48 // method is only implemented for model associators that are invoked | |
| 49 // off the main thread. | |
| 50 virtual void AbortAssociation() = 0; | |
| 51 | |
| 52 // Returns whether the datatype is ready for encryption/decryption if the | |
| 53 // sync service requires it. | |
| 54 // TODO(zea): This should be implemented automatically for each datatype, see | |
| 55 // http://crbug.com/76232. | |
| 56 virtual bool CryptoReadyIfNecessary() = 0; | |
| 57 }; | |
| 58 | |
| 59 // In addition to the generic methods, association can refer to operations | |
| 60 // that depend on the types of the actual IDs we are associating and the | |
| 61 // underlying node type in the browser. We collect these into a templatized | |
| 62 // interface that encapsulates everything you need to implement to have a model | |
| 63 // associator for a specific data type. | |
| 64 // 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 | |
| 66 // in this world, we may want to have several PerDataType templates. | |
| 67 template <class Node, class IDType> | |
| 68 class PerDataTypeAssociatorInterface : public AssociatorInterface { | |
| 69 public: | |
| 70 virtual ~PerDataTypeAssociatorInterface() {} | |
| 71 // Returns sync id for the given chrome model id. | |
| 72 // Returns syncer::kInvalidId if the sync node is not found for the given | |
| 73 // chrome id. | |
| 74 virtual int64_t GetSyncIdFromChromeId(const IDType& id) = 0; | |
| 75 | |
| 76 // Returns the chrome node for the given sync id. | |
| 77 // Returns NULL if no node is found for the given sync id. | |
| 78 virtual const Node* GetChromeNodeFromSyncId(int64_t sync_id) = 0; | |
| 79 | |
| 80 // 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 | |
| 82 // if the initialization of sync node fails. | |
| 83 virtual bool InitSyncNodeFromChromeId( | |
| 84 const IDType& node_id, | |
| 85 syncer::BaseNode* sync_node) = 0; | |
| 86 | |
| 87 // Associates the given chrome node with the given sync node. | |
| 88 virtual void Associate(const Node* node, | |
| 89 const syncer::BaseNode& sync_node) = 0; | |
| 90 | |
| 91 // Remove the association that corresponds to the given sync id. | |
| 92 virtual void Disassociate(int64_t sync_id) = 0; | |
| 93 }; | |
| 94 | |
| 95 } // namespace sync_driver | |
| 96 | |
| 97 #endif // COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATOR_H_ | |
| OLD | NEW |