OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/metrics/serialization/serialization_utils.h" | 5 #include "components/metrics/serialization/serialization_utils.h" |
6 | 6 |
7 #include <sys/file.h> | 7 #include <sys/file.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 return true; | 84 return true; |
85 } | 85 } |
86 | 86 |
87 } // namespace | 87 } // namespace |
88 | 88 |
89 scoped_ptr<MetricSample> SerializationUtils::ParseSample( | 89 scoped_ptr<MetricSample> SerializationUtils::ParseSample( |
90 const std::string& sample) { | 90 const std::string& sample) { |
91 if (sample.empty()) | 91 if (sample.empty()) |
92 return scoped_ptr<MetricSample>(); | 92 return scoped_ptr<MetricSample>(); |
93 | 93 |
94 std::vector<std::string> parts; | 94 std::vector<std::string> parts = base::SplitString( |
95 base::SplitString(sample, '\0', &parts); | 95 sample, std::string(1, '\0'), |
| 96 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
96 // We should have two null terminated strings so split should produce | 97 // We should have two null terminated strings so split should produce |
97 // three chunks. | 98 // three chunks. |
98 if (parts.size() != 3) { | 99 if (parts.size() != 3) { |
99 DLOG(ERROR) << "splitting message on \\0 produced " << parts.size() | 100 DLOG(ERROR) << "splitting message on \\0 produced " << parts.size() |
100 << " parts (expected 3)"; | 101 << " parts (expected 3)"; |
101 return scoped_ptr<MetricSample>(); | 102 return scoped_ptr<MetricSample>(); |
102 } | 103 } |
103 const std::string& name = parts[0]; | 104 const std::string& name = parts[0]; |
104 const std::string& value = parts[1]; | 105 const std::string& value = parts[1]; |
105 | 106 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 if (!base::WriteFileDescriptor( | 213 if (!base::WriteFileDescriptor( |
213 file_descriptor.get(), msg.c_str(), msg.size())) { | 214 file_descriptor.get(), msg.c_str(), msg.size())) { |
214 DPLOG(ERROR) << "error writing message: " << filename; | 215 DPLOG(ERROR) << "error writing message: " << filename; |
215 return false; | 216 return false; |
216 } | 217 } |
217 | 218 |
218 return true; | 219 return true; |
219 } | 220 } |
220 | 221 |
221 } // namespace metrics | 222 } // namespace metrics |
OLD | NEW |