Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Unified Diff: chrome/browser/bookmarks/enhanced/image_store.h

Issue 259863007: Local salient image storage for enhanced bookmark experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..550ccc02a39138d7e91cd4c68598919707b01dc3
--- /dev/null
+++ b/chrome/browser/bookmarks/enhanced/image_store.h
@@ -0,0 +1,108 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// 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_
sky 2014/04/30 18:09:13 Shouldn't all this code live in components now?
sky 2014/04/30 18:09:13 nit: newline between 3/4.
Kibeom Kim (inactive) 2014/05/01 19:02:26 Done.
Kibeom Kim (inactive) 2014/05/01 19:02:26 Done.
+#define CHROME_BROWSER_BOOKMARKS_ENHANCED_IMAGE_STORE_H_
+
+#include <map>
+#include <vector>
+
+#include "base/files/file_path.h"
sky 2014/04/30 18:09:13 nit: forward declare as much as you can.
Kibeom Kim (inactive) 2014/05/01 19:02:26 Done.
+#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> {
sky 2014/04/30 18:09:13 What thread is all this code used from?
Kibeom Kim (inactive) 2014/05/01 19:02:26 Thanks for pointing this out! ImageStore will be
sky 2014/05/01 20:11:56 Doesn't that mean you could potentially be destroy
+ 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
sky 2014/04/30 18:09:13 imageUrl->image_url
Kibeom Kim (inactive) 2014/05/01 19:02:26 Done.
+ // downloaded from or failed to be downloaded from.
+ virtual gfx::Image Get(const GURL& page_url, GURL& image_url) = 0;
sky 2014/04/30 18:09:13 style guide says all refs should be const. If you
Kibeom Kim (inactive) 2014/05/01 19:02:26 Done.
+
+ // Returns the size of the image stored for this URL or CGSizeZero if no
sky 2014/04/30 18:09:13 CGSizeZero->empty size
Kibeom Kim (inactive) 2014/05/01 19:02:26 Done.
+ // 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;
sky 2014/04/30 18:09:13 From the name it isn't clear if this is intended t
Kibeom Kim (inactive) 2014/05/01 19:02:26 Done.
+
+ // 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:
sky 2014/04/30 18:09:13 nit: newline between 54/55.
Kibeom Kim (inactive) 2014/05/01 19:02:26 Done.
+ friend class base::RefCounted<ImageStore>;
+
+ DISALLOW_COPY_AND_ASSIGN(ImageStore);
sky 2014/04/30 18:09:13 I don't believe this is necessary for a pure virtu
Kibeom Kim (inactive) 2014/05/01 19:02:26 Done.
+};
+
+// 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 {
sky 2014/04/30 18:09:13 Move these into their own files.
Kibeom Kim (inactive) 2014/05/01 19:02:26 Done.
+ 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:
sky 2014/04/30 18:09:13 nit: newline before new section headers (except fo
Kibeom Kim (inactive) 2014/05/01 19:02:26 Done.
+ 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_
« no previous file with comments | « no previous file | chrome/browser/bookmarks/enhanced/image_store.cc » ('j') | chrome/browser/bookmarks/enhanced/image_store.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698