| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_BOOKMARKS_BROWSER_BOOKMARK_CODEC_H_ | 5 #ifndef COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CODEC_H_ |
| 6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CODEC_H_ | 6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CODEC_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 // are not unique, we will reassign IDs to make them unique. There are no | 35 // are not unique, we will reassign IDs to make them unique. There are no |
| 36 // guarantees on how the IDs are reassigned or about doing minimal | 36 // guarantees on how the IDs are reassigned or about doing minimal |
| 37 // reassignments to achieve uniqueness. | 37 // reassignments to achieve uniqueness. |
| 38 BookmarkCodec(); | 38 BookmarkCodec(); |
| 39 ~BookmarkCodec(); | 39 ~BookmarkCodec(); |
| 40 | 40 |
| 41 // Encodes the model to a JSON value. It's up to the caller to delete the | 41 // Encodes the model to a JSON value. It's up to the caller to delete the |
| 42 // returned object. This is invoked to encode the contents of the bookmark bar | 42 // returned object. This is invoked to encode the contents of the bookmark bar |
| 43 // model and is currently a convenience to invoking Encode that takes the | 43 // model and is currently a convenience to invoking Encode that takes the |
| 44 // bookmark bar node and other folder node. | 44 // bookmark bar node and other folder node. |
| 45 base::Value* Encode(BookmarkModel* model); | 45 std::unique_ptr<base::Value> Encode(BookmarkModel* model); |
| 46 | 46 |
| 47 // Encodes the bookmark bar and other folders returning the JSON value. It's | 47 // Encodes the bookmark bar and other folders returning the JSON value. |
| 48 // up to the caller to delete the returned object. | 48 std::unique_ptr<base::Value> Encode( |
| 49 base::Value* Encode(const BookmarkNode* bookmark_bar_node, | 49 const BookmarkNode* bookmark_bar_node, |
| 50 const BookmarkNode* other_folder_node, | 50 const BookmarkNode* other_folder_node, |
| 51 const BookmarkNode* mobile_folder_node, | 51 const BookmarkNode* mobile_folder_node, |
| 52 const BookmarkNode::MetaInfoMap* model_meta_info_map, | 52 const BookmarkNode::MetaInfoMap* model_meta_info_map, |
| 53 int64_t sync_transaction_version); | 53 int64_t sync_transaction_version); |
| 54 | 54 |
| 55 // Decodes the previously encoded value to the specified nodes as well as | 55 // Decodes the previously encoded value to the specified nodes as well as |
| 56 // setting |max_node_id| to the greatest node id. Returns true on success, | 56 // setting |max_node_id| to the greatest node id. Returns true on success, |
| 57 // false otherwise. If there is an error (such as unexpected version) all | 57 // false otherwise. If there is an error (such as unexpected version) all |
| 58 // children are removed from the bookmark bar and other folder nodes. On exit | 58 // children are removed from the bookmark bar and other folder nodes. On exit |
| 59 // |max_node_id| is set to the max id of the nodes. | 59 // |max_node_id| is set to the max id of the nodes. |
| 60 bool Decode(BookmarkNode* bb_node, | 60 bool Decode(BookmarkNode* bb_node, |
| 61 BookmarkNode* other_folder_node, | 61 BookmarkNode* other_folder_node, |
| 62 BookmarkNode* mobile_folder_node, | 62 BookmarkNode* mobile_folder_node, |
| 63 int64_t* max_node_id, | 63 int64_t* max_node_id, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 static const char kSyncTransactionVersion[]; | 105 static const char kSyncTransactionVersion[]; |
| 106 | 106 |
| 107 // Possible values for kTypeKey. | 107 // Possible values for kTypeKey. |
| 108 static const char kTypeURL[]; | 108 static const char kTypeURL[]; |
| 109 static const char kTypeFolder[]; | 109 static const char kTypeFolder[]; |
| 110 | 110 |
| 111 private: | 111 private: |
| 112 // Encodes node and all its children into a Value object and returns it. | 112 // Encodes node and all its children into a Value object and returns it. |
| 113 std::unique_ptr<base::Value> EncodeNode(const BookmarkNode* node); | 113 std::unique_ptr<base::Value> EncodeNode(const BookmarkNode* node); |
| 114 | 114 |
| 115 // Encodes the given meta info into a Value object and returns it. The caller | 115 // Encodes the given meta info into a Value object and returns it. |
| 116 // takes ownership of the returned object. | 116 std::unique_ptr<base::Value> EncodeMetaInfo( |
| 117 base::Value* EncodeMetaInfo(const BookmarkNode::MetaInfoMap& meta_info_map); | 117 const BookmarkNode::MetaInfoMap& meta_info_map); |
| 118 | 118 |
| 119 // Helper to perform decoding. | 119 // Helper to perform decoding. |
| 120 bool DecodeHelper(BookmarkNode* bb_node, | 120 bool DecodeHelper(BookmarkNode* bb_node, |
| 121 BookmarkNode* other_folder_node, | 121 BookmarkNode* other_folder_node, |
| 122 BookmarkNode* mobile_folder_node, | 122 BookmarkNode* mobile_folder_node, |
| 123 const base::Value& value); | 123 const base::Value& value); |
| 124 | 124 |
| 125 // Decodes the children of the specified node. Returns true on success. | 125 // Decodes the children of the specified node. Returns true on success. |
| 126 bool DecodeChildren(const base::ListValue& child_value_list, | 126 bool DecodeChildren(const base::ListValue& child_value_list, |
| 127 BookmarkNode* parent); | 127 BookmarkNode* parent); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 204 |
| 205 // Sync transaction version set on bookmark model root. | 205 // Sync transaction version set on bookmark model root. |
| 206 int64_t model_sync_transaction_version_; | 206 int64_t model_sync_transaction_version_; |
| 207 | 207 |
| 208 DISALLOW_COPY_AND_ASSIGN(BookmarkCodec); | 208 DISALLOW_COPY_AND_ASSIGN(BookmarkCodec); |
| 209 }; | 209 }; |
| 210 | 210 |
| 211 } // namespace bookmarks | 211 } // namespace bookmarks |
| 212 | 212 |
| 213 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CODEC_H_ | 213 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CODEC_H_ |
| OLD | NEW |