Index: base/json/json_file_value_serializer.cc |
diff --git a/base/json/json_file_value_serializer.cc b/base/json/json_file_value_serializer.cc |
index d60f800cfcfbb9235fc62fc050feb98c87a54740..c12fcd689e035d41d25040b2abfa45195705e694 100644 |
--- a/base/json/json_file_value_serializer.cc |
+++ b/base/json/json_file_value_serializer.cc |
@@ -7,6 +7,7 @@ |
#include "base/files/file_util.h" |
#include "base/json/json_string_value_serializer.h" |
#include "base/logging.h" |
+#include "base/metrics/histogram.h" |
using base::FilePath; |
@@ -15,6 +16,19 @@ const char JSONFileValueSerializer::kCannotReadFile[] = "Can't read file."; |
const char JSONFileValueSerializer::kFileLocked[] = "File locked."; |
const char JSONFileValueSerializer::kNoSuchFile[] = "File doesn't exist."; |
+JSONFileValueSerializer::JSONFileValueSerializer( |
+ const base::FilePath& json_file_path, |
+ const std::string& histogram_suffix) |
+ : json_file_path_(json_file_path), |
+ allow_trailing_comma_(false), |
+ histogram_suffix_(histogram_suffix) {} |
+ |
+JSONFileValueSerializer::JSONFileValueSerializer( |
+ const base::FilePath& json_file_path) |
+ : JSONFileValueSerializer(json_file_path, std::string()) {} |
+ |
+JSONFileValueSerializer::~JSONFileValueSerializer() {} |
+ |
bool JSONFileValueSerializer::Serialize(const base::Value& root) { |
return SerializeInternal(root, false); |
} |
@@ -59,6 +73,17 @@ int JSONFileValueSerializer::ReadFileToString(std::string* json_string) { |
else |
return JSON_CANNOT_READ_FILE; |
} |
+ |
+ if (!histogram_suffix_.empty()) { |
+ // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS |
+ // macro adapted to allow for a dynamically suffixed histogram name. |
+ // Note: The factory creates and owns the histogram. |
+ base::HistogramBase* histogram = base::Histogram::FactoryGet( |
+ "Settings.JsonDataReadSizeKilobytes." + histogram_suffix_, 1, 10000, 50, |
+ base::HistogramBase::kUmaTargetedHistogramFlag); |
+ histogram->Add(static_cast<int>(json_string->size()) / 1024); |
+ } |
+ |
return JSON_NO_ERROR; |
} |