| 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 <errno.h> | 7 #include <errno.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <sys/file.h> | 9 #include <sys/file.h> |
| 10 | 10 |
| 11 #include <memory> | |
| 12 #include <string> | |
| 13 #include <utility> | 11 #include <utility> |
| 14 #include <vector> | |
| 15 | 12 |
| 16 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 17 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 18 #include "base/files/scoped_file.h" | 15 #include "base/files/scoped_file.h" |
| 19 #include "base/logging.h" | 16 #include "base/logging.h" |
| 20 #include "base/memory/scoped_vector.h" | |
| 21 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 22 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 23 #include "components/metrics/serialization/metric_sample.h" | 19 #include "components/metrics/serialization/metric_sample.h" |
| 24 | 20 |
| 25 #define READ_WRITE_ALL_FILE_FLAGS \ | 21 #define READ_WRITE_ALL_FILE_FLAGS \ |
| 26 (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) | 22 (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) |
| 27 | 23 |
| 28 namespace metrics { | 24 namespace metrics { |
| 29 namespace { | 25 namespace { |
| 30 | 26 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } else if (base::LowerCaseEqualsASCII(name, "useraction")) { | 114 } else if (base::LowerCaseEqualsASCII(name, "useraction")) { |
| 119 return MetricSample::UserActionSample(value); | 115 return MetricSample::UserActionSample(value); |
| 120 } else { | 116 } else { |
| 121 DLOG(ERROR) << "invalid event type: " << name << ", value: " << value; | 117 DLOG(ERROR) << "invalid event type: " << name << ", value: " << value; |
| 122 } | 118 } |
| 123 return std::unique_ptr<MetricSample>(); | 119 return std::unique_ptr<MetricSample>(); |
| 124 } | 120 } |
| 125 | 121 |
| 126 void SerializationUtils::ReadAndTruncateMetricsFromFile( | 122 void SerializationUtils::ReadAndTruncateMetricsFromFile( |
| 127 const std::string& filename, | 123 const std::string& filename, |
| 128 ScopedVector<MetricSample>* metrics) { | 124 std::vector<std::unique_ptr<MetricSample>>* metrics) { |
| 129 struct stat stat_buf; | 125 struct stat stat_buf; |
| 130 int result; | 126 int result; |
| 131 | 127 |
| 132 result = stat(filename.c_str(), &stat_buf); | 128 result = stat(filename.c_str(), &stat_buf); |
| 133 if (result < 0) { | 129 if (result < 0) { |
| 134 if (errno != ENOENT) | 130 if (errno != ENOENT) |
| 135 DPLOG(ERROR) << "bad metrics file stat: " << filename; | 131 DPLOG(ERROR) << "bad metrics file stat: " << filename; |
| 136 | 132 |
| 137 // Nothing to collect---try later. | 133 // Nothing to collect---try later. |
| 138 return; | 134 return; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 if (!base::WriteFileDescriptor( | 212 if (!base::WriteFileDescriptor( |
| 217 file_descriptor.get(), msg.c_str(), msg.size())) { | 213 file_descriptor.get(), msg.c_str(), msg.size())) { |
| 218 DPLOG(ERROR) << "error writing message: " << filename; | 214 DPLOG(ERROR) << "error writing message: " << filename; |
| 219 return false; | 215 return false; |
| 220 } | 216 } |
| 221 | 217 |
| 222 return true; | 218 return true; |
| 223 } | 219 } |
| 224 | 220 |
| 225 } // namespace metrics | 221 } // namespace metrics |
| OLD | NEW |