OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 BookmarkBarModel | 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 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 | 13 |
14 class BookmarkBarModel; | 14 class BookmarkModel; |
15 class BookmarkBarNode; | 15 class BookmarkNode; |
16 class DictionaryValue; | 16 class DictionaryValue; |
17 class ListValue; | 17 class ListValue; |
18 class Value; | 18 class Value; |
19 | 19 |
20 // BookmarkCodec is responsible for encoding/decoding bookmarks into JSON | 20 // BookmarkCodec is responsible for encoding/decoding bookmarks into JSON |
21 // values. BookmarkCodec is used by BookmarkService. | 21 // values. BookmarkCodec is used by BookmarkService. |
22 | 22 |
23 class BookmarkCodec { | 23 class BookmarkCodec { |
24 public: | 24 public: |
25 BookmarkCodec() {} | 25 BookmarkCodec() {} |
26 | 26 |
27 // Encodes the model to a JSON value. It's up to the caller to delete the | 27 // Encodes the model to a JSON value. It's up to the caller to delete the |
28 // returned object. This is invoked to encode the contents of the bookmark bar | 28 // returned object. This is invoked to encode the contents of the bookmark bar |
29 // model and is currently a convenience to invoking Encode that takes the | 29 // model and is currently a convenience to invoking Encode that takes the |
30 // bookmark bar node and other folder node. | 30 // bookmark bar node and other folder node. |
31 Value* Encode(BookmarkBarModel* model); | 31 Value* Encode(BookmarkModel* model); |
32 | 32 |
33 // Encodes the bookmark bar and other folders returning the JSON value. It's | 33 // Encodes the bookmark bar and other folders returning the JSON value. It's |
34 // up to the caller to delete the returned object. | 34 // up to the caller to delete the returned object. |
35 // This method is public for use by StarredURLDatabase in migrating the | 35 // This method is public for use by StarredURLDatabase in migrating the |
36 // bookmarks out of the database. | 36 // bookmarks out of the database. |
37 Value* Encode(BookmarkBarNode* bookmark_bar_node, | 37 Value* Encode(BookmarkNode* bookmark_bar_node, |
38 BookmarkBarNode* other_folder_node); | 38 BookmarkNode* other_folder_node); |
39 | 39 |
40 // Decodes the previously encoded value to the specified model. Returns true | 40 // Decodes the previously encoded value to the specified model. Returns true |
41 // on success, false otherwise. If there is an error (such as unexpected | 41 // on success, false otherwise. If there is an error (such as unexpected |
42 // version) all children are removed from the bookmark bar and other folder | 42 // version) all children are removed from the bookmark bar and other folder |
43 // nodes. | 43 // nodes. |
44 bool Decode(BookmarkBarModel* model, const Value& value); | 44 bool Decode(BookmarkModel* model, const Value& value); |
45 | 45 |
46 private: | 46 private: |
47 // Encodes node and all its children into a Value object and returns it. | 47 // Encodes node and all its children into a Value object and returns it. |
48 // The caller takes ownership of the returned object. | 48 // The caller takes ownership of the returned object. |
49 Value* EncodeNode(BookmarkBarNode* node); | 49 Value* EncodeNode(BookmarkNode* node); |
50 | 50 |
51 // Decodes the children of the specified node. Returns true on success. | 51 // Decodes the children of the specified node. Returns true on success. |
52 bool DecodeChildren(BookmarkBarModel* model, | 52 bool DecodeChildren(BookmarkModel* model, |
53 const ListValue& child_value_list, | 53 const ListValue& child_value_list, |
54 BookmarkBarNode* parent); | 54 BookmarkNode* parent); |
55 | 55 |
56 // Decodes the supplied node from the supplied value. Child nodes are | 56 // Decodes the supplied node from the supplied value. Child nodes are |
57 // created appropriately by way of DecodeChildren. If node is NULL a new | 57 // created appropriately by way of DecodeChildren. If node is NULL a new |
58 // node is created and added to parent, otherwise node is used. | 58 // node is created and added to parent, otherwise node is used. |
59 bool DecodeNode(BookmarkBarModel* model, | 59 bool DecodeNode(BookmarkModel* model, |
60 const DictionaryValue& value, | 60 const DictionaryValue& value, |
61 BookmarkBarNode* parent, | 61 BookmarkNode* parent, |
62 BookmarkBarNode* node); | 62 BookmarkNode* node); |
63 | 63 |
64 DISALLOW_COPY_AND_ASSIGN(BookmarkCodec); | 64 DISALLOW_COPY_AND_ASSIGN(BookmarkCodec); |
65 }; | 65 }; |
66 | 66 |
67 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_CODEC_H_ | 67 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_CODEC_H_ |
OLD | NEW |