OLD | NEW |
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 COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_CHANGE_PROCESSOR_H_ | 5 #ifndef COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_CHANGE_PROCESSOR_H_ |
6 #define COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_CHANGE_PROCESSOR_H_ | 6 #define COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_CHANGE_PROCESSOR_H_ |
7 | 7 |
| 8 #include <stdint.h> |
| 9 |
8 #include <vector> | 10 #include <vector> |
9 | 11 |
10 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/macros.h" |
11 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
12 #include "components/bookmarks/browser/bookmark_model_observer.h" | 15 #include "components/bookmarks/browser/bookmark_model_observer.h" |
13 #include "components/bookmarks/browser/bookmark_node.h" | 16 #include "components/bookmarks/browser/bookmark_node.h" |
14 #include "components/sync_bookmarks/bookmark_model_associator.h" | 17 #include "components/sync_bookmarks/bookmark_model_associator.h" |
15 #include "components/sync_driver/change_processor.h" | 18 #include "components/sync_driver/change_processor.h" |
16 #include "components/sync_driver/data_type_error_handler.h" | 19 #include "components/sync_driver/data_type_error_handler.h" |
17 | 20 |
18 class Profile; | 21 class Profile; |
19 | 22 |
20 namespace base { | 23 namespace base { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 void BookmarkNodeFaviconChanged(bookmarks::BookmarkModel* model, | 78 void BookmarkNodeFaviconChanged(bookmarks::BookmarkModel* model, |
76 const bookmarks::BookmarkNode* node) override; | 79 const bookmarks::BookmarkNode* node) override; |
77 void BookmarkNodeChildrenReordered( | 80 void BookmarkNodeChildrenReordered( |
78 bookmarks::BookmarkModel* model, | 81 bookmarks::BookmarkModel* model, |
79 const bookmarks::BookmarkNode* node) override; | 82 const bookmarks::BookmarkNode* node) override; |
80 | 83 |
81 // The change processor implementation, responsible for applying changes from | 84 // The change processor implementation, responsible for applying changes from |
82 // the sync model to the bookmarks model. | 85 // the sync model to the bookmarks model. |
83 void ApplyChangesFromSyncModel( | 86 void ApplyChangesFromSyncModel( |
84 const syncer::BaseTransaction* trans, | 87 const syncer::BaseTransaction* trans, |
85 int64 model_version, | 88 int64_t model_version, |
86 const syncer::ImmutableChangeRecordList& changes) override; | 89 const syncer::ImmutableChangeRecordList& changes) override; |
87 | 90 |
88 // The following methods are static and hence may be invoked at any time, and | 91 // The following methods are static and hence may be invoked at any time, and |
89 // do not depend on having a running ChangeProcessor. | 92 // do not depend on having a running ChangeProcessor. |
90 // TODO(stanisc): considier refactoring these methods out of this class. | 93 // TODO(stanisc): considier refactoring these methods out of this class. |
91 | 94 |
92 // Updates the title, URL, creation time and favicon of the bookmark |node| | 95 // Updates the title, URL, creation time and favicon of the bookmark |node| |
93 // with data taken from the |sync_node| sync node. | 96 // with data taken from the |sync_node| sync node. |
94 static void UpdateBookmarkWithSyncData(const syncer::BaseNode& sync_node, | 97 static void UpdateBookmarkWithSyncData(const syncer::BaseNode& sync_node, |
95 bookmarks::BookmarkModel* model, | 98 bookmarks::BookmarkModel* model, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 // Sets the favicon of the given sync node from the given bookmark node. | 141 // Sets the favicon of the given sync node from the given bookmark node. |
139 static void SetSyncNodeFavicon(const bookmarks::BookmarkNode* bookmark_node, | 142 static void SetSyncNodeFavicon(const bookmarks::BookmarkNode* bookmark_node, |
140 bookmarks::BookmarkModel* model, | 143 bookmarks::BookmarkModel* model, |
141 syncer::WriteNode* sync_node); | 144 syncer::WriteNode* sync_node); |
142 | 145 |
143 // Treat the |index|th child of |parent| as a newly added node, and create a | 146 // Treat the |index|th child of |parent| as a newly added node, and create a |
144 // corresponding node in the sync domain using |trans|. All properties | 147 // corresponding node in the sync domain using |trans|. All properties |
145 // will be transferred to the new node. A node corresponding to |parent| | 148 // will be transferred to the new node. A node corresponding to |parent| |
146 // must already exist and be associated for this call to succeed. Returns | 149 // must already exist and be associated for this call to succeed. Returns |
147 // the ID of the just-created node, or if creation fails, kInvalidID. | 150 // the ID of the just-created node, or if creation fails, kInvalidID. |
148 static int64 CreateSyncNode(const bookmarks::BookmarkNode* parent, | 151 static int64_t CreateSyncNode( |
149 bookmarks::BookmarkModel* model, | 152 const bookmarks::BookmarkNode* parent, |
150 int index, | 153 bookmarks::BookmarkModel* model, |
151 syncer::WriteTransaction* trans, | 154 int index, |
152 BookmarkModelAssociator* associator, | 155 syncer::WriteTransaction* trans, |
153 sync_driver::DataTypeErrorHandler* error_handler); | 156 BookmarkModelAssociator* associator, |
| 157 sync_driver::DataTypeErrorHandler* error_handler); |
154 | 158 |
155 // Update |bookmark_node|'s sync node. | 159 // Update |bookmark_node|'s sync node. |
156 static int64 UpdateSyncNode(const bookmarks::BookmarkNode* bookmark_node, | 160 static int64_t UpdateSyncNode( |
157 bookmarks::BookmarkModel* model, | 161 const bookmarks::BookmarkNode* bookmark_node, |
158 syncer::WriteTransaction* trans, | 162 bookmarks::BookmarkModel* model, |
159 BookmarkModelAssociator* associator, | 163 syncer::WriteTransaction* trans, |
160 sync_driver::DataTypeErrorHandler* error_handler); | 164 BookmarkModelAssociator* associator, |
| 165 sync_driver::DataTypeErrorHandler* error_handler); |
161 | 166 |
162 // Tombstone |topmost_sync_node| node and all its children in the sync domain | 167 // Tombstone |topmost_sync_node| node and all its children in the sync domain |
163 // using transaction |trans|. Returns the number of removed nodes. | 168 // using transaction |trans|. Returns the number of removed nodes. |
164 static int RemoveSyncNodeHierarchy(syncer::WriteTransaction* trans, | 169 static int RemoveSyncNodeHierarchy(syncer::WriteTransaction* trans, |
165 syncer::WriteNode* topmost_sync_node, | 170 syncer::WriteNode* topmost_sync_node, |
166 BookmarkModelAssociator* associator); | 171 BookmarkModelAssociator* associator); |
167 | 172 |
168 // Update transaction version of |model| and |nodes| to |new_version| if | 173 // Update transaction version of |model| and |nodes| to |new_version| if |
169 // it's valid. | 174 // it's valid. |
170 static void UpdateTransactionVersion( | 175 static void UpdateTransactionVersion( |
171 int64 new_version, | 176 int64_t new_version, |
172 bookmarks::BookmarkModel* model, | 177 bookmarks::BookmarkModel* model, |
173 const std::vector<const bookmarks::BookmarkNode*>& nodes); | 178 const std::vector<const bookmarks::BookmarkNode*>& nodes); |
174 | 179 |
175 protected: | 180 protected: |
176 void StartImpl() override; | 181 void StartImpl() override; |
177 | 182 |
178 private: | 183 private: |
179 enum MoveOrCreate { | 184 enum MoveOrCreate { |
180 MOVE, | 185 MOVE, |
181 CREATE, | 186 CREATE, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 223 |
219 // Remove all sync nodes, except the permanent nodes. | 224 // Remove all sync nodes, except the permanent nodes. |
220 void RemoveAllSyncNodes(); | 225 void RemoveAllSyncNodes(); |
221 | 226 |
222 // Remove all the sync nodes associated with |node| and its children. | 227 // Remove all the sync nodes associated with |node| and its children. |
223 void RemoveSyncNodeHierarchy(const bookmarks::BookmarkNode* node); | 228 void RemoveSyncNodeHierarchy(const bookmarks::BookmarkNode* node); |
224 | 229 |
225 // Remove all children of |sync_node|. Returns the number of removed | 230 // Remove all children of |sync_node|. Returns the number of removed |
226 // children. | 231 // children. |
227 static int RemoveAllChildNodes(syncer::WriteTransaction* trans, | 232 static int RemoveAllChildNodes(syncer::WriteTransaction* trans, |
228 int64 sync_id, | 233 int64_t sync_id, |
229 BookmarkModelAssociator* associator); | 234 BookmarkModelAssociator* associator); |
230 | 235 |
231 // Remove |sync_node|. It should not have any children. | 236 // Remove |sync_node|. It should not have any children. |
232 static void RemoveOneSyncNode(syncer::WriteNode* sync_node, | 237 static void RemoveOneSyncNode(syncer::WriteNode* sync_node, |
233 BookmarkModelAssociator* associator); | 238 BookmarkModelAssociator* associator); |
234 | 239 |
235 // Creates or updates a sync node associated with |node|. | 240 // Creates or updates a sync node associated with |node|. |
236 void CreateOrUpdateSyncNode(const bookmarks::BookmarkNode* node); | 241 void CreateOrUpdateSyncNode(const bookmarks::BookmarkNode* node); |
237 | 242 |
238 // Returns false if |node| should not be synced. | 243 // Returns false if |node| should not be synced. |
239 bool CanSyncNode(const bookmarks::BookmarkNode* node); | 244 bool CanSyncNode(const bookmarks::BookmarkNode* node); |
240 | 245 |
241 base::ThreadChecker thread_checker_; | 246 base::ThreadChecker thread_checker_; |
242 | 247 |
243 // The bookmark model we are processing changes from. Non-NULL when | 248 // The bookmark model we are processing changes from. Non-NULL when |
244 // |running_| is true. | 249 // |running_| is true. |
245 bookmarks::BookmarkModel* bookmark_model_; | 250 bookmarks::BookmarkModel* bookmark_model_; |
246 | 251 |
247 sync_driver::SyncClient* sync_client_; | 252 sync_driver::SyncClient* sync_client_; |
248 | 253 |
249 // The two models should be associated according to this ModelAssociator. | 254 // The two models should be associated according to this ModelAssociator. |
250 BookmarkModelAssociator* model_associator_; | 255 BookmarkModelAssociator* model_associator_; |
251 | 256 |
252 DISALLOW_COPY_AND_ASSIGN(BookmarkChangeProcessor); | 257 DISALLOW_COPY_AND_ASSIGN(BookmarkChangeProcessor); |
253 }; | 258 }; |
254 | 259 |
255 } // namespace browser_sync | 260 } // namespace browser_sync |
256 | 261 |
257 #endif // COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_CHANGE_PROCESSOR_H_ | 262 #endif // COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_CHANGE_PROCESSOR_H_ |
OLD | NEW |