OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // BookmarkCodec is responsible for encoding and decoding the BookmarkModel | 5 // BookmarkCodec is responsible for encoding and decoding the BookmarkModel |
6 // into JSON values. The encoded values are written to disk via the | 6 // into JSON values. The encoded values are written to disk via the |
7 // BookmarkService. | 7 // BookmarkService. |
8 | 8 |
9 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_CODEC_H_ | 9 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_CODEC_H_ |
10 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_CODEC_H_ | 10 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_CODEC_H_ |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 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. It's |
48 // up to the caller to delete the returned object. | 48 // up to the caller to delete the returned object. |
49 // This method is public for use by StarredURLDatabase in migrating the | 49 // This method is public for use by StarredURLDatabase in migrating the |
50 // bookmarks out of the database. | 50 // bookmarks out of the database. |
51 base::Value* Encode(const BookmarkNode* bookmark_bar_node, | 51 base::Value* Encode(const BookmarkNode* bookmark_bar_node, |
52 const BookmarkNode* other_folder_node, | 52 const BookmarkNode* other_folder_node, |
53 const BookmarkNode* synced_folder_node); | 53 const BookmarkNode* mobile_folder_node); |
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* synced_folder_node, | 62 BookmarkNode* mobile_folder_node, |
63 int64* max_node_id, | 63 int64* max_node_id, |
64 const base::Value& value); | 64 const base::Value& value); |
65 | 65 |
66 // Returns the checksum computed during last encoding/decoding call. | 66 // Returns the checksum computed during last encoding/decoding call. |
67 const std::string& computed_checksum() const { return computed_checksum_; } | 67 const std::string& computed_checksum() const { return computed_checksum_; } |
68 | 68 |
69 // Returns the checksum that's stored in the file. After a call to Encode, | 69 // Returns the checksum that's stored in the file. After a call to Encode, |
70 // the computed and stored checksums are the same since the computed checksum | 70 // the computed and stored checksums are the same since the computed checksum |
71 // is stored to the file. After a call to decode, the computed checksum can | 71 // is stored to the file. After a call to decode, the computed checksum can |
72 // differ from the stored checksum if the file contents were changed by the | 72 // differ from the stored checksum if the file contents were changed by the |
73 // user. | 73 // user. |
74 const std::string& stored_checksum() const { return stored_checksum_; } | 74 const std::string& stored_checksum() const { return stored_checksum_; } |
75 | 75 |
76 // Returns whether the IDs were reassigned during decoding. Always returns | 76 // Returns whether the IDs were reassigned during decoding. Always returns |
77 // false after encoding. | 77 // false after encoding. |
78 bool ids_reassigned() const { return ids_reassigned_; } | 78 bool ids_reassigned() const { return ids_reassigned_; } |
79 | 79 |
80 // Names of the various keys written to the Value. | 80 // Names of the various keys written to the Value. |
81 static const char* kRootsKey; | 81 static const char* kRootsKey; |
82 static const char* kRootFolderNameKey; | 82 static const char* kRootFolderNameKey; |
83 static const char* kOtherBookmarkFolderNameKey; | 83 static const char* kOtherBookmarkFolderNameKey; |
84 static const char* kSyncedBookmarkFolderNameKey; | 84 static const char* kMobileBookmarkFolderNameKey; |
85 static const char* kVersionKey; | 85 static const char* kVersionKey; |
86 static const char* kChecksumKey; | 86 static const char* kChecksumKey; |
87 static const char* kIdKey; | 87 static const char* kIdKey; |
88 static const char* kTypeKey; | 88 static const char* kTypeKey; |
89 static const char* kNameKey; | 89 static const char* kNameKey; |
90 static const char* kDateAddedKey; | 90 static const char* kDateAddedKey; |
91 static const char* kURLKey; | 91 static const char* kURLKey; |
92 static const char* kDateModifiedKey; | 92 static const char* kDateModifiedKey; |
93 static const char* kChildrenKey; | 93 static const char* kChildrenKey; |
94 | 94 |
95 // Possible values for kTypeKey. | 95 // Possible values for kTypeKey. |
96 static const char* kTypeURL; | 96 static const char* kTypeURL; |
97 static const char* kTypeFolder; | 97 static const char* kTypeFolder; |
98 | 98 |
99 private: | 99 private: |
100 // Encodes node and all its children into a Value object and returns it. | 100 // Encodes node and all its children into a Value object and returns it. |
101 // The caller takes ownership of the returned object. | 101 // The caller takes ownership of the returned object. |
102 base::Value* EncodeNode(const BookmarkNode* node); | 102 base::Value* EncodeNode(const BookmarkNode* node); |
103 | 103 |
104 // Helper to perform decoding. | 104 // Helper to perform decoding. |
105 bool DecodeHelper(BookmarkNode* bb_node, | 105 bool DecodeHelper(BookmarkNode* bb_node, |
106 BookmarkNode* other_folder_node, | 106 BookmarkNode* other_folder_node, |
107 BookmarkNode* synced_folder_node, | 107 BookmarkNode* mobile_folder_node, |
108 const base::Value& value); | 108 const base::Value& value); |
109 | 109 |
110 // Decodes the children of the specified node. Returns true on success. | 110 // Decodes the children of the specified node. Returns true on success. |
111 bool DecodeChildren(const base::ListValue& child_value_list, | 111 bool DecodeChildren(const base::ListValue& child_value_list, |
112 BookmarkNode* parent); | 112 BookmarkNode* parent); |
113 | 113 |
114 // Reassigns bookmark IDs for all nodes. | 114 // Reassigns bookmark IDs for all nodes. |
115 void ReassignIDs(BookmarkNode* bb_node, | 115 void ReassignIDs(BookmarkNode* bb_node, |
116 BookmarkNode* other_node, | 116 BookmarkNode* other_node, |
117 BookmarkNode* synced_node); | 117 BookmarkNode* mobile_node); |
118 | 118 |
119 // Helper to recursively reassign IDs. | 119 // Helper to recursively reassign IDs. |
120 void ReassignIDsHelper(BookmarkNode* node); | 120 void ReassignIDsHelper(BookmarkNode* node); |
121 | 121 |
122 // Decodes the supplied node from the supplied value. Child nodes are | 122 // Decodes the supplied node from the supplied value. Child nodes are |
123 // created appropriately by way of DecodeChildren. If node is NULL a new | 123 // created appropriately by way of DecodeChildren. If node is NULL a new |
124 // node is created and added to parent (parent must then be non-NULL), | 124 // node is created and added to parent (parent must then be non-NULL), |
125 // otherwise node is used. | 125 // otherwise node is used. |
126 bool DecodeNode(const base::DictionaryValue& value, | 126 bool DecodeNode(const base::DictionaryValue& value, |
127 BookmarkNode* parent, | 127 BookmarkNode* parent, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 std::string computed_checksum_; | 165 std::string computed_checksum_; |
166 std::string stored_checksum_; | 166 std::string stored_checksum_; |
167 | 167 |
168 // Maximum ID assigned when decoding data. | 168 // Maximum ID assigned when decoding data. |
169 int64 maximum_id_; | 169 int64 maximum_id_; |
170 | 170 |
171 DISALLOW_COPY_AND_ASSIGN(BookmarkCodec); | 171 DISALLOW_COPY_AND_ASSIGN(BookmarkCodec); |
172 }; | 172 }; |
173 | 173 |
174 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_CODEC_H_ | 174 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_CODEC_H_ |
OLD | NEW |