Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 #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.
| |
| 5 #define CHROME_BROWSER_BOOKMARKS_ENHANCED_IMAGE_STORE_H_ | |
| 6 | |
| 7 #include <map> | |
| 8 #include <vector> | |
| 9 | |
| 10 #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.
| |
| 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> { | |
|
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
| |
| 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 | |
|
sky
2014/04/30 18:09:13
imageUrl->image_url
Kibeom Kim (inactive)
2014/05/01 19:02:26
Done.
| |
| 37 // downloaded from or failed to be downloaded from. | |
| 38 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.
| |
| 39 | |
| 40 // 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.
| |
| 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; | |
|
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.
| |
| 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: | |
|
sky
2014/04/30 18:09:13
nit: newline between 54/55.
Kibeom Kim (inactive)
2014/05/01 19:02:26
Done.
| |
| 56 friend class base::RefCounted<ImageStore>; | |
| 57 | |
| 58 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.
| |
| 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 { | |
|
sky
2014/04/30 18:09:13
Move these into their own files.
Kibeom Kim (inactive)
2014/05/01 19:02:26
Done.
| |
| 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: | |
|
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.
| |
| 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 |