Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2933)

Unified Diff: base/prefs/json_pref_store.cc

Issue 891663003: Log pref file size histogram on read rather than on write. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/prefs/json_pref_store.cc
diff --git a/base/prefs/json_pref_store.cc b/base/prefs/json_pref_store.cc
index e35ed295d699b68ffe50d707d1864b8dcc046125..6eb3188e82f4afc3f2239f9389b50d7d0110e78b 100644
--- a/base/prefs/json_pref_store.cc
+++ b/base/prefs/json_pref_store.cc
@@ -8,12 +8,10 @@
#include "base/bind.h"
#include "base/callback.h"
-#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/json/json_file_value_serializer.h"
#include "base/json/json_string_value_serializer.h"
#include "base/memory/ref_counted.h"
-#include "base/metrics/histogram.h"
#include "base/prefs/pref_filter.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/string_util.h"
@@ -99,11 +97,15 @@ scoped_ptr<JsonPrefStore::ReadResult> ReadPrefsFromDisk(
base::Move(alternate_path, path);
}
+ std::string histogram_suffix;
+ base::ReplaceChars(path.BaseName().MaybeAsASCII(), " ", "_",
+ &histogram_suffix);
+
int error_code;
std::string error_msg;
scoped_ptr<JsonPrefStore::ReadResult> read_result(
new JsonPrefStore::ReadResult);
- JSONFileValueSerializer serializer(path);
+ JSONFileValueSerializer serializer(path, histogram_suffix);
read_result->value.reset(serializer.Deserialize(&error_code, &error_msg));
read_result->error =
HandleReadErrors(read_result->value.get(), path, error_code, error_msg);
@@ -379,27 +381,7 @@ bool JsonPrefStore::SerializeData(std::string* output) {
JSONStringValueSerializer serializer(output);
serializer.set_pretty_print(true);
- bool result = serializer.Serialize(*prefs_);
-
- if (result) {
- std::string spaceless_basename;
- base::ReplaceChars(path_.BaseName().MaybeAsASCII(), " ", "_",
- &spaceless_basename);
-
- // The histogram below is an expansion of the UMA_HISTOGRAM_COUNTS_10000
- // macro adapted to allow for a dynamically suffixed histogram name.
- // Note: The factory creates and owns the histogram.
- base::HistogramBase* histogram =
- base::LinearHistogram::FactoryGet(
- "Settings.JsonDataSizeKilobytes." + spaceless_basename,
- 1,
- 10000,
- 50,
- base::HistogramBase::kUmaTargetedHistogramFlag);
- histogram->Add(static_cast<int>(output->size()) / 1024);
- }
-
- return result;
+ return serializer.Serialize(*prefs_);
}
void JsonPrefStore::FinalizeFileRead(bool initialization_successful,

Powered by Google App Engine
This is Rietveld 408576698