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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 189 |
190 std::string msg = sample.ToString(); | 190 std::string msg = sample.ToString(); |
191 int32 size = msg.length() + sizeof(int32); | 191 int32 size = msg.length() + sizeof(int32); |
192 if (size > kMessageMaxLength) { | 192 if (size > kMessageMaxLength) { |
193 DLOG(ERROR) << "cannot write message: too long"; | 193 DLOG(ERROR) << "cannot write message: too long"; |
194 return false; | 194 return false; |
195 } | 195 } |
196 | 196 |
197 // The file containing the metrics samples will only be read by programs on | 197 // The file containing the metrics samples will only be read by programs on |
198 // the same device so we do not check endianness. | 198 // the same device so we do not check endianness. |
199 if (base::WriteFileDescriptor(file_descriptor.get(), | 199 if (!base::WriteFileDescriptor(file_descriptor.get(), |
200 reinterpret_cast<char*>(&size), | 200 reinterpret_cast<char*>(&size), |
201 sizeof(size)) != sizeof(size)) { | 201 sizeof(size))) { |
202 DLOG(ERROR) << "error writing message length " << errno; | 202 DPLOG(ERROR) << "error writing message length"; |
203 return false; | 203 return false; |
204 } | 204 } |
205 | 205 |
206 if (base::WriteFileDescriptor( | 206 if (!base::WriteFileDescriptor( |
207 file_descriptor.get(), msg.c_str(), msg.length()) != | 207 file_descriptor.get(), msg.c_str(), msg.size())) { |
208 static_cast<int>(msg.length())) { | 208 DPLOG(ERROR) << "error writing message"; |
209 DLOG(ERROR) << "error writing message" << errno; | |
210 return false; | 209 return false; |
211 } | 210 } |
212 | 211 |
213 return true; | 212 return true; |
214 } | 213 } |
215 | 214 |
216 } // namespace metrics | 215 } // namespace metrics |
OLD | NEW |