| Index: chrome/browser/history/url_index_private_data.cc
|
| ===================================================================
|
| --- chrome/browser/history/url_index_private_data.cc (revision 125078)
|
| +++ 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"
|
|
|
| @@ -133,6 +137,10 @@
|
| history_info_map_.clear();
|
| }
|
|
|
| +bool URLIndexPrivateData::Empty() const {
|
| + return history_info_map_.empty();
|
| +}
|
| +
|
| // Cache Updating --------------------------------------------------------------
|
|
|
| bool URLIndexPrivateData::IndexRow(const URLRow& row) {
|
| @@ -902,9 +910,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 +1038,49 @@
|
|
|
| // 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,
|
| + URLIndexPrivateData* data) {
|
| + data = 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
|
|
|