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