summaryrefslogtreecommitdiffstats
path: root/chrome/browser/thumbnail_store.h
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-04 21:43:53 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-04 21:43:53 +0000
commit1984a5fb88d86ccd8289917caa3f64f4a4afc297 (patch)
tree4c86f01bfa844798b0a2579f9036b2169c3117e5 /chrome/browser/thumbnail_store.h
parenta2068a61d67a2e90789e45a8073e631899bdeb9c (diff)
downloadchromium_src-1984a5fb88d86ccd8289917caa3f64f4a4afc297.zip
chromium_src-1984a5fb88d86ccd8289917caa3f64f4a4afc297.tar.gz
chromium_src-1984a5fb88d86ccd8289917caa3f64f4a4afc297.tar.bz2
Implement a first pass at thumbnail store storage to disk, including a unit test for the new behavior.
TEST=covered by unittest BUG=none git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17670 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/thumbnail_store.h')
-rw-r--r--chrome/browser/thumbnail_store.h57
1 files changed, 47 insertions, 10 deletions
diff --git a/chrome/browser/thumbnail_store.h b/chrome/browser/thumbnail_store.h
index bfff59a..46b6ae0 100644
--- a/chrome/browser/thumbnail_store.h
+++ b/chrome/browser/thumbnail_store.h
@@ -5,11 +5,16 @@
#ifndef CHROME_BROWSER_THUMBNAIL_STORE_H_
#define CHROME_BROWSER_THUMBNAIL_STORE_H_
+#include <map>
#include <vector>
#include "base/file_path.h"
+#include "base/message_loop.h"
+#include "base/ref_counted.h"
+#include "testing/gtest/include/gtest/gtest_prod.h"
class GURL;
+class Pickle;
class SkBitmap;
struct ThumbnailScore;
namespace base {
@@ -18,7 +23,7 @@ class Time;
// This storage interface provides storage for the thumbnails used
// by the new_tab_ui.
-class ThumbnailStore {
+class ThumbnailStore : public base::RefCountedThreadSafe<ThumbnailStore> {
public:
ThumbnailStore();
~ThumbnailStore();
@@ -26,34 +31,66 @@ class ThumbnailStore {
// Must be called after creation but before other methods are called.
// file_path is a directory where a new database should be created
// or the location of an existing databse.
- // If false is returned, no other methods should be called.
- bool Init(const FilePath& file_path);
+ void Init(const FilePath& file_path);
- // Stores the given thumbnail and score with the associated url.
+ // Stores the given thumbnail and score with the associated url in the cache.
+ // If write_to_disk is true, the thumbnail data is written to disk on the
+ // file_thread.
bool SetPageThumbnail(const GURL& url,
- const SkBitmap& thumbnail,
+ SkBitmap& thumbnail,
const ThumbnailScore& score,
- const base::Time& time);
+ bool write_to_disk);
// Retrieves the thumbnail and score for the given url.
// Returns false if there is not data for the given url or some other
// error occurred.
bool GetPageThumbnail(const GURL& url,
- SkBitmap** thumbnail,
- ThumbnailScore& score);
+ SkBitmap* thumbnail,
+ ThumbnailScore* score);
private:
+ FRIEND_TEST(ThumbnailStoreTest, RetrieveFromCache);
+ FRIEND_TEST(ThumbnailStoreTest, RetrieveFromDisk);
+
+ // Data structure used to store thumbnail data in memory.
+ typedef std::map<GURL, std::pair<SkBitmap, ThumbnailScore> > Cache;
+
// The location of the thumbnail store.
FilePath file_path_;
+ // Read all thumbnail data from the specified FilePath into a Cache object.
+ // Done on the file_thread and returns to OnDiskDataAvailable on the thread
+ // owning the specified MessageLoop.
+ void GetAllThumbnailsFromDisk(FilePath filepath, MessageLoop* cb_loop);
+
+ // Read the thumbnail data from the given file and stores it in the
+ // out parameters GURL, SkBitmap, and ThumbnailScore.
+ bool GetPageThumbnailFromDisk(const FilePath& file,
+ GURL* url,
+ SkBitmap* thumbnail,
+ ThumbnailScore* score) const;
+
+ // Once thumbnail data from the disk is available from the file_thread,
+ // this function is invoked on the main thread. It takes ownership of the
+ // Cache* passed in and retains this Cache* for the lifetime of the object.
+ void OnDiskDataAvailable(ThumbnailStore::Cache* cache);
+
+ // Write thumbnail data to disk for a given url.
+ bool WriteThumbnailToDisk(const GURL& url) const;
+
// Pack the given ThumbnailScore into the given Pickle.
- void PackScore(const ThumbnailScore& score, Pickle& packed);
+ void PackScore(const ThumbnailScore& score, Pickle* packed) const;
// Unpack a ThumbnailScore from a given Pickle and associated iterator.
// Returns false is a ThumbnailScore could not be unpacked.
- bool UnpackScore(ThumbnailScore* score, const Pickle& packed, void*& iter);
+ bool UnpackScore(ThumbnailScore* score, const Pickle& packed,
+ void*& iter) const;
DISALLOW_COPY_AND_ASSIGN(ThumbnailStore);
+
+ // The Cache maintained by the object.
+ scoped_ptr<ThumbnailStore::Cache> cache_;
+ bool cache_initialized_;
};
#endif // CHROME_BROWSER_THUMBNAIL_STORE_H_