diff options
author | meelapshah@chromium.org <meelapshah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-08 00:08:31 +0000 |
---|---|---|
committer | meelapshah@chromium.org <meelapshah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-08 00:08:31 +0000 |
commit | 3254563421b09469b9668ff69562d098a8661d23 (patch) | |
tree | b9222dcaebe54cc87dcf47f952f58d124ae9b4ab /chrome/browser/thumbnail_store.h | |
parent | cb1da54001174e027d1bd5de4dbc5a91dca140e2 (diff) | |
download | chromium_src-3254563421b09469b9668ff69562d098a8661d23.zip chromium_src-3254563421b09469b9668ff69562d098a8661d23.tar.gz chromium_src-3254563421b09469b9668ff69562d098a8661d23.tar.bz2 |
Reverting 20097.
Review URL: http://codereview.chromium.org/155186
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20101 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/thumbnail_store.h')
-rw-r--r-- | chrome/browser/thumbnail_store.h | 78 |
1 files changed, 42 insertions, 36 deletions
diff --git a/chrome/browser/thumbnail_store.h b/chrome/browser/thumbnail_store.h index 0ec81f4..cf29e43 100644 --- a/chrome/browser/thumbnail_store.h +++ b/chrome/browser/thumbnail_store.h @@ -15,19 +15,17 @@ #include "base/timer.h" #include "chrome/browser/cancelable_request.h" #include "chrome/browser/history/history.h" -#include "chrome/browser/history/url_database.h" // For DBCloseScoper #include "chrome/common/pref_names.h" #include "chrome/common/ref_counted_util.h" -#include "chrome/common/sqlite_compiled_statement.h" -#include "chrome/common/thumbnail_score.h" #include "testing/gtest/include/gtest/gtest_prod.h" class DictionaryValue; class GURL; class HistoryService; +class Pickle; class Profile; class SkBitmap; -struct sqlite3; +struct ThumbnailScore; namespace base { class Time; } @@ -40,13 +38,17 @@ class ThumbnailStore : public base::RefCountedThreadSafe<ThumbnailStore> { ~ThumbnailStore(); // Must be called after creation but before other methods are called. - void Init(const FilePath& db_name, // The location of the database. - Profile* profile); // To get to the HistoryService. + // file_path is a directory where a new database should be created + // or the location of an existing databse. + void Init(const FilePath& file_path, Profile* profile); // 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, - const ThumbnailScore& score); + const ThumbnailScore& score, + bool write_to_disk); // Sets *data to point to the thumbnail for the given url. // Returns false if no thumbnail available. @@ -59,22 +61,9 @@ class ThumbnailStore : public base::RefCountedThreadSafe<ThumbnailStore> { FRIEND_TEST(ThumbnailStoreTest, FollowRedirects); friend class ThumbnailStoreTest; - struct CacheEntry { - scoped_refptr<RefCountedBytes> data_; - ThumbnailScore score_; - bool dirty_; - - CacheEntry() : data_(NULL), score_(ThumbnailScore()), dirty_(false) {} - CacheEntry(RefCountedBytes* data, - const ThumbnailScore& score, - bool dirty) - : data_(data), - score_(score), - dirty_(dirty) {} - }; - // Data structure used to store thumbnail data in memory. - typedef std::map<GURL, CacheEntry> Cache; + typedef std::map<GURL, std::pair<scoped_refptr<RefCountedBytes>, + ThumbnailScore> > Cache; // Most visited URLs and their redirect lists ------------------------------- @@ -83,7 +72,8 @@ class ThumbnailStore : public base::RefCountedThreadSafe<ThumbnailStore> { // callback is OnURLDataAvailable. void UpdateURLData(); - // The callback for UpdateURLData. + // The callback for UpdateURLData. The ThumbnailStore takes ownership of + // the most visited urls list and redirect lists passed in. void OnURLDataAvailable(std::vector<GURL>* urls, history::RedirectMap* redirects); @@ -94,26 +84,43 @@ class ThumbnailStore : public base::RefCountedThreadSafe<ThumbnailStore> { // visited sites. void CleanCacheData(); - // Disk operations ---------------------------------------------------------- + // Deletes thumbnail data from disk for the given list of urls. + void DeleteThumbnails( + scoped_refptr<RefCountedVector<GURL> > thumbnail_urls) const; - // Initialize |db_| to the database specified in |db_name|. If |cb_loop| - // is non-null, calls GetAllThumbnailsFromDisk. Done on the file_thread. - void InitializeFromDB(const FilePath& db_name, MessageLoop* cb_loop); + // Disk operations ---------------------------------------------------------- // 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(MessageLoop* cb_loop); + 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, + RefCountedBytes* data, + 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(Cache* cache); - // Delete each URL in the given vector from the DB and write all dirty - // cache entries to the DB. - void CommitCacheToDB( - scoped_refptr<RefCountedVector<GURL> > stale_urls) const; + // Write thumbnail data to disk for a given url. + bool WriteThumbnailToDisk(const GURL& url, + scoped_refptr<RefCountedBytes> data, + const ThumbnailScore& score) const; + + + // Pack the given ThumbnailScore into the given Pickle. + 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) const; // Decide whether to store data --------------------------------------------- @@ -132,11 +139,10 @@ class ThumbnailStore : public base::RefCountedThreadSafe<ThumbnailStore> { // The Cache maintained by the object. scoped_ptr<Cache> cache_; + bool cache_initialized_; - // The database holding the thumbnails on disk. - sqlite3* db_; - SqliteStatementCache* statement_cache_; - history::DBCloseScoper close_scoper_; + // The location of the thumbnail store. + FilePath file_path_; // We hold a reference to the history service to query for most visited URLs // and redirect information. |