metadata_accessor.h revision 6d86b77056ed63eb6871182f42a9fd5f07550f90
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
3// found in the LICENSE file.
4
5#ifndef COMPONENTS_ENHANCED_BOOKMARKS_METADATA_ACCESSOR_H_
6#define COMPONENTS_ENHANCED_BOOKMARKS_METADATA_ACCESSOR_H_
7
8#include <set>
9#include <string>
10#include <vector>
11
12class BookmarkModel;
13class BookmarkNode;
14class GURL;
15
16// The functions in this file store and retrieve structured data encoded in the
17// bookmark metadata. This information suplements the data in the bookmark with
18// images and descriptions related to the url.
19namespace enhanced_bookmarks {
20
21typedef std::vector<const BookmarkNode*> NodeVector;
22typedef std::set<const BookmarkNode*> NodeSet;
23
24// The keys used to store the data in the bookmarks metadata dictionary.
25extern const char* kPageDataKey;
26extern const char* kImageDataKey;
27extern const char* kIdDataKey;
28extern const char* kNoteKey;
29
30// Returns the remoteId for a bookmark. If the bookmark doesn't have one already
31// this function will create and set one.
32std::string RemoteIdFromBookmark(BookmarkModel* bookmark_model,
33                                 const BookmarkNode* node);
34
35// Sets the description of a bookmark.
36void SetDescriptionForBookmark(BookmarkModel* bookmark_model,
37                               const BookmarkNode* node,
38                               const std::string& description);
39
40// Returns the description of a bookmark.
41std::string DescriptionFromBookmark(const BookmarkNode* node);
42
43// Sets the URL of an image representative of the page.
44// Expects the URL to be valid and not empty.
45// Returns true if the metainfo is successfully populated.
46bool SetOriginalImageForBookmark(BookmarkModel* bookmark_model,
47                                 const BookmarkNode* node,
48                                 const GURL& url,
49                                 int width,
50                                 int height);
51
52// Returns the url and dimensions of the original scraped image.
53// Returns true if the out variables are populated, false otherwise.
54bool OriginalImageFromBookmark(const BookmarkNode* node,
55                               GURL* url,
56                               int* width,
57                               int* height);
58
59// Returns the url and dimensions of the server provided thumbnail image.
60// Returns true if the out variables are populated, false otherwise.
61bool ThumbnailImageFromBookmark(const BookmarkNode* node,
62                                GURL* url,
63                                int* width,
64                                int* height);
65
66// Returns a brief server provided synopsis of the bookmarked page.
67// Returns the empty string if the snippet could not be extracted.
68std::string SnippetFromBookmark(const BookmarkNode* node);
69
70// Used for testing, simulates the process that creates the thumnails. Will
71// remove existing entries for empty urls or set them if the url is not empty.
72// expects valid or empty urls. Returns true if the metainfo is successfully
73// populated.
74bool SetAllImagesForBookmark(BookmarkModel* bookmark_model,
75                             const BookmarkNode* node,
76                             const GURL& image_url,
77                             int image_width,
78                             int image_height,
79                             const GURL& thumbnail_url,
80                             int thumbnail_width,
81                             int thumbnail_height);
82
83}  // namespace enhanced_bookmarks
84
85#endif  // COMPONENTS_ENHANCED_BOOKMARKS_METADATA_ACCESSOR_H_
86