| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // This processes all messages in the log. When all messages are | 145 // This processes all messages in the log. When all messages are |
| 146 // read and processed, or an error occurs, truncate the file to zero size. | 146 // read and processed, or an error occurs, truncate the file to zero size. |
| 147 for (;;) { | 147 for (;;) { |
| 148 std::string message; | 148 std::string message; |
| 149 | 149 |
| 150 if (!ReadMessage(fd.get(), &message)) | 150 if (!ReadMessage(fd.get(), &message)) |
| 151 break; | 151 break; |
| 152 | 152 |
| 153 scoped_ptr<MetricSample> sample = ParseSample(message); | 153 scoped_ptr<MetricSample> sample = ParseSample(message); |
| 154 if (sample) | 154 if (sample) |
| 155 metrics->push_back(sample.release()); | 155 metrics->push_back(sample.Pass()); |
| 156 } | 156 } |
| 157 | 157 |
| 158 result = ftruncate(fd.get(), 0); | 158 result = ftruncate(fd.get(), 0); |
| 159 if (result < 0) | 159 if (result < 0) |
| 160 DPLOG(ERROR) << "truncate metrics log: " << filename; | 160 DPLOG(ERROR) << "truncate metrics log: " << filename; |
| 161 | 161 |
| 162 result = flock(fd.get(), LOCK_UN); | 162 result = flock(fd.get(), LOCK_UN); |
| 163 if (result < 0) | 163 if (result < 0) |
| 164 DPLOG(ERROR) << "unlock metrics log: " << filename; | 164 DPLOG(ERROR) << "unlock metrics log: " << filename; |
| 165 } | 165 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 if (!base::WriteFileDescriptor( | 206 if (!base::WriteFileDescriptor( |
| 207 file_descriptor.get(), msg.c_str(), msg.size())) { | 207 file_descriptor.get(), msg.c_str(), msg.size())) { |
| 208 DPLOG(ERROR) << "error writing message: " << filename; | 208 DPLOG(ERROR) << "error writing message: " << filename; |
| 209 return false; | 209 return false; |
| 210 } | 210 } |
| 211 | 211 |
| 212 return true; | 212 return true; |
| 213 } | 213 } |
| 214 | 214 |
| 215 } // namespace metrics | 215 } // namespace metrics |
| OLD | NEW |