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 <set> | 8 #include <set> |
9 | 9 |
10 #include "base/sequence_checker.h" | 10 #include "base/sequence_checker.h" |
11 #include "components/enhanced_bookmarks/image_record.h" | 11 #include "components/enhanced_bookmarks/image_record.h" |
12 #include "ui/gfx/geometry/size.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 ImageRecord in the store for the given page url. The image can | 26 // Inserts an ImageRecord in the store for the given page url. The image can |
27 // 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( |
31 const enhanced_bookmarks::ImageRecord& image_record) = 0; | 31 const GURL& page_url, |
| 32 scoped_refptr<enhanced_bookmarks::ImageRecord> image_record) = 0; |
32 | 33 |
33 // Removes an image from the store. | 34 // Removes an image from the store. |
34 virtual void Erase(const GURL& page_url) = 0; | 35 virtual void Erase(const GURL& page_url) = 0; |
35 | 36 |
36 // Returns the image associated with this url. Returns an ImageRecord with an | 37 // Returns the image associated with this url. Returns an ImageRecord with an |
37 // empty image if there is no image for this url. It also returns the | 38 // empty image if there is no image for this url. It also returns the |
38 // image_url where the image was downloaded from or failed to be downloaded | 39 // image_url where the image was downloaded from or failed to be downloaded |
39 // from. When the image is not empty, the dominant color of the image is also | 40 // from. When the image is not empty, the dominant color of the image is also |
40 // filled. | 41 // filled. |
41 virtual enhanced_bookmarks::ImageRecord Get(const GURL& page_url) = 0; | 42 virtual scoped_refptr<enhanced_bookmarks::ImageRecord> Get( |
| 43 const GURL& page_url) = 0; |
42 | 44 |
43 // Returns the size of the image stored for this URL or empty size if no | 45 // Returns the size of the image stored for this URL or empty size if no |
44 // images are present. | 46 // images are present. |
45 virtual gfx::Size GetSize(const GURL& page_url) = 0; | 47 virtual gfx::Size GetSize(const GURL& page_url) = 0; |
46 | 48 |
47 // Populates |urls| with all the urls that have an image in the store. | 49 // Populates |urls| with all the urls that have an image in the store. |
48 virtual void GetAllPageUrls(std::set<GURL>* urls) = 0; | 50 virtual void GetAllPageUrls(std::set<GURL>* urls) = 0; |
49 | 51 |
50 // Removes all images. | 52 // Removes all images. |
51 virtual void ClearAll() = 0; | 53 virtual void ClearAll() = 0; |
52 | 54 |
53 // Moves an image from one url to another. | 55 // Moves an image from one url to another. |
54 void ChangeImageURL(const GURL& from, const GURL& to); | 56 void ChangeImageURL(const GURL& from, const GURL& to); |
55 | 57 |
56 // Returns the saved images storage size in bytes. If the storage doesn't | 58 // Returns the saved images storage size in bytes. If the storage doesn't |
57 // exist yet or failed to read, returns -1. | 59 // exist yet or failed to read, returns -1. |
58 virtual int64 GetStoreSizeInBytes() = 0; | 60 virtual int64 GetStoreSizeInBytes() = 0; |
59 | 61 |
60 protected: | 62 protected: |
61 base::SequenceChecker sequence_checker_; | 63 base::SequenceChecker sequence_checker_; |
62 | 64 |
63 private: | 65 private: |
64 DISALLOW_COPY_AND_ASSIGN(ImageStore); | 66 DISALLOW_COPY_AND_ASSIGN(ImageStore); |
65 }; | 67 }; |
66 | 68 |
67 #endif // COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_H_ | 69 #endif // COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_H_ |
OLD | NEW |