diff options
author | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-15 00:36:48 +0000 |
---|---|---|
committer | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-15 00:36:48 +0000 |
commit | ff3c69a3b1bca4a844d7d7c634725d74835d7d5b (patch) | |
tree | cd4452c19866f0acf6639b3969fd4d1d65cbafeb | |
parent | 4b223286325c82f04bc02a5e758a410c992b6d98 (diff) | |
download | chromium_src-ff3c69a3b1bca4a844d7d7c634725d74835d7d5b.zip chromium_src-ff3c69a3b1bca4a844d7d7c634725d74835d7d5b.tar.gz chromium_src-ff3c69a3b1bca4a844d7d7c634725d74835d7d5b.tar.bz2 |
Produce histogram in important_file_writer code
I'm trying to ensure that prefs are being written
consistently, so this will help monitor file access
such as what is used in pref writing.
I also cleaned up the use of a histogram in pref-services.
r=rtenneti
Review URL: http://codereview.chromium.org/7890038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101202 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/prefs/pref_service.cc | 3 | ||||
-rw-r--r-- | chrome/common/important_file_writer.cc | 28 | ||||
-rw-r--r-- | chrome/common/persistent_pref_store.h | 3 |
3 files changed, 24 insertions, 10 deletions
diff --git a/chrome/browser/prefs/pref_service.cc b/chrome/browser/prefs/pref_service.cc index 6cb9836..1eebf82 100644 --- a/chrome/browser/prefs/pref_service.cc +++ b/chrome/browser/prefs/pref_service.cc @@ -102,7 +102,8 @@ class ReadErrorHandler : public PersistentPrefStore::ReadErrorDelegate { BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableFunction(&NotifyReadError, message_id)); } - UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, 20); + UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, + PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); } } }; diff --git a/chrome/common/important_file_writer.cc b/chrome/common/important_file_writer.cc index 94e7fb5..a1abd8d 100644 --- a/chrome/common/important_file_writer.cc +++ b/chrome/common/important_file_writer.cc @@ -12,6 +12,7 @@ #include "base/file_util.h" #include "base/logging.h" #include "base/message_loop_proxy.h" +#include "base/metrics/histogram.h" #include "base/string_number_conversions.h" #include "base/task.h" #include "base/threading/thread.h" @@ -37,7 +38,7 @@ class WriteToDiskTask : public Task { // is securely created. FilePath tmp_file_path; if (!file_util::CreateTemporaryFileInDir(path_.DirName(), &tmp_file_path)) { - LogFailure("could not create temporary file"); + LogFailure(FAILED_CREATING, "could not create temporary file"); return; } @@ -45,7 +46,7 @@ class WriteToDiskTask : public Task { base::PlatformFile tmp_file = base::CreatePlatformFile(tmp_file_path, flags, NULL, NULL); if (tmp_file == base::kInvalidPlatformFileValue) { - LogFailure("could not open temporary file"); + LogFailure(FAILED_OPENING, "could not open temporary file"); return; } @@ -55,29 +56,40 @@ class WriteToDiskTask : public Task { base::FlushPlatformFile(tmp_file); // Ignore return value. if (!base::ClosePlatformFile(tmp_file)) { - LogFailure("failed to close temporary file"); + LogFailure(FAILED_CLOSING, "failed to close temporary file"); file_util::Delete(tmp_file_path, false); return; } if (bytes_written < static_cast<int>(data_.length())) { - LogFailure("error writing, bytes_written=" + + LogFailure(FAILED_WRITING, "error writing, bytes_written=" + base::IntToString(bytes_written)); file_util::Delete(tmp_file_path, false); return; } if (!file_util::ReplaceFile(tmp_file_path, path_)) { - LogFailure("could not rename temporary file"); + LogFailure(FAILED_RENAMING, "could not rename temporary file"); file_util::Delete(tmp_file_path, false); return; } } private: - void LogFailure(const std::string& message) { - PLOG(WARNING) << "failed to write " << path_.value() - << ": " << message; + enum TempFileFailure { + FAILED_CREATING, + FAILED_OPENING, + FAILED_CLOSING, + FAILED_WRITING, + FAILED_RENAMING, + TEMP_FILE_FAILURE_MAX + }; + + void LogFailure(TempFileFailure failure_code, const std::string& message) { + UMA_HISTOGRAM_ENUMERATION("ImportantFile.TempFileFailures", failure_code, + TEMP_FILE_FAILURE_MAX); + PLOG(WARNING) << "temp file failure: " << path_.value() + << " : " << message; } const FilePath path_; diff --git a/chrome/common/persistent_pref_store.h b/chrome/common/persistent_pref_store.h index b209716..b7aaf8e 100644 --- a/chrome/common/persistent_pref_store.h +++ b/chrome/common/persistent_pref_store.h @@ -31,7 +31,8 @@ class PersistentPrefStore : public PrefStore { PREF_READ_ERROR_NO_FILE, PREF_READ_ERROR_JSON_REPEAT, PREF_READ_ERROR_OTHER, - PREF_READ_ERROR_FILE_NOT_SPECIFIED + PREF_READ_ERROR_FILE_NOT_SPECIFIED, + PREF_READ_ERROR_MAX_ENUM }; class ReadErrorDelegate { |