Index: chrome/browser/bookmarks/enhanced/image_store.h |
diff --git a/chrome/browser/bookmarks/enhanced/image_store.h b/chrome/browser/bookmarks/enhanced/image_store.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..24654b176e5aff2b2060887b383b4fd3d845f168 |
--- /dev/null |
+++ b/chrome/browser/bookmarks/enhanced/image_store.h |
@@ -0,0 +1,108 @@ |
+// 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.
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+#ifndef CHROME_BROWSER_BOOKMARKS_ENHANCED_IMAGE_STORE_H_ |
+#define CHROME_BROWSER_BOOKMARKS_ENHANCED_IMAGE_STORE_H_ |
+ |
+#include <map> |
+#include <vector> |
+ |
+#include "base/files/file_path.h" |
+#include "sql/connection.h" |
+#include "sql/init_status.h" |
+#include "ui/gfx/geometry/size.h" |
+#include "ui/gfx/image/image.h" |
+#include "url/gurl.h" |
+ |
+// The ImageStore keeps an image for each URL. |
+class ImageStore : public base::RefCounted<ImageStore> { |
+ public: |
+ ImageStore() {} |
+ |
+ // Returns true if there is an image for this url. |
+ virtual bool HasKey(const GURL& page_url) = 0; |
+ |
+ // Inserts an image and its url in the store for the the given page url. The |
+ // image can be null indicating that the download of the image at this URL |
+ // failed previously. |
+ virtual void Insert(const GURL& page_url, |
+ const GURL& image_url, |
+ const gfx::Image& image) = 0; |
+ |
+ // Removes an image from the store. |
+ virtual void Erase(const GURL& page_url) = 0; |
+ |
+ // Returns the image associated with this url. Returns nil if there are no |
+ // image for this url. It also returns the imageUrl where the image was |
+ // downloaded from or failed to be downloaded from. |
+ virtual gfx::Image Get(const GURL& page_url, GURL& image_url) = 0; |
+ |
+ // Returns the size of the image stored for this URL or CGSizeZero if no |
+ // images are present. |
+ virtual gfx::Size GetSize(const GURL& page_url) = 0; |
+ |
+ // Returns all the urls that have an image in the store. |
+ virtual std::vector<GURL> AllKeys() = 0; |
+ |
+ // Moves an image from one url to another. |
+ virtual void ChangeImageURL(const GURL& from, const GURL& to); |
+ |
+ // Removes all images. |
+ void ClearAll(); |
+ |
+ protected: |
+ virtual ~ImageStore() {} |
+ private: |
+ friend class base::RefCounted<ImageStore>; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ImageStore); |
+}; |
+ |
+// The MemoryImageStore is an implementation of ImageStore that keeps all its |
+// data in memory. When deallocated all the associations are lost. |
+// Used in tests. |
+class MemoryImageStore : public ImageStore { |
+ public: |
+ MemoryImageStore(); |
+ virtual bool HasKey(const GURL& page_url) OVERRIDE; |
+ virtual void Insert(const GURL& page_url, |
+ const GURL& image_url, |
+ const gfx::Image& image) OVERRIDE; |
+ virtual void Erase(const GURL& page_url) OVERRIDE; |
+ virtual gfx::Image Get(const GURL& page_url, GURL& image_url) OVERRIDE; |
+ virtual gfx::Size GetSize(const GURL& page_url) OVERRIDE; |
+ virtual std::vector<GURL> AllKeys() OVERRIDE; |
+ protected: |
+ virtual ~MemoryImageStore(); |
+ private: |
+ typedef std::map<const GURL, std::pair<gfx::Image, const GURL> > ImageMap; |
+ ImageMap store_; |
+ DISALLOW_COPY_AND_ASSIGN(MemoryImageStore); |
+}; |
+ |
+// The PersistentImageStore is an implementation of ImageStore that persists its |
+// data on disk. |
+class PersistentImageStore : public ImageStore { |
+ public: |
+ // Creates a PersistentImageStore in the directory at the given path. |
+ explicit PersistentImageStore(const base::FilePath& path); |
+ virtual bool HasKey(const GURL& page_url) OVERRIDE; |
+ virtual void Insert(const GURL& page_url, |
+ const GURL& image_url, |
+ const gfx::Image& image) OVERRIDE; |
+ virtual void Erase(const GURL& page_url) OVERRIDE; |
+ virtual gfx::Image Get(const GURL& page_url, GURL& image_url) OVERRIDE; |
+ virtual gfx::Size GetSize(const GURL& page_url) OVERRIDE; |
+ virtual std::vector<GURL> AllKeys() OVERRIDE; |
+ protected: |
+ virtual ~PersistentImageStore(); |
+ private: |
+ sql::InitStatus OpenDatabase(); |
+ bool InitTables(); |
+ bool InitIndices(); |
+ const base::FilePath path_; |
+ sql::Connection db_; |
+ DISALLOW_COPY_AND_ASSIGN(PersistentImageStore); |
+}; |
+ |
+#endif // CHROME_BROWSER_BOOKMARKS_ENHANCED_IMAGE_STORE_H_ |