Roll src/third_party/WebKit 8121bc6:918aba1 (svn 188871:188878)
[chromium-blink-merge.git] / components / enhanced_bookmarks / image_store.h
blob9d79506f861beabff07778aaf8f06ce4125cdd0e
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 <map>
9 #include <set>
11 #include "base/sequence_checker.h"
12 #include "ui/gfx/image/image.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 image and its url in the store for the the given page url. The
27 // image can 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(const GURL& page_url,
31 const GURL& image_url,
32 const gfx::Image& image) = 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 empty image and url if
38 // there are no image for this url. It also returns the image_url where the
39 // image was downloaded from or failed to be downloaded from.
40 virtual std::pair<gfx::Image, GURL> Get(const GURL& page_url) = 0;
42 // Returns the size of the image stored for this URL or empty size if no
43 // images are present.
44 virtual gfx::Size GetSize(const GURL& page_url) = 0;
46 // Populates |urls| with all the urls that have an image in the store.
47 virtual void GetAllPageUrls(std::set<GURL>* urls) = 0;
49 // Removes all images.
50 virtual void ClearAll() = 0;
52 // Moves an image from one url to another.
53 void ChangeImageURL(const GURL& from, const GURL& to);
55 // Returns the saved images storage size in bytes. If the storage doesn't
56 // exist yet or failed to read, returns -1.
57 virtual int64 GetStoreSizeInBytes() = 0;
59 protected:
60 base::SequenceChecker sequence_checker_;
62 private:
63 DISALLOW_COPY_AND_ASSIGN(ImageStore);
66 #endif // COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_H_