OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
noyau (Ping after 24h)
2014/04/29 08:17:39
This probably should be 2014 as this is a new file
Kibeom Kim (inactive)
2014/04/29 08:22:48
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 #ifndef CHROME_BROWSER_BOOKMARKS_ENHANCED_IMAGE_STORE_H_ | |
5 #define CHROME_BROWSER_BOOKMARKS_ENHANCED_IMAGE_STORE_H_ | |
6 | |
7 #include <map> | |
8 #include <vector> | |
9 | |
10 #include "base/files/file_path.h" | |
11 #include "sql/connection.h" | |
12 #include "sql/init_status.h" | |
13 #include "ui/gfx/geometry/size.h" | |
14 #include "ui/gfx/image/image.h" | |
15 #include "url/gurl.h" | |
16 | |
17 // The ImageStore keeps an image for each URL. | |
18 class ImageStore : public base::RefCounted<ImageStore> { | |
19 public: | |
20 ImageStore() {} | |
21 | |
22 // Returns true if there is an image for this url. | |
23 virtual bool HasKey(const GURL& page_url) = 0; | |
24 | |
25 // Inserts an image and its url in the store for the the given page url. The | |
26 // image can be null indicating that the download of the image at this URL | |
27 // failed previously. | |
28 virtual void Insert(const GURL& page_url, | |
29 const GURL& image_url, | |
30 const gfx::Image& image) = 0; | |
31 | |
32 // Removes an image from the store. | |
33 virtual void Erase(const GURL& page_url) = 0; | |
34 | |
35 // Returns the image associated with this url. Returns nil if there are no | |
36 // image for this url. It also returns the imageUrl where the image was | |
37 // downloaded from or failed to be downloaded from. | |
38 virtual gfx::Image Get(const GURL& page_url, GURL& image_url) = 0; | |
39 | |
40 // Returns the size of the image stored for this URL or CGSizeZero if no | |
41 // images are present. | |
42 virtual gfx::Size GetSize(const GURL& page_url) = 0; | |
43 | |
44 // Returns all the urls that have an image in the store. | |
45 virtual std::vector<GURL> AllKeys() = 0; | |
46 | |
47 // Moves an image from one url to another. | |
48 virtual void ChangeImageURL(const GURL& from, const GURL& to); | |
49 | |
50 // Removes all images. | |
51 void ClearAll(); | |
52 | |
53 protected: | |
54 virtual ~ImageStore() {} | |
55 private: | |
56 friend class base::RefCounted<ImageStore>; | |
57 | |
58 DISALLOW_COPY_AND_ASSIGN(ImageStore); | |
59 }; | |
60 | |
61 // The MemoryImageStore is an implementation of ImageStore that keeps all its | |
62 // data in memory. When deallocated all the associations are lost. | |
63 // Used in tests. | |
64 class MemoryImageStore : public ImageStore { | |
65 public: | |
66 MemoryImageStore(); | |
67 virtual bool HasKey(const GURL& page_url) OVERRIDE; | |
68 virtual void Insert(const GURL& page_url, | |
69 const GURL& image_url, | |
70 const gfx::Image& image) OVERRIDE; | |
71 virtual void Erase(const GURL& page_url) OVERRIDE; | |
72 virtual gfx::Image Get(const GURL& page_url, GURL& image_url) OVERRIDE; | |
73 virtual gfx::Size GetSize(const GURL& page_url) OVERRIDE; | |
74 virtual std::vector<GURL> AllKeys() OVERRIDE; | |
75 protected: | |
76 virtual ~MemoryImageStore(); | |
77 private: | |
78 typedef std::map<const GURL, std::pair<gfx::Image, const GURL> > ImageMap; | |
79 ImageMap store_; | |
80 DISALLOW_COPY_AND_ASSIGN(MemoryImageStore); | |
81 }; | |
82 | |
83 // The PersistentImageStore is an implementation of ImageStore that persists its | |
84 // data on disk. | |
85 class PersistentImageStore : public ImageStore { | |
86 public: | |
87 // Creates a PersistentImageStore in the directory at the given path. | |
88 explicit PersistentImageStore(const base::FilePath& path); | |
89 virtual bool HasKey(const GURL& page_url) OVERRIDE; | |
90 virtual void Insert(const GURL& page_url, | |
91 const GURL& image_url, | |
92 const gfx::Image& image) OVERRIDE; | |
93 virtual void Erase(const GURL& page_url) OVERRIDE; | |
94 virtual gfx::Image Get(const GURL& page_url, GURL& image_url) OVERRIDE; | |
95 virtual gfx::Size GetSize(const GURL& page_url) OVERRIDE; | |
96 virtual std::vector<GURL> AllKeys() OVERRIDE; | |
97 protected: | |
98 virtual ~PersistentImageStore(); | |
99 private: | |
100 sql::InitStatus OpenDatabase(); | |
101 bool InitTables(); | |
102 bool InitIndices(); | |
103 const base::FilePath path_; | |
104 sql::Connection db_; | |
105 DISALLOW_COPY_AND_ASSIGN(PersistentImageStore); | |
106 }; | |
107 | |
108 #endif // CHROME_BROWSER_BOOKMARKS_ENHANCED_IMAGE_STORE_H_ | |
OLD | NEW |