OLD | NEW |
1 // Copyright (c) 2010 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_ |
11 #pragma once | 11 #pragma once |
(...skipping 27 matching lines...) Expand all Loading... |
39 // returned object. This is invoked to encode the contents of the bookmark bar | 39 // returned object. This is invoked to encode the contents of the bookmark bar |
40 // model and is currently a convenience to invoking Encode that takes the | 40 // model and is currently a convenience to invoking Encode that takes the |
41 // bookmark bar node and other folder node. | 41 // bookmark bar node and other folder node. |
42 Value* Encode(BookmarkModel* model); | 42 Value* Encode(BookmarkModel* model); |
43 | 43 |
44 // Encodes the bookmark bar and other folders returning the JSON value. It's | 44 // Encodes the bookmark bar and other folders returning the JSON value. It's |
45 // up to the caller to delete the returned object. | 45 // up to the caller to delete the returned object. |
46 // This method is public for use by StarredURLDatabase in migrating the | 46 // This method is public for use by StarredURLDatabase in migrating the |
47 // bookmarks out of the database. | 47 // bookmarks out of the database. |
48 Value* Encode(const BookmarkNode* bookmark_bar_node, | 48 Value* Encode(const BookmarkNode* bookmark_bar_node, |
49 const BookmarkNode* other_folder_node); | 49 const BookmarkNode* other_folder_node, |
| 50 const BookmarkNode* synced_folder_node); |
50 | 51 |
51 // Decodes the previously encoded value to the specified nodes as well as | 52 // Decodes the previously encoded value to the specified nodes as well as |
52 // setting |max_node_id| to the greatest node id. Returns true on success, | 53 // setting |max_node_id| to the greatest node id. Returns true on success, |
53 // false otherwise. If there is an error (such as unexpected version) all | 54 // false otherwise. If there is an error (such as unexpected version) all |
54 // children are removed from the bookmark bar and other folder nodes. On exit | 55 // children are removed from the bookmark bar and other folder nodes. On exit |
55 // |max_node_id| is set to the max id of the nodes. | 56 // |max_node_id| is set to the max id of the nodes. |
56 bool Decode(BookmarkNode* bb_node, | 57 bool Decode(BookmarkNode* bb_node, |
57 BookmarkNode* other_folder_node, | 58 BookmarkNode* other_folder_node, |
| 59 BookmarkNode* synced_folder_node, |
58 int64* max_node_id, | 60 int64* max_node_id, |
59 const Value& value); | 61 const Value& value); |
60 | 62 |
61 // Returns the checksum computed during last encoding/decoding call. | 63 // Returns the checksum computed during last encoding/decoding call. |
62 const std::string& computed_checksum() const { return computed_checksum_; } | 64 const std::string& computed_checksum() const { return computed_checksum_; } |
63 | 65 |
64 // Returns the checksum that's stored in the file. After a call to Encode, | 66 // Returns the checksum that's stored in the file. After a call to Encode, |
65 // the computed and stored checksums are the same since the computed checksum | 67 // the computed and stored checksums are the same since the computed checksum |
66 // is stored to the file. After a call to decode, the computed checksum can | 68 // is stored to the file. After a call to decode, the computed checksum can |
67 // differ from the stored checksum if the file contents were changed by the | 69 // differ from the stored checksum if the file contents were changed by the |
68 // user. | 70 // user. |
69 const std::string& stored_checksum() const { return stored_checksum_; } | 71 const std::string& stored_checksum() const { return stored_checksum_; } |
70 | 72 |
71 // Returns whether the IDs were reassigned during decoding. Always returns | 73 // Returns whether the IDs were reassigned during decoding. Always returns |
72 // false after encoding. | 74 // false after encoding. |
73 bool ids_reassigned() const { return ids_reassigned_; } | 75 bool ids_reassigned() const { return ids_reassigned_; } |
74 | 76 |
75 // Names of the various keys written to the Value. | 77 // Names of the various keys written to the Value. |
76 static const char* kRootsKey; | 78 static const char* kRootsKey; |
77 static const char* kRootFolderNameKey; | 79 static const char* kRootFolderNameKey; |
78 static const char* kOtherBookmarkFolderNameKey; | 80 static const char* kOtherBookmarkFolderNameKey; |
| 81 static const char* kSyncedBookmarkFolderNameKey; |
79 static const char* kVersionKey; | 82 static const char* kVersionKey; |
80 static const char* kChecksumKey; | 83 static const char* kChecksumKey; |
81 static const char* kIdKey; | 84 static const char* kIdKey; |
82 static const char* kTypeKey; | 85 static const char* kTypeKey; |
83 static const char* kNameKey; | 86 static const char* kNameKey; |
84 static const char* kDateAddedKey; | 87 static const char* kDateAddedKey; |
85 static const char* kURLKey; | 88 static const char* kURLKey; |
86 static const char* kDateModifiedKey; | 89 static const char* kDateModifiedKey; |
87 static const char* kChildrenKey; | 90 static const char* kChildrenKey; |
88 | 91 |
89 // Possible values for kTypeKey. | 92 // Possible values for kTypeKey. |
90 static const char* kTypeURL; | 93 static const char* kTypeURL; |
91 static const char* kTypeFolder; | 94 static const char* kTypeFolder; |
92 | 95 |
93 private: | 96 private: |
94 // Encodes node and all its children into a Value object and returns it. | 97 // Encodes node and all its children into a Value object and returns it. |
95 // The caller takes ownership of the returned object. | 98 // The caller takes ownership of the returned object. |
96 Value* EncodeNode(const BookmarkNode* node); | 99 Value* EncodeNode(const BookmarkNode* node); |
97 | 100 |
98 // Helper to perform decoding. | 101 // Helper to perform decoding. |
99 bool DecodeHelper(BookmarkNode* bb_node, | 102 bool DecodeHelper(BookmarkNode* bb_node, |
100 BookmarkNode* other_folder_node, | 103 BookmarkNode* other_folder_node, |
| 104 BookmarkNode* synced_folder_node, |
101 const Value& value); | 105 const Value& value); |
102 | 106 |
103 // Decodes the children of the specified node. Returns true on success. | 107 // Decodes the children of the specified node. Returns true on success. |
104 bool DecodeChildren(const ListValue& child_value_list, | 108 bool DecodeChildren(const ListValue& child_value_list, |
105 BookmarkNode* parent); | 109 BookmarkNode* parent); |
106 | 110 |
107 // Reassigns bookmark IDs for all nodes. | 111 // Reassigns bookmark IDs for all nodes. |
108 void ReassignIDs(BookmarkNode* bb_node, BookmarkNode* other_node); | 112 void ReassignIDs(BookmarkNode* bb_node, |
| 113 BookmarkNode* other_node, |
| 114 BookmarkNode* synced_node); |
109 | 115 |
110 // Helper to recursively reassign IDs. | 116 // Helper to recursively reassign IDs. |
111 void ReassignIDsHelper(BookmarkNode* node); | 117 void ReassignIDsHelper(BookmarkNode* node); |
112 | 118 |
113 // Decodes the supplied node from the supplied value. Child nodes are | 119 // Decodes the supplied node from the supplied value. Child nodes are |
114 // created appropriately by way of DecodeChildren. If node is NULL a new | 120 // created appropriately by way of DecodeChildren. If node is NULL a new |
115 // node is created and added to parent (parent must then be non-NULL), | 121 // node is created and added to parent (parent must then be non-NULL), |
116 // otherwise node is used. | 122 // otherwise node is used. |
117 bool DecodeNode(const DictionaryValue& value, | 123 bool DecodeNode(const DictionaryValue& value, |
118 BookmarkNode* parent, | 124 BookmarkNode* parent, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 std::string computed_checksum_; | 162 std::string computed_checksum_; |
157 std::string stored_checksum_; | 163 std::string stored_checksum_; |
158 | 164 |
159 // Maximum ID assigned when decoding data. | 165 // Maximum ID assigned when decoding data. |
160 int64 maximum_id_; | 166 int64 maximum_id_; |
161 | 167 |
162 DISALLOW_COPY_AND_ASSIGN(BookmarkCodec); | 168 DISALLOW_COPY_AND_ASSIGN(BookmarkCodec); |
163 }; | 169 }; |
164 | 170 |
165 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_CODEC_H_ | 171 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_CODEC_H_ |
OLD | NEW |