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

Side by Side Diff: base/json/json_file_value_serializer.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, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/json/json_file_value_serializer.h" 5 #include "base/json/json_file_value_serializer.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/json/json_string_value_serializer.h" 8 #include "base/json/json_string_value_serializer.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram.h"
10 11
11 using base::FilePath; 12 using base::FilePath;
12 13
13 const char JSONFileValueSerializer::kAccessDenied[] = "Access denied."; 14 const char JSONFileValueSerializer::kAccessDenied[] = "Access denied.";
14 const char JSONFileValueSerializer::kCannotReadFile[] = "Can't read file."; 15 const char JSONFileValueSerializer::kCannotReadFile[] = "Can't read file.";
15 const char JSONFileValueSerializer::kFileLocked[] = "File locked."; 16 const char JSONFileValueSerializer::kFileLocked[] = "File locked.";
16 const char JSONFileValueSerializer::kNoSuchFile[] = "File doesn't exist."; 17 const char JSONFileValueSerializer::kNoSuchFile[] = "File doesn't exist.";
17 18
18 bool JSONFileValueSerializer::Serialize(const base::Value& root) { 19 bool JSONFileValueSerializer::Serialize(const base::Value& root) {
19 return SerializeInternal(root, false); 20 return SerializeInternal(root, false);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 return JSON_FILE_LOCKED; 53 return JSON_FILE_LOCKED;
53 } else if (error == ERROR_ACCESS_DENIED) { 54 } else if (error == ERROR_ACCESS_DENIED) {
54 return JSON_ACCESS_DENIED; 55 return JSON_ACCESS_DENIED;
55 } 56 }
56 #endif 57 #endif
57 if (!base::PathExists(json_file_path_)) 58 if (!base::PathExists(json_file_path_))
58 return JSON_NO_SUCH_FILE; 59 return JSON_NO_SUCH_FILE;
59 else 60 else
60 return JSON_CANNOT_READ_FILE; 61 return JSON_CANNOT_READ_FILE;
61 } 62 }
63
64 if (!histogram_suffix_.empty()) {
65 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS
66 // macro adapted to allow for a dynamically suffixed histogram name.
67 // Note: The factory creates and owns the histogram.
68 base::HistogramBase* histogram =
69 base::Histogram::FactoryGet(
70 "Settings.JsonDataSizeKilobytes." + histogram_suffix_,
Alexei Svitkine (slow) 2015/01/30 13:49:03 Should be JsonDataReadSizeKilobytes.
gab 2015/01/30 17:33:37 Oops, done.
71 1,
72 10000,
73 50,
74 base::HistogramBase::kUmaTargetedHistogramFlag);
75 histogram->Add(static_cast<int>(json_string->size()) / 1024);
76 }
77
62 return JSON_NO_ERROR; 78 return JSON_NO_ERROR;
63 } 79 }
64 80
65 const char* JSONFileValueSerializer::GetErrorMessageForCode(int error_code) { 81 const char* JSONFileValueSerializer::GetErrorMessageForCode(int error_code) {
66 switch (error_code) { 82 switch (error_code) {
67 case JSON_NO_ERROR: 83 case JSON_NO_ERROR:
68 return ""; 84 return "";
69 case JSON_ACCESS_DENIED: 85 case JSON_ACCESS_DENIED:
70 return kAccessDenied; 86 return kAccessDenied;
71 case JSON_CANNOT_READ_FILE: 87 case JSON_CANNOT_READ_FILE:
(...skipping 17 matching lines...) Expand all
89 *error_code = error; 105 *error_code = error;
90 if (error_str) 106 if (error_str)
91 *error_str = GetErrorMessageForCode(error); 107 *error_str = GetErrorMessageForCode(error);
92 return NULL; 108 return NULL;
93 } 109 }
94 110
95 JSONStringValueSerializer serializer(json_string); 111 JSONStringValueSerializer serializer(json_string);
96 serializer.set_allow_trailing_comma(allow_trailing_comma_); 112 serializer.set_allow_trailing_comma(allow_trailing_comma_);
97 return serializer.Deserialize(error_code, error_str); 113 return serializer.Deserialize(error_code, error_str);
98 } 114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698