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 <set> | 11 #include <set> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
17 #include "components/bookmarks/browser/bookmark_model_observer.h" | 17 #include "components/bookmarks/browser/bookmark_model_observer.h" |
18 #include "components/bookmarks/browser/bookmark_node.h" | 18 #include "components/bookmarks/browser/bookmark_node.h" |
19 #include "components/sync/api/data_type_error_handler.h" | 19 #include "components/sync/api/data_type_error_handler.h" |
20 #include "components/sync/driver/change_processor.h" | 20 #include "components/sync/driver/change_processor.h" |
21 #include "components/sync_bookmarks/bookmark_model_associator.h" | 21 #include "components/sync_bookmarks/bookmark_model_associator.h" |
22 | 22 |
23 class Profile; | 23 class Profile; |
24 | 24 |
25 namespace base { | 25 namespace base { |
26 class RefCountedMemory; | 26 class RefCountedMemory; |
27 } // namespace base | 27 } |
28 | 28 |
29 namespace syncer { | 29 namespace syncer { |
30 class SyncClient; | |
31 class WriteNode; | 30 class WriteNode; |
32 class WriteTransaction; | 31 class WriteTransaction; |
33 } // namespace syncer | 32 } // namespace syncer |
34 | 33 |
| 34 namespace sync_driver { |
| 35 class SyncClient; |
| 36 } |
| 37 |
35 namespace sync_bookmarks { | 38 namespace sync_bookmarks { |
36 | 39 |
37 // This class is responsible for taking changes from the BookmarkModel | 40 // This class is responsible for taking changes from the BookmarkModel |
38 // and applying them to the sync API 'syncable' model, and vice versa. | 41 // and applying them to the sync API 'syncable' model, and vice versa. |
39 // All operations and use of this class are from the UI thread. | 42 // All operations and use of this class are from the UI thread. |
40 // This is currently bookmarks specific. | 43 // This is currently bookmarks specific. |
41 class BookmarkChangeProcessor : public bookmarks::BookmarkModelObserver, | 44 class BookmarkChangeProcessor : public bookmarks::BookmarkModelObserver, |
42 public syncer::ChangeProcessor { | 45 public sync_driver::ChangeProcessor { |
43 public: | 46 public: |
44 BookmarkChangeProcessor( | 47 BookmarkChangeProcessor( |
45 syncer::SyncClient* sync_client, | 48 sync_driver::SyncClient* sync_client, |
46 BookmarkModelAssociator* model_associator, | 49 BookmarkModelAssociator* model_associator, |
47 std::unique_ptr<syncer::DataTypeErrorHandler> error_handler); | 50 std::unique_ptr<syncer::DataTypeErrorHandler> error_handler); |
48 ~BookmarkChangeProcessor() override; | 51 ~BookmarkChangeProcessor() override; |
49 | 52 |
50 // bookmarks::BookmarkModelObserver: | 53 // bookmarks::BookmarkModelObserver: |
51 // BookmarkModel -> sync API model change application. | 54 // BookmarkModel -> sync API model change application. |
52 void BookmarkModelLoaded(bookmarks::BookmarkModel* model, | 55 void BookmarkModelLoaded(bookmarks::BookmarkModel* model, |
53 bool ids_reassigned) override; | 56 bool ids_reassigned) override; |
54 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override; | 57 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override; |
55 void BookmarkNodeMoved(bookmarks::BookmarkModel* model, | 58 void BookmarkNodeMoved(bookmarks::BookmarkModel* model, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 93 |
91 // The following methods are static and hence may be invoked at any time, and | 94 // The following methods are static and hence may be invoked at any time, and |
92 // do not depend on having a running ChangeProcessor. | 95 // do not depend on having a running ChangeProcessor. |
93 // TODO(stanisc): considier refactoring these methods out of this class. | 96 // TODO(stanisc): considier refactoring these methods out of this class. |
94 | 97 |
95 // Updates the title, URL, creation time and favicon of the bookmark |node| | 98 // Updates the title, URL, creation time and favicon of the bookmark |node| |
96 // with data taken from the |sync_node| sync node. | 99 // with data taken from the |sync_node| sync node. |
97 static void UpdateBookmarkWithSyncData(const syncer::BaseNode& sync_node, | 100 static void UpdateBookmarkWithSyncData(const syncer::BaseNode& sync_node, |
98 bookmarks::BookmarkModel* model, | 101 bookmarks::BookmarkModel* model, |
99 const bookmarks::BookmarkNode* node, | 102 const bookmarks::BookmarkNode* node, |
100 syncer::SyncClient* sync_client); | 103 sync_driver::SyncClient* sync_client); |
101 | 104 |
102 // Creates a bookmark node under the given parent node from the given sync | 105 // Creates a bookmark node under the given parent node from the given sync |
103 // node. Returns the newly created node. The created node is placed at the | 106 // node. Returns the newly created node. The created node is placed at the |
104 // specified index among the parent's children. | 107 // specified index among the parent's children. |
105 static const bookmarks::BookmarkNode* CreateBookmarkNode( | 108 static const bookmarks::BookmarkNode* CreateBookmarkNode( |
106 const syncer::BaseNode* sync_node, | 109 const syncer::BaseNode* sync_node, |
107 const bookmarks::BookmarkNode* parent, | 110 const bookmarks::BookmarkNode* parent, |
108 bookmarks::BookmarkModel* model, | 111 bookmarks::BookmarkModel* model, |
109 syncer::SyncClient* sync_client, | 112 sync_driver::SyncClient* sync_client, |
110 int index); | 113 int index); |
111 | 114 |
112 // Overload of CreateBookmarkNode function above that helps to avoid | 115 // Overload of CreateBookmarkNode function above that helps to avoid |
113 // converting / parsing the bookmark title and URL multiple times. | 116 // converting / parsing the bookmark title and URL multiple times. |
114 static const bookmarks::BookmarkNode* CreateBookmarkNode( | 117 static const bookmarks::BookmarkNode* CreateBookmarkNode( |
115 const base::string16& title, | 118 const base::string16& title, |
116 const GURL& url, | 119 const GURL& url, |
117 const syncer::BaseNode* sync_node, | 120 const syncer::BaseNode* sync_node, |
118 const bookmarks::BookmarkNode* parent, | 121 const bookmarks::BookmarkNode* parent, |
119 bookmarks::BookmarkModel* model, | 122 bookmarks::BookmarkModel* model, |
120 syncer::SyncClient* sync_client, | 123 sync_driver::SyncClient* sync_client, |
121 int index); | 124 int index); |
122 | 125 |
123 // Sets the favicon of the given bookmark node from the given sync node. | 126 // Sets the favicon of the given bookmark node from the given sync node. |
124 // Returns whether the favicon was set in the bookmark node. | 127 // Returns whether the favicon was set in the bookmark node. |
125 // |profile| is the profile that contains the HistoryService and BookmarkModel | 128 // |profile| is the profile that contains the HistoryService and BookmarkModel |
126 // for the bookmark in question. | 129 // for the bookmark in question. |
127 static bool SetBookmarkFavicon(const syncer::BaseNode* sync_node, | 130 static bool SetBookmarkFavicon(const syncer::BaseNode* sync_node, |
128 const bookmarks::BookmarkNode* bookmark_node, | 131 const bookmarks::BookmarkNode* bookmark_node, |
129 bookmarks::BookmarkModel* model, | 132 bookmarks::BookmarkModel* model, |
130 syncer::SyncClient* sync_client); | 133 sync_driver::SyncClient* sync_client); |
131 | 134 |
132 // Applies the 1x favicon |bitmap_data| and |icon_url| to |bookmark_node|. | 135 // Applies the 1x favicon |bitmap_data| and |icon_url| to |bookmark_node|. |
133 // |profile| is the profile that contains the HistoryService and BookmarkModel | 136 // |profile| is the profile that contains the HistoryService and BookmarkModel |
134 // for the bookmark in question. | 137 // for the bookmark in question. |
135 static void ApplyBookmarkFavicon( | 138 static void ApplyBookmarkFavicon( |
136 const bookmarks::BookmarkNode* bookmark_node, | 139 const bookmarks::BookmarkNode* bookmark_node, |
137 syncer::SyncClient* sync_client, | 140 sync_driver::SyncClient* sync_client, |
138 const GURL& icon_url, | 141 const GURL& icon_url, |
139 const scoped_refptr<base::RefCountedMemory>& bitmap_data); | 142 const scoped_refptr<base::RefCountedMemory>& bitmap_data); |
140 | 143 |
141 // Sets the favicon of the given sync node from the given bookmark node. | 144 // Sets the favicon of the given sync node from the given bookmark node. |
142 static void SetSyncNodeFavicon(const bookmarks::BookmarkNode* bookmark_node, | 145 static void SetSyncNodeFavicon(const bookmarks::BookmarkNode* bookmark_node, |
143 bookmarks::BookmarkModel* model, | 146 bookmarks::BookmarkModel* model, |
144 syncer::WriteNode* sync_node); | 147 syncer::WriteNode* sync_node); |
145 | 148 |
146 // Treat the |index|th child of |parent| as a newly added node, and create a | 149 // Treat the |index|th child of |parent| as a newly added node, and create a |
147 // corresponding node in the sync domain using |trans|. All properties | 150 // corresponding node in the sync domain using |trans|. All properties |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 243 |
241 // Returns false if |node| should not be synced. | 244 // Returns false if |node| should not be synced. |
242 bool CanSyncNode(const bookmarks::BookmarkNode* node); | 245 bool CanSyncNode(const bookmarks::BookmarkNode* node); |
243 | 246 |
244 base::ThreadChecker thread_checker_; | 247 base::ThreadChecker thread_checker_; |
245 | 248 |
246 // The bookmark model we are processing changes from. Non-NULL when | 249 // The bookmark model we are processing changes from. Non-NULL when |
247 // |running_| is true. | 250 // |running_| is true. |
248 bookmarks::BookmarkModel* bookmark_model_; | 251 bookmarks::BookmarkModel* bookmark_model_; |
249 | 252 |
250 syncer::SyncClient* sync_client_; | 253 sync_driver::SyncClient* sync_client_; |
251 | 254 |
252 // The two models should be associated according to this ModelAssociator. | 255 // The two models should be associated according to this ModelAssociator. |
253 BookmarkModelAssociator* model_associator_; | 256 BookmarkModelAssociator* model_associator_; |
254 | 257 |
255 DISALLOW_COPY_AND_ASSIGN(BookmarkChangeProcessor); | 258 DISALLOW_COPY_AND_ASSIGN(BookmarkChangeProcessor); |
256 }; | 259 }; |
257 | 260 |
258 } // namespace sync_bookmarks | 261 } // namespace sync_bookmarks |
259 | 262 |
260 #endif // COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_CHANGE_PROCESSOR_H_ | 263 #endif // COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_CHANGE_PROCESSOR_H_ |
OLD | NEW |