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

Unified Diff: chrome/browser/history/url_index_private_data.h

Issue 9030031: Move InMemoryURLIndex Caching Operations to FILE Thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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/history/url_index_private_data.h
===================================================================
--- chrome/browser/history/url_index_private_data.h (revision 125451)
+++ chrome/browser/history/url_index_private_data.h (working copy)
@@ -8,8 +8,11 @@
#include "base/file_path.h"
#include "base/gtest_prod_util.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "chrome/browser/history/in_memory_url_index_types.h"
#include "chrome/browser/history/in_memory_url_index_cache.pb.h"
+#include "content/public/browser/notification_details.h"
class HistoryQuickProviderTest;
@@ -22,7 +25,27 @@
namespace imui = in_memory_url_index;
class HistoryDatabase;
+class InMemoryURLIndex;
+class URLIndexPrivateData;
+// A helper class to carry around a pointer to private data that is being
+// restored from the cache or rebuilt from the history database.
+class RefCountedURLIndexPrivateDataPtr
+ : public base::RefCountedThreadSafe<RefCountedURLIndexPrivateDataPtr> {
+ public:
+ RefCountedURLIndexPrivateDataPtr();
+
+ URLIndexPrivateData* get();
+ URLIndexPrivateData* release();
brettw 2012/03/12 04:37:40 Delete release and reset.
mrossetti 2012/03/13 22:25:46 This whole class is gone now.
+ void reset(URLIndexPrivateData* data);
+
+ private:
+ friend class base::RefCountedThreadSafe<RefCountedURLIndexPrivateDataPtr>;
+ virtual ~RefCountedURLIndexPrivateDataPtr();
+
+ scoped_ptr<URLIndexPrivateData> data_;
brettw 2012/03/12 04:37:40 I don't think you should wrap a scoped_ptr with a
mrossetti 2012/03/12 23:21:13 Because I wanted the original class to be copy-abl
mrossetti 2012/03/13 22:25:46 Done.
+};
+
// A structure describing the InMemoryURLIndex's internal data and providing for
// restoring, rebuilding and updating that internal data.
class URLIndexPrivateData {
@@ -131,23 +154,41 @@
// down into words and each word is broken down into characters.
void set_languages(const std::string& languages) { languages_ = languages; }
- // Restores the index's private data from the cache file stored in the
- // profile directory and returns true if successful.
- bool RestoreFromFile(const FilePath& file_path);
+ // Creates a new URLIndexPrivateData object, populates it from the contents
+ // of the cache file stored in |file_path|, and assigns it to
+ // |private_data_ptr|.
+ static void RestoreFromFileTask(
+ const FilePath& file_path,
+ scoped_refptr<RefCountedURLIndexPrivateDataPtr> private_data_ptr);
+ // Constructs a new object by restoring its contents from the file at |path|.
+ // Returns the new URLIndexPrivateData which on success will contain the
+ // restored data but upon failure will be empty.
+ static URLIndexPrivateData* RestoreFromFile(const FilePath& path);
+
// Constructs a new object by rebuilding its contents from the history
// database in |history_db|. Returns the new URLIndexPrivateData which on
// success will contain the rebuilt data but upon failure will be empty.
static URLIndexPrivateData* RebuildFromHistory(HistoryDatabase* history_db);
+ // Writes |private_data| as a cache file to |file_path| and returns success
+ // via |succeeded|.
+ static void WritePrivateDataToCacheFileTask(
+ scoped_ptr<URLIndexPrivateData> private_data,
+ const FilePath& file_path,
+ scoped_refptr<history::RefCountedBool> succeeded);
+
// Caches the index private data and writes the cache file to the profile
- // directory.
+ // directory. Called by WritePrivateDataToCacheFileTask.
bool SaveToFile(const FilePath& file_path);
// Initializes all index data members in preparation for restoring the index
// from the cache or a complete rebuild from the history database.
void Clear();
+ // Returns true if there is no data in the index.
+ bool Empty() const;
+
// Adds |word_id| to |history_id|'s entry in the history/word map,
// creating a new entry if one does not already exist.
void AddToHistoryIDWordMap(HistoryID history_id, WordID word_id);
@@ -230,9 +271,6 @@
static int ScoreComponentForMatches(const TermMatches& matches,
size_t max_length);
- // Determines if |gurl| has a whitelisted scheme and returns true if so.
- bool URLSchemeIsWhitelisted(const GURL& gurl) const;
-
// Encode a data structure into the protobuf |cache|.
void SavePrivateData(imui::InMemoryURLIndexCacheItem* cache) const;
void SaveWordList(imui::InMemoryURLIndexCacheItem* cache) const;
@@ -250,6 +288,9 @@
bool RestoreWordIDHistoryMap(const imui::InMemoryURLIndexCacheItem& cache);
bool RestoreHistoryInfoMap(const imui::InMemoryURLIndexCacheItem& cache);
+ // Determines if |gurl| has a whitelisted scheme and returns true if so.
+ bool URLSchemeIsWhitelisted(const GURL& gurl) const;
+
// Cache of search terms.
SearchTermCacheMap search_term_cache_;

Powered by Google App Engine
This is Rietveld 408576698