Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: chrome/browser/sync/glue/bookmark_model_associator.h

Issue 865163003: bookmarks: Move BookmarkNode into 'bookmarks' namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: enhanced_bookmarks fix Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_ 5 #ifndef CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_
6 #define CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_ 6 #define CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "components/sync_driver/data_type_controller.h" 15 #include "components/sync_driver/data_type_controller.h"
16 #include "components/sync_driver/data_type_error_handler.h" 16 #include "components/sync_driver/data_type_error_handler.h"
17 #include "components/sync_driver/model_associator.h" 17 #include "components/sync_driver/model_associator.h"
18 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" 18 #include "sync/internal_api/public/util/unrecoverable_error_handler.h"
19 19
20 class BookmarkNode;
21 class Profile; 20 class Profile;
22 21
23 namespace bookmarks { 22 namespace bookmarks {
24 class BookmarkModel; 23 class BookmarkModel;
24 class BookmarkNode;
25 } 25 }
26 26
27 namespace syncer { 27 namespace syncer {
28 class BaseNode; 28 class BaseNode;
29 class BaseTransaction; 29 class BaseTransaction;
30 struct UserShare; 30 struct UserShare;
31 } 31 }
32 32
33 namespace browser_sync { 33 namespace browser_sync {
34 34
35 // Contains all model association related logic: 35 // Contains all model association related logic:
36 // * Algorithm to associate bookmark model and sync model. 36 // * Algorithm to associate bookmark model and sync model.
37 // * Methods to get a bookmark node for a given sync node and vice versa. 37 // * Methods to get a bookmark node for a given sync node and vice versa.
38 // * Persisting model associations and loading them back. 38 // * Persisting model associations and loading them back.
39 class BookmarkModelAssociator 39 class BookmarkModelAssociator
40 : public sync_driver::PerDataTypeAssociatorInterface<BookmarkNode, int64> { 40 : public sync_driver::
41 PerDataTypeAssociatorInterface<bookmarks::BookmarkNode, int64> {
41 public: 42 public:
42 static syncer::ModelType model_type() { return syncer::BOOKMARKS; } 43 static syncer::ModelType model_type() { return syncer::BOOKMARKS; }
43 // |expect_mobile_bookmarks_folder| controls whether or not we 44 // |expect_mobile_bookmarks_folder| controls whether or not we
44 // expect the mobile bookmarks permanent folder to be created. 45 // expect the mobile bookmarks permanent folder to be created.
45 // Should be set to true only by mobile clients. 46 // Should be set to true only by mobile clients.
46 BookmarkModelAssociator( 47 BookmarkModelAssociator(
47 bookmarks::BookmarkModel* bookmark_model, 48 bookmarks::BookmarkModel* bookmark_model,
48 Profile* profile_, 49 Profile* profile_,
49 syncer::UserShare* user_share, 50 syncer::UserShare* user_share,
50 sync_driver::DataTypeErrorHandler* unrecoverable_error_handler, 51 sync_driver::DataTypeErrorHandler* unrecoverable_error_handler,
(...skipping 22 matching lines...) Expand all
73 // than the permanent tagged nodes. 74 // than the permanent tagged nodes.
74 bool SyncModelHasUserCreatedNodes(bool* has_nodes) override; 75 bool SyncModelHasUserCreatedNodes(bool* has_nodes) override;
75 76
76 // Returns sync id for the given bookmark node id. 77 // Returns sync id for the given bookmark node id.
77 // Returns syncer::kInvalidId if the sync node is not found for the given 78 // Returns syncer::kInvalidId if the sync node is not found for the given
78 // bookmark node id. 79 // bookmark node id.
79 int64 GetSyncIdFromChromeId(const int64& node_id) override; 80 int64 GetSyncIdFromChromeId(const int64& node_id) override;
80 81
81 // Returns the bookmark node for the given sync id. 82 // Returns the bookmark node for the given sync id.
82 // Returns NULL if no bookmark node is found for the given sync id. 83 // Returns NULL if no bookmark node is found for the given sync id.
83 const BookmarkNode* GetChromeNodeFromSyncId(int64 sync_id) override; 84 const bookmarks::BookmarkNode* GetChromeNodeFromSyncId(
85 int64 sync_id) override;
84 86
85 // Initializes the given sync node from the given bookmark node id. 87 // Initializes the given sync node from the given bookmark node id.
86 // Returns false if no sync node was found for the given bookmark node id or 88 // Returns false if no sync node was found for the given bookmark node id or
87 // if the initialization of sync node fails. 89 // if the initialization of sync node fails.
88 bool InitSyncNodeFromChromeId(const int64& node_id, 90 bool InitSyncNodeFromChromeId(const int64& node_id,
89 syncer::BaseNode* sync_node) override; 91 syncer::BaseNode* sync_node) override;
90 92
91 // Associates the given bookmark node with the given sync id. 93 // Associates the given bookmark node with the given sync id.
92 void Associate(const BookmarkNode* node, int64 sync_id) override; 94 void Associate(const bookmarks::BookmarkNode* node, int64 sync_id) override;
93 // Remove the association that corresponds to the given sync id. 95 // Remove the association that corresponds to the given sync id.
94 void Disassociate(int64 sync_id) override; 96 void Disassociate(int64 sync_id) override;
95 97
96 void AbortAssociation() override { 98 void AbortAssociation() override {
97 // No implementation needed, this associator runs on the main 99 // No implementation needed, this associator runs on the main
98 // thread. 100 // thread.
99 } 101 }
100 102
101 // See ModelAssociator interface. 103 // See ModelAssociator interface.
102 bool CryptoReadyIfNecessary() override; 104 bool CryptoReadyIfNecessary() override;
103 105
104 protected: 106 protected:
105 // Stores the id of the node with the given tag in |sync_id|. 107 // Stores the id of the node with the given tag in |sync_id|.
106 // Returns of that node was found successfully. 108 // Returns of that node was found successfully.
107 // Tests override this. 109 // Tests override this.
108 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id); 110 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id);
109 111
110 private: 112 private:
111 typedef std::map<int64, int64> BookmarkIdToSyncIdMap; 113 typedef std::map<int64, int64> BookmarkIdToSyncIdMap;
112 typedef std::map<int64, const BookmarkNode*> SyncIdToBookmarkNodeMap; 114 typedef std::map<int64, const bookmarks::BookmarkNode*>
115 SyncIdToBookmarkNodeMap;
113 typedef std::set<int64> DirtyAssociationsSyncIds; 116 typedef std::set<int64> DirtyAssociationsSyncIds;
114 117
115 // Posts a task to persist dirty associations. 118 // Posts a task to persist dirty associations.
116 void PostPersistAssociationsTask(); 119 void PostPersistAssociationsTask();
117 // Persists all dirty associations. 120 // Persists all dirty associations.
118 void PersistAssociations(); 121 void PersistAssociations();
119 122
120 // Matches up the bookmark model and the sync model to build model 123 // Matches up the bookmark model and the sync model to build model
121 // associations. 124 // associations.
122 syncer::SyncError BuildAssociations( 125 syncer::SyncError BuildAssociations(
123 syncer::SyncMergeResult* local_merge_result, 126 syncer::SyncMergeResult* local_merge_result,
124 syncer::SyncMergeResult* syncer_merge_result); 127 syncer::SyncMergeResult* syncer_merge_result);
125 128
126 // Removes bookmark nodes whose corresponding sync nodes have been deleted 129 // Removes bookmark nodes whose corresponding sync nodes have been deleted
127 // according to sync delete journals. Return number of deleted bookmarks. 130 // according to sync delete journals. Return number of deleted bookmarks.
128 int64 ApplyDeletesFromSyncJournal(syncer::BaseTransaction* trans); 131 int64 ApplyDeletesFromSyncJournal(syncer::BaseTransaction* trans);
129 132
130 // Associate a top-level node of the bookmark model with a permanent node in 133 // Associate a top-level node of the bookmark model with a permanent node in
131 // the sync domain. Such permanent nodes are identified by a tag that is 134 // the sync domain. Such permanent nodes are identified by a tag that is
132 // well known to the server and the client, and is unique within a particular 135 // well known to the server and the client, and is unique within a particular
133 // user's share. For example, "other_bookmarks" is the tag for the Other 136 // user's share. For example, "other_bookmarks" is the tag for the Other
134 // Bookmarks folder. The sync nodes are server-created. 137 // Bookmarks folder. The sync nodes are server-created.
135 // Returns true on success, false if association failed. 138 // Returns true on success, false if association failed.
136 bool AssociateTaggedPermanentNode( 139 bool AssociateTaggedPermanentNode(
137 const BookmarkNode* permanent_node, 140 const bookmarks::BookmarkNode* permanent_node,
138 const std::string& tag) WARN_UNUSED_RESULT; 141 const std::string& tag) WARN_UNUSED_RESULT;
139 142
140 // Compare the properties of a pair of nodes from either domain. 143 // Compare the properties of a pair of nodes from either domain.
141 bool NodesMatch(const BookmarkNode* bookmark, 144 bool NodesMatch(const bookmarks::BookmarkNode* bookmark,
142 const syncer::BaseNode* sync_node) const; 145 const syncer::BaseNode* sync_node) const;
143 146
144 // Check whether bookmark model and sync model are synced by comparing 147 // Check whether bookmark model and sync model are synced by comparing
145 // their transaction versions. 148 // their transaction versions.
146 // Returns a PERSISTENCE_ERROR if a transaction mismatch was detected where 149 // Returns a PERSISTENCE_ERROR if a transaction mismatch was detected where
147 // the native model has a newer transaction verison. 150 // the native model has a newer transaction verison.
148 syncer::SyncError CheckModelSyncState( 151 syncer::SyncError CheckModelSyncState(
149 syncer::SyncMergeResult* local_merge_result, 152 syncer::SyncMergeResult* local_merge_result,
150 syncer::SyncMergeResult* syncer_merge_result) const; 153 syncer::SyncMergeResult* syncer_merge_result) const;
151 154
(...skipping 11 matching lines...) Expand all
163 // guarantees no invocations can occur if |this| has been deleted. (This 166 // guarantees no invocations can occur if |this| has been deleted. (This
164 // allows this class to be non-refcounted). 167 // allows this class to be non-refcounted).
165 base::WeakPtrFactory<BookmarkModelAssociator> weak_factory_; 168 base::WeakPtrFactory<BookmarkModelAssociator> weak_factory_;
166 169
167 DISALLOW_COPY_AND_ASSIGN(BookmarkModelAssociator); 170 DISALLOW_COPY_AND_ASSIGN(BookmarkModelAssociator);
168 }; 171 };
169 172
170 } // namespace browser_sync 173 } // namespace browser_sync
171 174
172 #endif // CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_ 175 #endif // CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698