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