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