diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-12 08:01:44 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-12 08:01:44 +0000 |
commit | a6d0f18778b7f27a3a5cb2feac1039e4a8f4235c (patch) | |
tree | 79bbaf938bf3e7d98f9c8dcbebcd891f3237e4d2 /chrome/browser/visitedlink_master.cc | |
parent | 3bcea86de6bbab9ae23146b2aed08028ae800ecb (diff) | |
download | chromium_src-a6d0f18778b7f27a3a5cb2feac1039e4a8f4235c.zip chromium_src-a6d0f18778b7f27a3a5cb2feac1039e4a8f4235c.tar.gz chromium_src-a6d0f18778b7f27a3a5cb2feac1039e4a8f4235c.tar.bz2 |
Revert "Take 2: Preload the visited link db on the file thread if"
This reverts commit r35991 due to a perf regression to New Tab Cold
on Mac.
TBR=thakis
Review URL: http://codereview.chromium.org/545024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35997 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/visitedlink_master.cc')
-rw-r--r-- | chrome/browser/visitedlink_master.cc | 153 |
1 files changed, 65 insertions, 88 deletions
diff --git a/chrome/browser/visitedlink_master.cc b/chrome/browser/visitedlink_master.cc index 58769dc..c2aa3fe 100644 --- a/chrome/browser/visitedlink_master.cc +++ b/chrome/browser/visitedlink_master.cc @@ -24,6 +24,7 @@ #include "base/rand_util.h" #include "base/stack_container.h" #include "base/string_util.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/history/history.h" #include "chrome/browser/profile.h" @@ -143,24 +144,6 @@ class AsyncCloseHandle : public Task { DISALLOW_COPY_AND_ASSIGN(AsyncCloseHandle); }; -// A helper class for clearing |profile_pointer_| then re-setting it when the -// object goes out of scope. This helps to make sure we don't accidentally -// use the pointer when we're not supposed to. -class ScopedNullProfile { - public: - ScopedNullProfile(Profile** profile) - : profile_(*profile), - profile_pointer_(profile) { - *profile_pointer_ = NULL; - } - ~ScopedNullProfile() { - *profile_pointer_ = profile_; - } - private: - Profile* profile_; - Profile** profile_pointer_; -}; - } // namespace // TableBuilder --------------------------------------------------------------- @@ -265,9 +248,6 @@ void VisitedLinkMaster::InitMembers(Listener* listener, Profile* profile) { suppress_rebuild_ = false; profile_ = profile; - if (profile_) - profile_dir_ = profile_->GetPath(); - #ifndef NDEBUG posted_asynchronous_operation_ = false; #endif @@ -275,74 +255,10 @@ void VisitedLinkMaster::InitMembers(Listener* listener, Profile* profile) { bool VisitedLinkMaster::Init() { if (!InitFromFile()) - return InitFromScratch(); - return true; -} - -bool VisitedLinkMaster::InitFromFile() { - // We allow running this method from background threads, so be careful not to - // access profile_ (which may already be deleted) from this method. - ScopedNullProfile scoped(&profile_); - DCHECK(file_ == NULL); - DCHECK(profile_ == NULL); - - FilePath filename; - GetDatabaseFileName(&filename); - ScopedFILE file_closer(OpenFile(filename, "rb+")); - if (!file_closer.get()) - return false; - - int32 num_entries, used_count; - if (!ReadFileHeader(file_closer.get(), &num_entries, &used_count, salt_)) - return false; // Header isn't valid. - - // Allocate and read the table. - if (!CreateURLTable(num_entries, false)) - return false; - if (!ReadFromFile(file_closer.get(), kFileHeaderSize, - hash_table_, num_entries * sizeof(Fingerprint))) { - FreeURLTable(); - return false; - } - used_items_ = used_count; - -#ifndef NDEBUG - DebugValidate(); -#endif - - file_ = file_closer.release(); + return InitFromScratch(suppress_rebuild_); return true; } -bool VisitedLinkMaster::InitFromScratch() { - int32 table_size = kDefaultTableSize; - if (table_size_override_) - table_size = table_size_override_; - - // The salt must be generated before the table so that it can be copied to - // the shared memory. - GenerateSalt(salt_); - if (!CreateURLTable(table_size, true)) - return false; - -#ifndef NDEBUG - DebugValidate(); -#endif - - if (suppress_rebuild_) { - // When we disallow rebuilds (normally just unit tests), just use the - // current empty table. - return WriteFullTable(); - } - - // This will build the table from history. On the first run, history will - // be empty, so this will be correct. This will also write the new table - // to disk. We don't want to save explicitly here, since the rebuild may - // not complete, leaving us with an empty but valid visited link database. - // In the future, we won't know we need to try rebuilding again. - return RebuildTableFromHistory(); -} - VisitedLinkMaster::Hash VisitedLinkMaster::TryToAddURL(const GURL& url) { // Extra check that we are not off the record. This should not happen. if (profile_ && profile_->IsOffTheRecord()) { @@ -621,6 +537,66 @@ bool VisitedLinkMaster::WriteFullTable() { return true; } +bool VisitedLinkMaster::InitFromFile() { + DCHECK(file_ == NULL); + + FilePath filename; + GetDatabaseFileName(&filename); + ScopedFILE file_closer(OpenFile(filename, "rb+")); + if (!file_closer.get()) + return false; + + int32 num_entries, used_count; + if (!ReadFileHeader(file_closer.get(), &num_entries, &used_count, salt_)) + return false; // Header isn't valid. + + // Allocate and read the table. + if (!CreateURLTable(num_entries, false)) + return false; + if (!ReadFromFile(file_closer.get(), kFileHeaderSize, + hash_table_, num_entries * sizeof(Fingerprint))) { + FreeURLTable(); + return false; + } + used_items_ = used_count; + +#ifndef NDEBUG + DebugValidate(); +#endif + + file_ = file_closer.release(); + return true; +} + +bool VisitedLinkMaster::InitFromScratch(bool suppress_rebuild) { + int32 table_size = kDefaultTableSize; + if (table_size_override_) + table_size = table_size_override_; + + // The salt must be generated before the table so that it can be copied to + // the shared memory. + GenerateSalt(salt_); + if (!CreateURLTable(table_size, true)) + return false; + +#ifndef NDEBUG + DebugValidate(); +#endif + + if (suppress_rebuild) { + // When we disallow rebuilds (normally just unit tests), just use the + // current empty table. + return WriteFullTable(); + } + + // This will build the table from history. On the first run, history will + // be empty, so this will be correct. This will also write the new table + // to disk. We don't want to save explicitly here, since the rebuild may + // not complete, leaving us with an empty but valid visited link database. + // In the future, we won't know we need to try rebuilding again. + return RebuildTableFromHistory(); +} + bool VisitedLinkMaster::ReadFileHeader(FILE* file, int32* num_entries, int32* used_count, @@ -678,10 +654,11 @@ bool VisitedLinkMaster::GetDatabaseFileName(FilePath* filename) { return true; } - if (profile_dir_.empty()) + if (!profile_ || profile_->GetPath().empty()) return false; - *filename = profile_dir_.Append(FILE_PATH_LITERAL("Visited Links")); + FilePath profile_dir = profile_->GetPath(); + *filename = profile_dir.Append(FILE_PATH_LITERAL("Visited Links")); return true; } |