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

Unified Diff: chrome/browser/history/in_memory_url_index.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/in_memory_url_index.h
===================================================================
--- chrome/browser/history/in_memory_url_index.h (revision 125451)
+++ chrome/browser/history/in_memory_url_index.h (working copy)
@@ -15,8 +15,8 @@
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/gtest_prod_util.h"
-#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/string16.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/history_provider_util.h"
@@ -24,7 +24,6 @@
#include "chrome/browser/history/history.h"
#include "chrome/browser/history/history_types.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_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "sql/connection.h"
@@ -45,6 +44,7 @@
namespace imui = in_memory_url_index;
class HistoryDatabase;
+class RefCountedURLIndexPrivateDataPtr;
class URLIndexPrivateData;
struct URLVisitedDetails;
struct URLsModifiedDetails;
@@ -69,8 +69,33 @@
// will eliminate such words except in the case where a single character
// is being searched on and which character occurs as the second char16 of a
// multi-char16 instance.
-class InMemoryURLIndex : public content::NotificationObserver {
+class InMemoryURLIndex : public content::NotificationObserver,
+ public base::SupportsWeakPtr<InMemoryURLIndex> {
public:
+ // Defines an abstract class which is notified upon completion of restoring
+ // the index's private data either by reading from the cache file or by
+ // rebuilding from the history database.
+ class RestoreCacheObserver {
+ public:
+ virtual ~RestoreCacheObserver();
+
+ // Callback that lets the observer know that the restore operation has
+ // completed. |succeeded| indicates if the restore was successful. This is
+ // called on the UI thread.
+ virtual void OnCacheRestoreFinished(bool succeeded) = 0;
+ };
+
+ // Defines an abstract class which is notified upon completion of saving
+ // the index's private data to the cache file.
+ class SaveCacheObserver {
+ public:
+ virtual ~SaveCacheObserver();
+
+ // Callback that lets the observer know that the save succeeded.
+ // This is called on the UI thread.
+ virtual void OnCacheSaveFinished(bool succeeded) = 0;
+ };
+
// |profile|, which may be NULL during unit testing, is used to register for
// history changes. |history_dir| is a path to the directory containing the
// history database within the profile wherein the cache and transaction
@@ -96,11 +121,21 @@
// refer to that class.
ScoredHistoryMatches HistoryItemsForTerms(const string16& term_string);
+ // Sets the optional observers for completion of restoral and saving of the
+ // index's private data.
+ void set_restore_cache_observer(
+ RestoreCacheObserver* restore_cache_observer) {
+ restore_cache_observer_ = restore_cache_observer;
+ }
+ void set_save_cache_observer(SaveCacheObserver* save_cache_observer) {
+ save_cache_observer_ = save_cache_observer;
+ }
+
private:
friend class ::HistoryQuickProviderTest;
friend class InMemoryURLIndexTest;
+ friend class InMemoryURLIndexCacheTest;
FRIEND_TEST_ALL_PREFIXES(LimitedInMemoryURLIndexTest, Initialization);
- FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexCacheTest, CacheFilePath);
// Creating one of me without a history path is not allowed (tests excepted).
InMemoryURLIndex();
@@ -133,14 +168,14 @@
// provided as a hook for unit testing.)
bool GetCacheFilePath(FilePath* file_path);
+ // Sets the directory wherein the cache file will be maintained.
+ // For unit test usage only.
+ void set_history_dir(const FilePath& dir_path) { history_dir_ = dir_path; }
+
// Restores the index's private data from the cache file stored in the
// profile directory.
- void RestoreFromCacheFile();
+ void PostRestoreFromCacheFileTask();
- // Restores private_data_ from the given |path|. Runs on the UI thread.
- // Provided for unit testing so that a test cache file can be used.
- void DoRestoreFromCacheFile(const FilePath& path);
-
// Schedules a history task to rebuild our private data from the history
// database.
void ScheduleRebuildFromHistory();
@@ -155,14 +190,42 @@
// Used for unit testing only.
void RebuildFromHistory(HistoryDatabase* history_db);
- // Caches the index private data and writes the cache file to the profile
- // directory.
- void SaveToCacheFile();
+ // Posts a task to cache the index private data and write the cache file to
+ // the profile directory.
+ void PostSaveToCacheFileTask();
// Saves private_data_ to the given |path|. Runs on the UI thread.
// Provided for unit testing so that a test cache file can be used.
void DoSaveToCacheFile(const FilePath& path);
+ // Notifies the observer, if any, of the success of the private data caching.
+ // |succeeded| is true on a successful save.
+ void OnCacheSaveDone(scoped_refptr<RefCountedBool> succeeded);
+
+ // Callback used by RebuildPrivateDataFromHistoryDBTask to signal completion
+ // or rebuilding our private data from the history database. |succeeded|
+ // will be true if the rebuild was successful. |data| will point to a new
+ // instanceof the private data just rebuilt.
+ void DoneRebuidingPrivateDataFromHistoryDB(bool succeeded,
+ URLIndexPrivateData* data);
+
+ // Rebuilds the history index from the history database in |history_db|.
+ // Used for unit testing only.
+ void RebuildFromHistory(URLDatabase* history_db);
+
+ // Determines if the private data was successfully reloaded from the cache
+ // file or if the private data must be rebuilt from the history database.
+ // |private_data_ptr|'s data will be NULL if the cache file load failed.
+ void OnCacheLoadDone(
+ scoped_refptr<RefCountedURLIndexPrivateDataPtr> private_data_ptr);
+
+ // Callback function that sets the private data from the just-restored-from-
+ // file |private_data| if |succeeded| otherwise clears the private data.
+ // Notifies any |restore_cache_observer_| of success status.
+ void OnCacheRestored(URLIndexPrivateData* private_data, bool succeeded);
+
+ // Notifications -------------------------------------------------------------
+
// Handles notifications of history changes.
virtual void Observe(int notification_type,
const content::NotificationSource& source,
@@ -187,12 +250,16 @@
// The index's durable private data.
scoped_ptr<URLIndexPrivateData> private_data_;
- // Set to true once the shutdown process has begun.
- bool shutdown_;
+ // Observers to notify upon restoral or save of the private data cache.
+ RestoreCacheObserver* restore_cache_observer_;
+ SaveCacheObserver* save_cache_observer_;
CancelableRequestConsumer cache_reader_consumer_;
content::NotificationRegistrar registrar_;
+ // Set to true once the shutdown process has begun.
+ bool shutdown_;
+
// Set to true when changes to the index have been made and the index needs
// to be cached. Set to false when the index has been cached. Used as a
// temporary safety check to insure that the cache is saved before the
« no previous file with comments | « no previous file | chrome/browser/history/in_memory_url_index.cc » ('j') | chrome/browser/history/in_memory_url_index.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698