OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_H_ | 5 #ifndef COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_H_ |
6 #define COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_H_ | 6 #define COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_H_ |
7 | 7 |
8 #include <map> | |
9 #include <set> | 8 #include <set> |
10 | 9 |
11 #include "base/sequence_checker.h" | 10 #include "base/sequence_checker.h" |
12 #include "ui/gfx/image/image.h" | 11 #include "components/enhanced_bookmarks/image_record.h" |
| 12 #include "ui/gfx/geometry/size.h" |
13 | 13 |
14 class GURL; | 14 class GURL; |
15 | 15 |
16 // The ImageStore keeps an image for each URL. This class is not thread safe, | 16 // The ImageStore keeps an image for each URL. This class is not thread safe, |
17 // and will check the thread using base::ThreadChecker, except the constructor. | 17 // and will check the thread using base::ThreadChecker, except the constructor. |
18 class ImageStore { | 18 class ImageStore { |
19 public: | 19 public: |
20 ImageStore(); | 20 ImageStore(); |
21 virtual ~ImageStore(); | 21 virtual ~ImageStore(); |
22 | 22 |
23 // Returns true if there is an image for this url. | 23 // Returns true if there is an image for this url. |
24 virtual bool HasKey(const GURL& page_url) = 0; | 24 virtual bool HasKey(const GURL& page_url) = 0; |
25 | 25 |
26 // Inserts an image and its url in the store for the the given page url. The | 26 // Inserts an ImageRecord in the store for the given page url. The image can |
27 // image can be null indicating that the download of the image at this URL or | 27 // be null indicating that the download of the image at this URL or |
28 // encoding for insertion failed previously. On non-ios platforms, |image| | 28 // encoding for insertion failed previously. On non-iOS platforms, |image| |
29 // must have exactly one representation with a scale factor of 1. | 29 // must have exactly one representation with a scale factor of 1. |
30 virtual void Insert(const GURL& page_url, | 30 virtual void Insert(const GURL& page_url, |
31 const GURL& image_url, | 31 const enhanced_bookmarks::ImageRecord& image_record) = 0; |
32 const gfx::Image& image) = 0; | |
33 | 32 |
34 // Removes an image from the store. | 33 // Removes an image from the store. |
35 virtual void Erase(const GURL& page_url) = 0; | 34 virtual void Erase(const GURL& page_url) = 0; |
36 | 35 |
37 // Returns the image associated with this url. Returns empty image and url if | 36 // Returns the image associated with this url. Returns an ImageRecord with an |
38 // there are no image for this url. It also returns the image_url where the | 37 // empty image if there is no image for this url. It also returns the |
39 // image was downloaded from or failed to be downloaded from. | 38 // image_url where the image was downloaded from or failed to be downloaded |
40 virtual std::pair<gfx::Image, GURL> Get(const GURL& page_url) = 0; | 39 // from. When the image is not empty, the dominant color of the image is also |
| 40 // filled. |
| 41 virtual enhanced_bookmarks::ImageRecord Get(const GURL& page_url) = 0; |
41 | 42 |
42 // Returns the size of the image stored for this URL or empty size if no | 43 // Returns the size of the image stored for this URL or empty size if no |
43 // images are present. | 44 // images are present. |
44 virtual gfx::Size GetSize(const GURL& page_url) = 0; | 45 virtual gfx::Size GetSize(const GURL& page_url) = 0; |
45 | 46 |
46 // Populates |urls| with all the urls that have an image in the store. | 47 // Populates |urls| with all the urls that have an image in the store. |
47 virtual void GetAllPageUrls(std::set<GURL>* urls) = 0; | 48 virtual void GetAllPageUrls(std::set<GURL>* urls) = 0; |
48 | 49 |
49 // Removes all images. | 50 // Removes all images. |
50 virtual void ClearAll() = 0; | 51 virtual void ClearAll() = 0; |
51 | 52 |
52 // Moves an image from one url to another. | 53 // Moves an image from one url to another. |
53 void ChangeImageURL(const GURL& from, const GURL& to); | 54 void ChangeImageURL(const GURL& from, const GURL& to); |
54 | 55 |
55 // Returns the saved images storage size in bytes. If the storage doesn't | 56 // Returns the saved images storage size in bytes. If the storage doesn't |
56 // exist yet or failed to read, returns -1. | 57 // exist yet or failed to read, returns -1. |
57 virtual int64 GetStoreSizeInBytes() = 0; | 58 virtual int64 GetStoreSizeInBytes() = 0; |
58 | 59 |
59 protected: | 60 protected: |
60 base::SequenceChecker sequence_checker_; | 61 base::SequenceChecker sequence_checker_; |
61 | 62 |
62 private: | 63 private: |
63 DISALLOW_COPY_AND_ASSIGN(ImageStore); | 64 DISALLOW_COPY_AND_ASSIGN(ImageStore); |
64 }; | 65 }; |
65 | 66 |
66 #endif // COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_H_ | 67 #endif // COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_H_ |
OLD | NEW |