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

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

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.cc
===================================================================
--- chrome/browser/history/url_index_private_data.cc (revision 125451)
+++ chrome/browser/history/url_index_private_data.cc (working copy)
@@ -14,11 +14,15 @@
#include "base/i18n/case_conversion.h"
#include "base/metrics/histogram.h"
#include "base/string_util.h"
-#include "base/threading/thread_restrictions.h"
+#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/history/history_database.h"
+#include "chrome/browser/history/in_memory_url_index.h"
#include "chrome/common/url_constants.h"
+#include "content/public/browser/notification_details.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_source.h"
#include "net/base/net_util.h"
#include "third_party/protobuf/src/google/protobuf/repeated_field.h"
@@ -54,6 +58,21 @@
// final calculation.
const int kScoreRank[] = { 1450, 1200, 900, 400 };
+// RefCountedURLIndexPrivateDataPtr --------------------------------------------
+
+RefCountedURLIndexPrivateDataPtr::RefCountedURLIndexPrivateDataPtr() {}
+RefCountedURLIndexPrivateDataPtr::~RefCountedURLIndexPrivateDataPtr() {}
+
+URLIndexPrivateData* RefCountedURLIndexPrivateDataPtr::get() {
+ return data_.get();
+}
+URLIndexPrivateData* RefCountedURLIndexPrivateDataPtr::release() {
+ return data_.release();
+}
+void RefCountedURLIndexPrivateDataPtr::reset(URLIndexPrivateData* data) {
+ data_.reset(data);
+}
+
// SearchTermCacheItem ---------------------------------------------------------
URLIndexPrivateData::SearchTermCacheItem::SearchTermCacheItem(
@@ -133,6 +152,10 @@
history_info_map_.clear();
}
+bool URLIndexPrivateData::Empty() const {
+ return history_info_map_.empty();
+}
+
// Cache Updating --------------------------------------------------------------
bool URLIndexPrivateData::IndexRow(const URLRow& row) {
@@ -902,9 +925,17 @@
// Cache Saving ----------------------------------------------------------------
+// static
+void URLIndexPrivateData::WritePrivateDataToCacheFileTask(
+ scoped_ptr<URLIndexPrivateData> private_data,
+ const FilePath& file_path,
+ scoped_refptr<RefCountedBool> succeeded) {
+ DCHECK(private_data.get());
+ DCHECK(!file_path.empty());
+ succeeded->set_value(private_data->SaveToFile(file_path));
+}
+
bool URLIndexPrivateData::SaveToFile(const FilePath& file_path) {
- // TODO(mrossetti): Move File IO to another thread.
- base::ThreadRestrictions::ScopedAllowIO allow_io;
base::TimeTicks beginning_time = base::TimeTicks::Now();
InMemoryURLIndexCacheItem index_cache;
SavePrivateData(&index_cache);
@@ -1022,44 +1053,50 @@
// Cache Restoring -------------------------------------------------------------
-bool URLIndexPrivateData::RestoreFromFile(const FilePath& file_path) {
- // TODO(mrossetti): Figure out how to determine if the cache is up-to-date.
- // That is: ensure that the database has not been modified since the cache
- // was last saved. DB file modification date is inadequate. There are no
- // SQLite table checksums automatically stored.
- Clear(); // Start with a clean slate.
+// static
+void URLIndexPrivateData::RestoreFromFileTask(
+ const FilePath& file_path,
+ scoped_refptr<RefCountedURLIndexPrivateDataPtr> private_data_ptr) {
+ private_data_ptr->reset(URLIndexPrivateData::RestoreFromFile(file_path));
+}
- // FIXME(mrossetti): Move File IO to another thread.
- base::ThreadRestrictions::ScopedAllowIO allow_io;
+// static
+URLIndexPrivateData* URLIndexPrivateData::RestoreFromFile(
+ const FilePath& file_path) {
base::TimeTicks beginning_time = base::TimeTicks::Now();
if (!file_util::PathExists(file_path))
- return false;
+ return NULL;
std::string data;
// If there is no cache file then simply give up. This will cause us to
// attempt to rebuild from the history database.
if (!file_util::ReadFileToString(file_path, &data))
- return false;
+ return NULL;
+ scoped_ptr<URLIndexPrivateData> restored_data(new URLIndexPrivateData);
InMemoryURLIndexCacheItem index_cache;
if (!index_cache.ParseFromArray(data.c_str(), data.size())) {
- LOG(WARNING) << "Failed to parse InMemoryURLIndex cache data read from "
+ LOG(WARNING) << "Failed to parse URLIndexPrivateData cache data read from "
<< file_path.value();
- return false;
+ return restored_data.release();
}
- if (!RestorePrivateData(index_cache)) {
- Clear(); // Back to square one -- must build from scratch.
- return false;
+ if (!restored_data->RestorePrivateData(index_cache)) {
+ restored_data.reset(); // Back to square one -- must build from history DB.
+ return NULL;
}
UMA_HISTOGRAM_TIMES("History.InMemoryURLIndexRestoreCacheTime",
base::TimeTicks::Now() - beginning_time);
UMA_HISTOGRAM_COUNTS("History.InMemoryURLHistoryItems",
- history_id_word_map_.size());
+ restored_data->history_id_word_map_.size());
UMA_HISTOGRAM_COUNTS("History.InMemoryURLCacheSize", data.size());
- UMA_HISTOGRAM_COUNTS_10000("History.InMemoryURLWords", word_map_.size());
- UMA_HISTOGRAM_COUNTS_10000("History.InMemoryURLChars", char_word_map_.size());
- return true;
+ UMA_HISTOGRAM_COUNTS_10000("History.InMemoryURLWords",
+ restored_data->word_map_.size());
+ UMA_HISTOGRAM_COUNTS_10000("History.InMemoryURLChars",
+ restored_data->char_word_map_.size());
+ if (restored_data->Empty())
+ restored_data.reset(); // 'No data' is the same as a failed reload.
+ return restored_data.release();
}
// static

Powered by Google App Engine
This is Rietveld 408576698