Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / enhanced_bookmarks / image_store.h
blobe92ba5a472bcd7055a90e8b02396834fb84e60f2
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.
5 #ifndef COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_H_
6 #define COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_H_
8 #include <set>
10 #include "base/sequence_checker.h"
11 #include "components/enhanced_bookmarks/image_record.h"
12 #include "ui/gfx/geometry/size.h"
14 class GURL;
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.
18 class ImageStore {
19 public:
20 ImageStore();
21 virtual ~ImageStore();
23 // Returns true if there is an image for this url.
24 virtual bool HasKey(const GURL& page_url) = 0;
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
28 // encoding for insertion failed previously. On non-iOS platforms, |image|
29 // must have exactly one representation with a scale factor of 1.
30 virtual void Insert(
31 const GURL& page_url,
32 scoped_refptr<enhanced_bookmarks::ImageRecord> image_record) = 0;
34 // Removes an image from the store.
35 virtual void Erase(const GURL& page_url) = 0;
37 // Returns the image associated with this url. Returns an ImageRecord with an
38 // empty image if there is no image for this url. It also returns the
39 // image_url where the image was downloaded from or failed to be downloaded
40 // from. When the image is not empty, the dominant color of the image is also
41 // filled.
42 virtual scoped_refptr<enhanced_bookmarks::ImageRecord> Get(
43 const GURL& page_url) = 0;
45 // Returns the size of the image stored for this URL or empty size if no
46 // images are present.
47 virtual gfx::Size GetSize(const GURL& page_url) = 0;
49 // Populates |urls| with all the urls that have an image in the store.
50 virtual void GetAllPageUrls(std::set<GURL>* urls) = 0;
52 // Removes all images.
53 virtual void ClearAll() = 0;
55 // Moves an image from one url to another.
56 void ChangeImageURL(const GURL& from, const GURL& to);
58 // Returns the saved images storage size in bytes. If the storage doesn't
59 // exist yet or failed to read, returns -1.
60 virtual int64 GetStoreSizeInBytes() = 0;
62 protected:
63 base::SequenceChecker sequence_checker_;
65 private:
66 DISALLOW_COPY_AND_ASSIGN(ImageStore);
69 #endif // COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_H_