| 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 CHROME_BROWSER_SYNC_GLUE_BOOKMARK_CHANGE_PROCESSOR_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_BOOKMARK_CHANGE_PROCESSOR_H_ |
| 6 #define CHROME_BROWSER_SYNC_GLUE_BOOKMARK_CHANGE_PROCESSOR_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_BOOKMARK_CHANGE_PROCESSOR_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 BookmarkModelAssociator* model_associator, | 39 BookmarkModelAssociator* model_associator, |
| 40 sync_driver::DataTypeErrorHandler* error_handler); | 40 sync_driver::DataTypeErrorHandler* error_handler); |
| 41 ~BookmarkChangeProcessor() override; | 41 ~BookmarkChangeProcessor() override; |
| 42 | 42 |
| 43 // bookmarks::BookmarkModelObserver: | 43 // bookmarks::BookmarkModelObserver: |
| 44 // BookmarkModel -> sync API model change application. | 44 // BookmarkModel -> sync API model change application. |
| 45 void BookmarkModelLoaded(bookmarks::BookmarkModel* model, | 45 void BookmarkModelLoaded(bookmarks::BookmarkModel* model, |
| 46 bool ids_reassigned) override; | 46 bool ids_reassigned) override; |
| 47 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override; | 47 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override; |
| 48 void BookmarkNodeMoved(bookmarks::BookmarkModel* model, | 48 void BookmarkNodeMoved(bookmarks::BookmarkModel* model, |
| 49 const BookmarkNode* old_parent, | 49 const bookmarks::BookmarkNode* old_parent, |
| 50 int old_index, | 50 int old_index, |
| 51 const BookmarkNode* new_parent, | 51 const bookmarks::BookmarkNode* new_parent, |
| 52 int new_index) override; | 52 int new_index) override; |
| 53 void BookmarkNodeAdded(bookmarks::BookmarkModel* model, | 53 void BookmarkNodeAdded(bookmarks::BookmarkModel* model, |
| 54 const BookmarkNode* parent, | 54 const bookmarks::BookmarkNode* parent, |
| 55 int index) override; | 55 int index) override; |
| 56 void BookmarkNodeRemoved(bookmarks::BookmarkModel* model, | 56 void BookmarkNodeRemoved(bookmarks::BookmarkModel* model, |
| 57 const BookmarkNode* parent, | 57 const bookmarks::BookmarkNode* parent, |
| 58 int index, | 58 int index, |
| 59 const BookmarkNode* node, | 59 const bookmarks::BookmarkNode* node, |
| 60 const std::set<GURL>& removed_urls) override; | 60 const std::set<GURL>& removed_urls) override; |
| 61 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel* model, | 61 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel* model, |
| 62 const std::set<GURL>& removed_urls) override; | 62 const std::set<GURL>& removed_urls) override; |
| 63 void BookmarkNodeChanged(bookmarks::BookmarkModel* model, | 63 void BookmarkNodeChanged(bookmarks::BookmarkModel* model, |
| 64 const BookmarkNode* node) override; | 64 const bookmarks::BookmarkNode* node) override; |
| 65 void BookmarkMetaInfoChanged(bookmarks::BookmarkModel* model, | 65 void BookmarkMetaInfoChanged(bookmarks::BookmarkModel* model, |
| 66 const BookmarkNode* node) override; | 66 const bookmarks::BookmarkNode* node) override; |
| 67 void BookmarkNodeFaviconChanged(bookmarks::BookmarkModel* model, | 67 void BookmarkNodeFaviconChanged(bookmarks::BookmarkModel* model, |
| 68 const BookmarkNode* node) override; | 68 const bookmarks::BookmarkNode* node) override; |
| 69 void BookmarkNodeChildrenReordered(bookmarks::BookmarkModel* model, | 69 void BookmarkNodeChildrenReordered( |
| 70 const BookmarkNode* node) override; | 70 bookmarks::BookmarkModel* model, |
| 71 const bookmarks::BookmarkNode* node) override; |
| 71 | 72 |
| 72 // The change processor implementation, responsible for applying changes from | 73 // The change processor implementation, responsible for applying changes from |
| 73 // the sync model to the bookmarks model. | 74 // the sync model to the bookmarks model. |
| 74 void ApplyChangesFromSyncModel( | 75 void ApplyChangesFromSyncModel( |
| 75 const syncer::BaseTransaction* trans, | 76 const syncer::BaseTransaction* trans, |
| 76 int64 model_version, | 77 int64 model_version, |
| 77 const syncer::ImmutableChangeRecordList& changes) override; | 78 const syncer::ImmutableChangeRecordList& changes) override; |
| 78 | 79 |
| 79 // The following methods are static and hence may be invoked at any time, and | 80 // The following methods are static and hence may be invoked at any time, and |
| 80 // do not depend on having a running ChangeProcessor. | 81 // do not depend on having a running ChangeProcessor. |
| 81 | 82 |
| 82 // Updates the title, URL, creation time and favicon of the bookmark |node| | 83 // Updates the title, URL, creation time and favicon of the bookmark |node| |
| 83 // with data taken from the |sync_node| sync node. | 84 // with data taken from the |sync_node| sync node. |
| 84 static void UpdateBookmarkWithSyncData(const syncer::BaseNode& sync_node, | 85 static void UpdateBookmarkWithSyncData(const syncer::BaseNode& sync_node, |
| 85 bookmarks::BookmarkModel* model, | 86 bookmarks::BookmarkModel* model, |
| 86 const BookmarkNode* node, | 87 const bookmarks::BookmarkNode* node, |
| 87 Profile* profile); | 88 Profile* profile); |
| 88 | 89 |
| 89 // Creates a bookmark node under the given parent node from the given sync | 90 // Creates a bookmark node under the given parent node from the given sync |
| 90 // node. Returns the newly created node. The created node is placed at the | 91 // node. Returns the newly created node. The created node is placed at the |
| 91 // specified index among the parent's children. | 92 // specified index among the parent's children. |
| 92 static const BookmarkNode* CreateBookmarkNode(syncer::BaseNode* sync_node, | 93 static const bookmarks::BookmarkNode* CreateBookmarkNode( |
| 93 const BookmarkNode* parent, | 94 syncer::BaseNode* sync_node, |
| 94 bookmarks::BookmarkModel* model, | 95 const bookmarks::BookmarkNode* parent, |
| 95 Profile* profile, | 96 bookmarks::BookmarkModel* model, |
| 96 int index); | 97 Profile* profile, |
| 98 int index); |
| 97 | 99 |
| 98 // Sets the favicon of the given bookmark node from the given sync node. | 100 // Sets the favicon of the given bookmark node from the given sync node. |
| 99 // Returns whether the favicon was set in the bookmark node. | 101 // Returns whether the favicon was set in the bookmark node. |
| 100 // |profile| is the profile that contains the HistoryService and BookmarkModel | 102 // |profile| is the profile that contains the HistoryService and BookmarkModel |
| 101 // for the bookmark in question. | 103 // for the bookmark in question. |
| 102 static bool SetBookmarkFavicon(const syncer::BaseNode* sync_node, | 104 static bool SetBookmarkFavicon(const syncer::BaseNode* sync_node, |
| 103 const BookmarkNode* bookmark_node, | 105 const bookmarks::BookmarkNode* bookmark_node, |
| 104 bookmarks::BookmarkModel* model, | 106 bookmarks::BookmarkModel* model, |
| 105 Profile* profile); | 107 Profile* profile); |
| 106 | 108 |
| 107 // Applies the 1x favicon |bitmap_data| and |icon_url| to |bookmark_node|. | 109 // Applies the 1x favicon |bitmap_data| and |icon_url| to |bookmark_node|. |
| 108 // |profile| is the profile that contains the HistoryService and BookmarkModel | 110 // |profile| is the profile that contains the HistoryService and BookmarkModel |
| 109 // for the bookmark in question. | 111 // for the bookmark in question. |
| 110 static void ApplyBookmarkFavicon( | 112 static void ApplyBookmarkFavicon( |
| 111 const BookmarkNode* bookmark_node, | 113 const bookmarks::BookmarkNode* bookmark_node, |
| 112 Profile* profile, | 114 Profile* profile, |
| 113 const GURL& icon_url, | 115 const GURL& icon_url, |
| 114 const scoped_refptr<base::RefCountedMemory>& bitmap_data); | 116 const scoped_refptr<base::RefCountedMemory>& bitmap_data); |
| 115 | 117 |
| 116 // Sets the favicon of the given sync node from the given bookmark node. | 118 // Sets the favicon of the given sync node from the given bookmark node. |
| 117 static void SetSyncNodeFavicon(const BookmarkNode* bookmark_node, | 119 static void SetSyncNodeFavicon(const bookmarks::BookmarkNode* bookmark_node, |
| 118 bookmarks::BookmarkModel* model, | 120 bookmarks::BookmarkModel* model, |
| 119 syncer::WriteNode* sync_node); | 121 syncer::WriteNode* sync_node); |
| 120 | 122 |
| 121 // Treat the |index|th child of |parent| as a newly added node, and create a | 123 // Treat the |index|th child of |parent| as a newly added node, and create a |
| 122 // corresponding node in the sync domain using |trans|. All properties | 124 // corresponding node in the sync domain using |trans|. All properties |
| 123 // will be transferred to the new node. A node corresponding to |parent| | 125 // will be transferred to the new node. A node corresponding to |parent| |
| 124 // must already exist and be associated for this call to succeed. Returns | 126 // must already exist and be associated for this call to succeed. Returns |
| 125 // the ID of the just-created node, or if creation fails, kInvalidID. | 127 // the ID of the just-created node, or if creation fails, kInvalidID. |
| 126 static int64 CreateSyncNode(const BookmarkNode* parent, | 128 static int64 CreateSyncNode(const bookmarks::BookmarkNode* parent, |
| 127 bookmarks::BookmarkModel* model, | 129 bookmarks::BookmarkModel* model, |
| 128 int index, | 130 int index, |
| 129 syncer::WriteTransaction* trans, | 131 syncer::WriteTransaction* trans, |
| 130 BookmarkModelAssociator* associator, | 132 BookmarkModelAssociator* associator, |
| 131 sync_driver::DataTypeErrorHandler* error_handler); | 133 sync_driver::DataTypeErrorHandler* error_handler); |
| 132 | 134 |
| 133 // Update |bookmark_node|'s sync node. | 135 // Update |bookmark_node|'s sync node. |
| 134 static int64 UpdateSyncNode(const BookmarkNode* bookmark_node, | 136 static int64 UpdateSyncNode(const bookmarks::BookmarkNode* bookmark_node, |
| 135 bookmarks::BookmarkModel* model, | 137 bookmarks::BookmarkModel* model, |
| 136 syncer::WriteTransaction* trans, | 138 syncer::WriteTransaction* trans, |
| 137 BookmarkModelAssociator* associator, | 139 BookmarkModelAssociator* associator, |
| 138 sync_driver::DataTypeErrorHandler* error_handler); | 140 sync_driver::DataTypeErrorHandler* error_handler); |
| 139 | 141 |
| 140 // Update transaction version of |model| and |nodes| to |new_version| if | 142 // Update transaction version of |model| and |nodes| to |new_version| if |
| 141 // it's valid. | 143 // it's valid. |
| 142 static void UpdateTransactionVersion( | 144 static void UpdateTransactionVersion( |
| 143 int64 new_version, | 145 int64 new_version, |
| 144 bookmarks::BookmarkModel* model, | 146 bookmarks::BookmarkModel* model, |
| 145 const std::vector<const BookmarkNode*>& nodes); | 147 const std::vector<const bookmarks::BookmarkNode*>& nodes); |
| 146 | 148 |
| 147 protected: | 149 protected: |
| 148 void StartImpl() override; | 150 void StartImpl() override; |
| 149 | 151 |
| 150 private: | 152 private: |
| 151 enum MoveOrCreate { | 153 enum MoveOrCreate { |
| 152 MOVE, | 154 MOVE, |
| 153 CREATE, | 155 CREATE, |
| 154 }; | 156 }; |
| 155 | 157 |
| 156 // Retrieves the meta info from the given sync node. | 158 // Retrieves the meta info from the given sync node. |
| 157 static scoped_ptr<BookmarkNode::MetaInfoMap> GetBookmarkMetaInfo( | 159 static scoped_ptr<bookmarks::BookmarkNode::MetaInfoMap> GetBookmarkMetaInfo( |
| 158 const syncer::BaseNode* sync_node); | 160 const syncer::BaseNode* sync_node); |
| 159 | 161 |
| 160 // Sets the meta info of the given sync node from the given bookmark node. | 162 // Sets the meta info of the given sync node from the given bookmark node. |
| 161 static void SetSyncNodeMetaInfo(const BookmarkNode* node, | 163 static void SetSyncNodeMetaInfo(const bookmarks::BookmarkNode* node, |
| 162 syncer::WriteNode* sync_node); | 164 syncer::WriteNode* sync_node); |
| 163 | 165 |
| 164 // Helper function used to fix the position of a sync node so that it matches | 166 // Helper function used to fix the position of a sync node so that it matches |
| 165 // the position of a corresponding bookmark model node. |parent| and | 167 // the position of a corresponding bookmark model node. |parent| and |
| 166 // |index| identify the bookmark model position. |dst| is the node whose | 168 // |index| identify the bookmark model position. |dst| is the node whose |
| 167 // position is to be fixed. If |operation| is CREATE, treat |dst| as an | 169 // position is to be fixed. If |operation| is CREATE, treat |dst| as an |
| 168 // uncreated node and set its position via InitByCreation(); otherwise, | 170 // uncreated node and set its position via InitByCreation(); otherwise, |
| 169 // |dst| is treated as an existing node, and its position will be set via | 171 // |dst| is treated as an existing node, and its position will be set via |
| 170 // SetPosition(). |trans| is the transaction to which |dst| belongs. Returns | 172 // SetPosition(). |trans| is the transaction to which |dst| belongs. Returns |
| 171 // false on failure. | 173 // false on failure. |
| 172 static bool PlaceSyncNode(MoveOrCreate operation, | 174 static bool PlaceSyncNode(MoveOrCreate operation, |
| 173 const BookmarkNode* parent, | 175 const bookmarks::BookmarkNode* parent, |
| 174 int index, | 176 int index, |
| 175 syncer::WriteTransaction* trans, | 177 syncer::WriteTransaction* trans, |
| 176 syncer::WriteNode* dst, | 178 syncer::WriteNode* dst, |
| 177 BookmarkModelAssociator* associator); | 179 BookmarkModelAssociator* associator); |
| 178 | 180 |
| 179 // Copy properties (but not position) from |src| to |dst|. | 181 // Copy properties (but not position) from |src| to |dst|. |
| 180 static void UpdateSyncNodeProperties(const BookmarkNode* src, | 182 static void UpdateSyncNodeProperties(const bookmarks::BookmarkNode* src, |
| 181 bookmarks::BookmarkModel* model, | 183 bookmarks::BookmarkModel* model, |
| 182 syncer::WriteNode* dst); | 184 syncer::WriteNode* dst); |
| 183 | 185 |
| 184 // Helper function to encode a bookmark's favicon into raw PNG data. | 186 // Helper function to encode a bookmark's favicon into raw PNG data. |
| 185 static void EncodeFavicon(const BookmarkNode* src, | 187 static void EncodeFavicon(const bookmarks::BookmarkNode* src, |
| 186 bookmarks::BookmarkModel* model, | 188 bookmarks::BookmarkModel* model, |
| 187 scoped_refptr<base::RefCountedMemory>* dst); | 189 scoped_refptr<base::RefCountedMemory>* dst); |
| 188 | 190 |
| 189 // Remove |sync_node|. It should not have any children | 191 // Remove |sync_node|. It should not have any children |
| 190 void RemoveOneSyncNode(syncer::WriteNode* sync_node); | 192 void RemoveOneSyncNode(syncer::WriteNode* sync_node); |
| 191 | 193 |
| 192 // Remove all sync nodes, except the permanent nodes. | 194 // Remove all sync nodes, except the permanent nodes. |
| 193 void RemoveAllSyncNodes(); | 195 void RemoveAllSyncNodes(); |
| 194 | 196 |
| 195 // Remove all children of the bookmark node with bookmark node id: | 197 // Remove all children of the bookmark node with bookmark node id: |
| 196 // |topmost_node_id|. | 198 // |topmost_node_id|. |
| 197 void RemoveAllChildNodes(syncer::WriteTransaction* trans, | 199 void RemoveAllChildNodes(syncer::WriteTransaction* trans, |
| 198 const int64& topmost_node_id); | 200 const int64& topmost_node_id); |
| 199 | 201 |
| 200 // Remove all the sync nodes associated with |node| and its children. | 202 // Remove all the sync nodes associated with |node| and its children. |
| 201 void RemoveSyncNodeHierarchy(const BookmarkNode* node); | 203 void RemoveSyncNodeHierarchy(const bookmarks::BookmarkNode* node); |
| 202 | 204 |
| 203 // Creates or updates a sync node associated with |node|. | 205 // Creates or updates a sync node associated with |node|. |
| 204 void CreateOrUpdateSyncNode(const BookmarkNode* node); | 206 void CreateOrUpdateSyncNode(const bookmarks::BookmarkNode* node); |
| 205 | 207 |
| 206 // Returns false if |node| should not be synced. | 208 // Returns false if |node| should not be synced. |
| 207 bool CanSyncNode(const BookmarkNode* node); | 209 bool CanSyncNode(const bookmarks::BookmarkNode* node); |
| 208 | 210 |
| 209 // The bookmark model we are processing changes from. Non-NULL when | 211 // The bookmark model we are processing changes from. Non-NULL when |
| 210 // |running_| is true. | 212 // |running_| is true. |
| 211 bookmarks::BookmarkModel* bookmark_model_; | 213 bookmarks::BookmarkModel* bookmark_model_; |
| 212 | 214 |
| 213 Profile* profile_; | 215 Profile* profile_; |
| 214 | 216 |
| 215 // The two models should be associated according to this ModelAssociator. | 217 // The two models should be associated according to this ModelAssociator. |
| 216 BookmarkModelAssociator* model_associator_; | 218 BookmarkModelAssociator* model_associator_; |
| 217 | 219 |
| 218 DISALLOW_COPY_AND_ASSIGN(BookmarkChangeProcessor); | 220 DISALLOW_COPY_AND_ASSIGN(BookmarkChangeProcessor); |
| 219 }; | 221 }; |
| 220 | 222 |
| 221 } // namespace browser_sync | 223 } // namespace browser_sync |
| 222 | 224 |
| 223 #endif // CHROME_BROWSER_SYNC_GLUE_BOOKMARK_CHANGE_PROCESSOR_H_ | 225 #endif // CHROME_BROWSER_SYNC_GLUE_BOOKMARK_CHANGE_PROCESSOR_H_ |
| OLD | NEW |