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> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
16 #include "components/bookmarks/browser/bookmark_model_observer.h" | 16 #include "components/bookmarks/browser/bookmark_model_observer.h" |
17 #include "components/bookmarks/browser/bookmark_node.h" | 17 #include "components/bookmarks/browser/bookmark_node.h" |
18 #include "components/sync_bookmarks/bookmark_model_associator.h" | 18 #include "components/sync_bookmarks/bookmark_model_associator.h" |
19 #include "components/sync_driver/change_processor.h" | 19 #include "components/sync_driver/change_processor.h" |
20 #include "components/sync_driver/data_type_error_handler.h" | 20 #include "sync/internal_api/public/data_type_error_handler.h" |
21 | 21 |
22 class Profile; | 22 class Profile; |
23 | 23 |
24 namespace base { | 24 namespace base { |
25 class RefCountedMemory; | 25 class RefCountedMemory; |
26 } | 26 } |
27 | 27 |
28 namespace syncer { | 28 namespace syncer { |
29 class WriteNode; | 29 class WriteNode; |
30 class WriteTransaction; | 30 class WriteTransaction; |
31 } // namespace syncer | 31 } // namespace syncer |
32 | 32 |
33 namespace sync_driver { | 33 namespace sync_driver { |
34 class SyncClient; | 34 class SyncClient; |
35 } | 35 } |
36 | 36 |
37 namespace browser_sync { | 37 namespace browser_sync { |
38 | 38 |
39 // This class is responsible for taking changes from the BookmarkModel | 39 // This class is responsible for taking changes from the BookmarkModel |
40 // and applying them to the sync API 'syncable' model, and vice versa. | 40 // and applying them to the sync API 'syncable' model, and vice versa. |
41 // All operations and use of this class are from the UI thread. | 41 // All operations and use of this class are from the UI thread. |
42 // This is currently bookmarks specific. | 42 // This is currently bookmarks specific. |
43 class BookmarkChangeProcessor : public bookmarks::BookmarkModelObserver, | 43 class BookmarkChangeProcessor : public bookmarks::BookmarkModelObserver, |
44 public sync_driver::ChangeProcessor { | 44 public sync_driver::ChangeProcessor { |
45 public: | 45 public: |
46 BookmarkChangeProcessor(sync_driver::SyncClient* sync_client, | 46 BookmarkChangeProcessor(sync_driver::SyncClient* sync_client, |
47 BookmarkModelAssociator* model_associator, | 47 BookmarkModelAssociator* model_associator, |
48 sync_driver::DataTypeErrorHandler* error_handler); | 48 syncer::DataTypeErrorHandler* error_handler); |
49 ~BookmarkChangeProcessor() override; | 49 ~BookmarkChangeProcessor() override; |
50 | 50 |
51 // bookmarks::BookmarkModelObserver: | 51 // bookmarks::BookmarkModelObserver: |
52 // BookmarkModel -> sync API model change application. | 52 // BookmarkModel -> sync API model change application. |
53 void BookmarkModelLoaded(bookmarks::BookmarkModel* model, | 53 void BookmarkModelLoaded(bookmarks::BookmarkModel* model, |
54 bool ids_reassigned) override; | 54 bool ids_reassigned) override; |
55 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override; | 55 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override; |
56 void BookmarkNodeMoved(bookmarks::BookmarkModel* model, | 56 void BookmarkNodeMoved(bookmarks::BookmarkModel* model, |
57 const bookmarks::BookmarkNode* old_parent, | 57 const bookmarks::BookmarkNode* old_parent, |
58 int old_index, | 58 int old_index, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // Sets the favicon of the given sync node from the given bookmark node. | 142 // Sets the favicon of the given sync node from the given bookmark node. |
143 static void SetSyncNodeFavicon(const bookmarks::BookmarkNode* bookmark_node, | 143 static void SetSyncNodeFavicon(const bookmarks::BookmarkNode* bookmark_node, |
144 bookmarks::BookmarkModel* model, | 144 bookmarks::BookmarkModel* model, |
145 syncer::WriteNode* sync_node); | 145 syncer::WriteNode* sync_node); |
146 | 146 |
147 // Treat the |index|th child of |parent| as a newly added node, and create a | 147 // Treat the |index|th child of |parent| as a newly added node, and create a |
148 // corresponding node in the sync domain using |trans|. All properties | 148 // corresponding node in the sync domain using |trans|. All properties |
149 // will be transferred to the new node. A node corresponding to |parent| | 149 // will be transferred to the new node. A node corresponding to |parent| |
150 // must already exist and be associated for this call to succeed. Returns | 150 // must already exist and be associated for this call to succeed. Returns |
151 // the ID of the just-created node, or if creation fails, kInvalidID. | 151 // the ID of the just-created node, or if creation fails, kInvalidID. |
152 static int64_t CreateSyncNode( | 152 static int64_t CreateSyncNode(const bookmarks::BookmarkNode* parent, |
153 const bookmarks::BookmarkNode* parent, | 153 bookmarks::BookmarkModel* model, |
154 bookmarks::BookmarkModel* model, | 154 int index, |
155 int index, | 155 syncer::WriteTransaction* trans, |
156 syncer::WriteTransaction* trans, | 156 BookmarkModelAssociator* associator, |
157 BookmarkModelAssociator* associator, | 157 syncer::DataTypeErrorHandler* error_handler); |
158 sync_driver::DataTypeErrorHandler* error_handler); | |
159 | 158 |
160 // Update |bookmark_node|'s sync node. | 159 // Update |bookmark_node|'s sync node. |
161 static int64_t UpdateSyncNode( | 160 static int64_t UpdateSyncNode(const bookmarks::BookmarkNode* bookmark_node, |
162 const bookmarks::BookmarkNode* bookmark_node, | 161 bookmarks::BookmarkModel* model, |
163 bookmarks::BookmarkModel* model, | 162 syncer::WriteTransaction* trans, |
164 syncer::WriteTransaction* trans, | 163 BookmarkModelAssociator* associator, |
165 BookmarkModelAssociator* associator, | 164 syncer::DataTypeErrorHandler* error_handler); |
166 sync_driver::DataTypeErrorHandler* error_handler); | |
167 | 165 |
168 // Tombstone |topmost_sync_node| node and all its children in the sync domain | 166 // Tombstone |topmost_sync_node| node and all its children in the sync domain |
169 // using transaction |trans|. Returns the number of removed nodes. | 167 // using transaction |trans|. Returns the number of removed nodes. |
170 static int RemoveSyncNodeHierarchy(syncer::WriteTransaction* trans, | 168 static int RemoveSyncNodeHierarchy(syncer::WriteTransaction* trans, |
171 syncer::WriteNode* topmost_sync_node, | 169 syncer::WriteNode* topmost_sync_node, |
172 BookmarkModelAssociator* associator); | 170 BookmarkModelAssociator* associator); |
173 | 171 |
174 // Update transaction version of |model| and |nodes| to |new_version| if | 172 // Update transaction version of |model| and |nodes| to |new_version| if |
175 // it's valid. | 173 // it's valid. |
176 static void UpdateTransactionVersion( | 174 static void UpdateTransactionVersion( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 int index, | 206 int index, |
209 syncer::WriteTransaction* trans, | 207 syncer::WriteTransaction* trans, |
210 syncer::WriteNode* dst, | 208 syncer::WriteNode* dst, |
211 BookmarkModelAssociator* associator); | 209 BookmarkModelAssociator* associator); |
212 | 210 |
213 // Copy properties (but not position) from |src| to |dst|. | 211 // Copy properties (but not position) from |src| to |dst|. |
214 static void UpdateSyncNodeProperties( | 212 static void UpdateSyncNodeProperties( |
215 const bookmarks::BookmarkNode* src, | 213 const bookmarks::BookmarkNode* src, |
216 bookmarks::BookmarkModel* model, | 214 bookmarks::BookmarkModel* model, |
217 syncer::WriteNode* dst, | 215 syncer::WriteNode* dst, |
218 sync_driver::DataTypeErrorHandler* error_handler); | 216 syncer::DataTypeErrorHandler* error_handler); |
219 | 217 |
220 // Helper function to encode a bookmark's favicon into raw PNG data. | 218 // Helper function to encode a bookmark's favicon into raw PNG data. |
221 static void EncodeFavicon(const bookmarks::BookmarkNode* src, | 219 static void EncodeFavicon(const bookmarks::BookmarkNode* src, |
222 bookmarks::BookmarkModel* model, | 220 bookmarks::BookmarkModel* model, |
223 scoped_refptr<base::RefCountedMemory>* dst); | 221 scoped_refptr<base::RefCountedMemory>* dst); |
224 | 222 |
225 // Remove all sync nodes, except the permanent nodes. | 223 // Remove all sync nodes, except the permanent nodes. |
226 void RemoveAllSyncNodes(); | 224 void RemoveAllSyncNodes(); |
227 | 225 |
228 // Remove all the sync nodes associated with |node| and its children. | 226 // Remove all the sync nodes associated with |node| and its children. |
(...skipping 25 matching lines...) Expand all Loading... |
254 | 252 |
255 // The two models should be associated according to this ModelAssociator. | 253 // The two models should be associated according to this ModelAssociator. |
256 BookmarkModelAssociator* model_associator_; | 254 BookmarkModelAssociator* model_associator_; |
257 | 255 |
258 DISALLOW_COPY_AND_ASSIGN(BookmarkChangeProcessor); | 256 DISALLOW_COPY_AND_ASSIGN(BookmarkChangeProcessor); |
259 }; | 257 }; |
260 | 258 |
261 } // namespace browser_sync | 259 } // namespace browser_sync |
262 | 260 |
263 #endif // COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_CHANGE_PROCESSOR_H_ | 261 #endif // COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_CHANGE_PROCESSOR_H_ |
OLD | NEW |