summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-11 22:38:48 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-11 22:38:48 +0000
commit1e5c78c698039ab93e989f8b1e78c00e7ae5206c (patch)
tree5348cc0d6108686b42a39781f8eb2d507312dd77
parent018cbb25b18f517870d08706cc0b367a6ae04a82 (diff)
downloadchromium_src-1e5c78c698039ab93e989f8b1e78c00e7ae5206c.zip
chromium_src-1e5c78c698039ab93e989f8b1e78c00e7ae5206c.tar.gz
chromium_src-1e5c78c698039ab93e989f8b1e78c00e7ae5206c.tar.bz2
Instrument safe-browsing to track file-format conversion.
Also track corruption separately for old and new file formats. BUG=58552 TEST=none Review URL: http://codereview.chromium.org/3632004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62198 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_store_file.cc31
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_store_file.h37
2 files changed, 64 insertions, 4 deletions
diff --git a/chrome/browser/safe_browsing/safe_browsing_store_file.cc b/chrome/browser/safe_browsing/safe_browsing_store_file.cc
index 7402d9a..a30bf51 100644
--- a/chrome/browser/safe_browsing/safe_browsing_store_file.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_store_file.cc
@@ -171,6 +171,11 @@ bool FileHeaderSanityCheck(const FilePath& filename,
} // namespace
+// static
+void SafeBrowsingStoreFile::RecordFormatEvent(FormatEventType event_type) {
+ UMA_HISTOGRAM_ENUMERATION("SB2.FormatEvent", event_type, FORMAT_EVENT_MAX);
+}
+
SafeBrowsingStoreFile::SafeBrowsingStoreFile()
: chunks_written_(0),
file_(NULL),
@@ -251,6 +256,10 @@ bool SafeBrowsingStoreFile::WriteSubHash(int32 chunk_id, int32 add_chunk_id,
}
bool SafeBrowsingStoreFile::OnCorruptDatabase() {
+ if (!corruption_seen_)
+ RecordFormatEvent(FORMAT_EVENT_FILE_CORRUPT);
+ corruption_seen_ = true;
+
if (corruption_callback_.get())
corruption_callback_->Run();
@@ -258,6 +267,15 @@ bool SafeBrowsingStoreFile::OnCorruptDatabase() {
return false;
}
+void SafeBrowsingStoreFile::HandleCorruptDatabase() {
+ if (!corruption_seen_)
+ RecordFormatEvent(FORMAT_EVENT_SQLITE_CORRUPT);
+ corruption_seen_ = true;
+
+ if (corruption_callback_.get())
+ corruption_callback_->Run();
+}
+
bool SafeBrowsingStoreFile::Close() {
ClearUpdateBuffers();
@@ -282,6 +300,8 @@ bool SafeBrowsingStoreFile::BeginUpdate() {
DCHECK(sub_hashes_.empty());
DCHECK_EQ(chunks_written_, 0);
+ corruption_seen_ = false;
+
const FilePath new_filename = TemporaryFileForFilename(filename_);
file_util::ScopedFILE new_file(file_util::OpenFile(new_filename, "wb+"));
if (new_file.get() == NULL)
@@ -304,6 +324,12 @@ bool SafeBrowsingStoreFile::BeginUpdate() {
return OnCorruptDatabase();
if (header.magic != kFileMagic || header.version != kFileVersion) {
+ if (!strcmp(reinterpret_cast<char*>(&header.magic), "SQLite format 3")) {
+ RecordFormatEvent(FORMAT_EVENT_FOUND_SQLITE);
+ } else {
+ RecordFormatEvent(FORMAT_EVENT_FOUND_UNKNOWN);
+ }
+
// Something about having the file open causes a problem with
// SQLite opening it. Perhaps PRAGMA locking_mode = EXCLUSIVE?
file.reset();
@@ -571,8 +597,11 @@ bool SafeBrowsingStoreFile::DoUpdate(
if (old_store_.get()) {
const bool deleted = old_store_->Delete();
old_store_.reset();
- if (!deleted)
+ if (!deleted) {
+ RecordFormatEvent(FORMAT_EVENT_SQLITE_DELETE_FAILED);
return false;
+ }
+ RecordFormatEvent(FORMAT_EVENT_SQLITE_DELETED);
} else {
if (!file_util::Delete(filename_, false) &&
file_util::PathExists(filename_))
diff --git a/chrome/browser/safe_browsing/safe_browsing_store_file.h b/chrome/browser/safe_browsing/safe_browsing_store_file.h
index 3530e60..ec612e6 100644
--- a/chrome/browser/safe_browsing/safe_browsing_store_file.h
+++ b/chrome/browser/safe_browsing/safe_browsing_store_file.h
@@ -160,6 +160,34 @@ class SafeBrowsingStoreFile : public SafeBrowsingStore {
}
private:
+ // Enumerate different format-change events for histogramming
+ // purposes. DO NOT CHANGE THE ORDERING OF THESE VALUES.
+ // TODO(shess): Remove this once the format change is complete.
+ enum FormatEventType {
+ // Corruption detected, broken down by file format.
+ FORMAT_EVENT_FILE_CORRUPT,
+ FORMAT_EVENT_SQLITE_CORRUPT,
+
+ // The type of format found in the file. The expected case (new
+ // file format) is intentionally not covered.
+ FORMAT_EVENT_FOUND_SQLITE,
+ FORMAT_EVENT_FOUND_UNKNOWN,
+
+ // The number of SQLite-format files deleted should be the same as
+ // FORMAT_EVENT_FOUND_SQLITE. It can differ if the delete fails,
+ // or if a failure prevents the update from succeeding.
+ FORMAT_EVENT_SQLITE_DELETED,
+ FORMAT_EVENT_SQLITE_DELETE_FAILED,
+
+ // Histogram space is determined by the max. If this is exceeded,
+ // simply start a new histogram.
+ FORMAT_EVENT_MAX = 50
+ };
+
+ // Helper to record an event related to format conversion from
+ // SQLite to file.
+ static void RecordFormatEvent(FormatEventType event_type);
+
// Close all files and clear all buffers.
bool Close();
@@ -169,9 +197,7 @@ class SafeBrowsingStoreFile : public SafeBrowsingStore {
// Helper for creating a corruption callback for |old_store_|.
// TODO(shess): Remove after migration.
- void HandleCorruptDatabase() {
- OnCorruptDatabase();
- }
+ void HandleCorruptDatabase();
// Clear temporary buffers used to accumulate chunk data.
bool ClearChunkBuffers() {
@@ -235,6 +261,11 @@ class SafeBrowsingStoreFile : public SafeBrowsingStore {
scoped_ptr<Callback0::Type> corruption_callback_;
+ // Tracks whether corruption has already been seen in the current
+ // update, so that only one instance is recorded in the stats.
+ // TODO(shess): Remove with format-migration support.
+ bool corruption_seen_;
+
DISALLOW_COPY_AND_ASSIGN(SafeBrowsingStoreFile);
};