| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 #if defined(BROWSER_SYNC) | 5 #if defined(BROWSER_SYNC) |
| 6 | 6 |
| 7 #ifndef CHROME_BROWSER_SYNC_GLUE_MODEL_ASSOCATOR_H_ | 7 #ifndef CHROME_BROWSER_SYNC_GLUE_MODEL_ASSOCIATOR_H_ |
| 8 #define CHROME_BROWSER_SYNC_GLUE_MODEL_ASSOCATOR_H_ | 8 #define CHROME_BROWSER_SYNC_GLUE_MODEL_ASSOCIATOR_H_ |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/ref_counted.h" | 15 #include "base/ref_counted.h" |
| 16 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" |
| 17 #include "base/string16.h" | 17 #include "base/string16.h" |
| 18 | 18 |
| 19 class BookmarkNode; | 19 class BookmarkNode; |
| 20 | 20 |
| 21 namespace sync_api { | 21 namespace sync_api { |
| 22 class BaseNode; | 22 class BaseNode; |
| 23 class BaseTransaction; | 23 class BaseTransaction; |
| 24 class ReadNode; | 24 class ReadNode; |
| 25 } | 25 } |
| 26 | 26 |
| 27 class ProfileSyncService; | 27 class ProfileSyncService; |
| 28 | 28 |
| 29 namespace browser_sync { | 29 namespace browser_sync { |
| 30 | 30 |
| 31 class ChangeProcessor; | 31 class ChangeProcessor; |
| 32 | 32 |
| 33 // Contains all model assocation related logic: | 33 // Contains all model association related logic: |
| 34 // * Algorithm to associate bookmark model and sync model. | 34 // * Algorithm to associate bookmark model and sync model. |
| 35 // * Methods to get a bookmark node for a given sync node and vice versa. | 35 // * Methods to get a bookmark node for a given sync node and vice versa. |
| 36 // * Persisting model assocations and loading them back. | 36 // * Persisting model associations and loading them back. |
| 37 class ModelAssociator | 37 class ModelAssociator |
| 38 : public base::RefCountedThreadSafe<ModelAssociator> { | 38 : public base::RefCountedThreadSafe<ModelAssociator> { |
| 39 public: | 39 public: |
| 40 explicit ModelAssociator(ProfileSyncService* sync_service); | 40 explicit ModelAssociator(ProfileSyncService* sync_service); |
| 41 virtual ~ModelAssociator() { } | 41 virtual ~ModelAssociator() { } |
| 42 | 42 |
| 43 // Clears all assocations. | 43 // Clears all associations. |
| 44 void ClearAll(); | 44 void ClearAll(); |
| 45 | 45 |
| 46 // Returns sync id for the given bookmark node id. | 46 // Returns sync id for the given bookmark node id. |
| 47 // Returns sync_api::kInvalidId if the sync node is not found for the given | 47 // Returns sync_api::kInvalidId if the sync node is not found for the given |
| 48 // bookmark node id. | 48 // bookmark node id. |
| 49 int64 GetSyncIdFromBookmarkId(int64 node_id) const; | 49 int64 GetSyncIdFromBookmarkId(int64 node_id) const; |
| 50 | 50 |
| 51 // Stores bookmark node id for the given sync id in bookmark_id. Returns true | 51 // Stores bookmark node id for the given sync id in bookmark_id. Returns true |
| 52 // if the bookmark id was successfully found; false otherwise. | 52 // if the bookmark id was successfully found; false otherwise. |
| 53 bool GetBookmarkIdFromSyncId(int64 sync_id, int64* bookmark_id) const; | 53 bool GetBookmarkIdFromSyncId(int64 sync_id, int64* bookmark_id) const; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 // Returns of that node was found successfully. | 89 // Returns of that node was found successfully. |
| 90 // Tests override this. | 90 // Tests override this. |
| 91 virtual bool GetSyncIdForTaggedNode(const string16& tag, int64* sync_id); | 91 virtual bool GetSyncIdForTaggedNode(const string16& tag, int64* sync_id); |
| 92 | 92 |
| 93 // Returns sync service instance. | 93 // Returns sync service instance. |
| 94 ProfileSyncService* sync_service() { return sync_service_; } | 94 ProfileSyncService* sync_service() { return sync_service_; } |
| 95 | 95 |
| 96 private: | 96 private: |
| 97 typedef std::map<int64, int64> BookmarkIdToSyncIdMap; | 97 typedef std::map<int64, int64> BookmarkIdToSyncIdMap; |
| 98 typedef std::map<int64, int64> SyncIdToBookmarkIdMap; | 98 typedef std::map<int64, int64> SyncIdToBookmarkIdMap; |
| 99 typedef std::set<int64> DirtyAssocationsSyncIds; | 99 typedef std::set<int64> DirtyAssociationsSyncIds; |
| 100 | 100 |
| 101 // Posts a task to persist dirty assocations. | 101 // Posts a task to persist dirty associations. |
| 102 void PostPersistAssociationsTask(); | 102 void PostPersistAssociationsTask(); |
| 103 // Persists all dirty assocations. | 103 // Persists all dirty associations. |
| 104 void PersistAssociations(); | 104 void PersistAssociations(); |
| 105 | 105 |
| 106 // Loads the persisted assocations into in-memory maps. | 106 // Loads the persisted associations into in-memory maps. |
| 107 // If the persisted associations are out-of-date due to some reason, returns | 107 // If the persisted associations are out-of-date due to some reason, returns |
| 108 // false; otehrwise returns true. | 108 // false; otherwise returns true. |
| 109 bool LoadAssociations(); | 109 bool LoadAssociations(); |
| 110 | 110 |
| 111 // Matches up the bookmark model and the sync model to build model | 111 // Matches up the bookmark model and the sync model to build model |
| 112 // assocations. | 112 // associations. |
| 113 bool BuildAssocations(); | 113 bool BuildAssociations(); |
| 114 | 114 |
| 115 // Associate a top-level node of the bookmark model with a permanent node in | 115 // Associate a top-level node of the bookmark model with a permanent node in |
| 116 // the sync domain. Such permanent nodes are identified by a tag that is | 116 // the sync domain. Such permanent nodes are identified by a tag that is |
| 117 // well known to the server and the client, and is unique within a particular | 117 // well known to the server and the client, and is unique within a particular |
| 118 // user's share. For example, "other_bookmarks" is the tag for the Other | 118 // user's share. For example, "other_bookmarks" is the tag for the Other |
| 119 // Bookmarks folder. The sync nodes are server-created. | 119 // Bookmarks folder. The sync nodes are server-created. |
| 120 bool AssociateTaggedPermanentNode(const BookmarkNode* permanent_node, | 120 bool AssociateTaggedPermanentNode(const BookmarkNode* permanent_node, |
| 121 const string16& tag); | 121 const string16& tag); |
| 122 | 122 |
| 123 // Compare the properties of a pair of nodes from either domain. | 123 // Compare the properties of a pair of nodes from either domain. |
| 124 bool NodesMatch(const BookmarkNode* bookmark, | 124 bool NodesMatch(const BookmarkNode* bookmark, |
| 125 const sync_api::BaseNode* sync_node) const; | 125 const sync_api::BaseNode* sync_node) const; |
| 126 | 126 |
| 127 ProfileSyncService* sync_service_; | 127 ProfileSyncService* sync_service_; |
| 128 BookmarkIdToSyncIdMap id_map_; | 128 BookmarkIdToSyncIdMap id_map_; |
| 129 SyncIdToBookmarkIdMap id_map_inverse_; | 129 SyncIdToBookmarkIdMap id_map_inverse_; |
| 130 // Stores sync ids for dirty associations. | 130 // Stores sync ids for dirty associations. |
| 131 DirtyAssocationsSyncIds dirty_assocations_sync_ids_; | 131 DirtyAssociationsSyncIds dirty_associations_sync_ids_; |
| 132 | 132 |
| 133 // Indicates whether there is already a pending task to persist dirty model | 133 // Indicates whether there is already a pending task to persist dirty model |
| 134 // associations. | 134 // associations. |
| 135 bool task_pending_; | 135 bool task_pending_; |
| 136 | 136 |
| 137 DISALLOW_COPY_AND_ASSIGN(ModelAssociator); | 137 DISALLOW_COPY_AND_ASSIGN(ModelAssociator); |
| 138 }; | 138 }; |
| 139 | 139 |
| 140 } // namespace browser_sync | 140 } // namespace browser_sync |
| 141 | 141 |
| 142 #endif // CHROME_BROWSER_SYNC_GLUE_MODEL_ASSOCATOR_H_ | 142 #endif // CHROME_BROWSER_SYNC_GLUE_MODEL_ASSOCIATOR_H_ |
| 143 #endif // defined(BROWSER_SYNC) | 143 #endif // defined(BROWSER_SYNC) |
| OLD | NEW |