Index: chrome/browser/visitedlink_master.cc |
diff --git a/chrome/browser/visitedlink_master.cc b/chrome/browser/visitedlink_master.cc |
index c2aa3fe183bf7c75e1bfde5f2259ee84296c778b..299f220b8a6467b1ffd4d357874ad7daa7a69c94 100644 |
--- a/chrome/browser/visitedlink_master.cc |
+++ b/chrome/browser/visitedlink_master.cc |
@@ -24,7 +24,6 @@ |
#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" |
@@ -255,10 +254,70 @@ void VisitedLinkMaster::InitMembers(Listener* listener, Profile* profile) { |
bool VisitedLinkMaster::Init() { |
if (!InitFromFile()) |
- return InitFromScratch(suppress_rebuild_); |
+ return InitFromScratch(); |
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() { |
+ 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()) { |
@@ -537,66 +596,6 @@ 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, |