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

Side by Side Diff: components/metrics/serialization/serialization_utils.cc

Issue 1548113002: Switch to standard integer types in components/, part 2 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gn Created 4 years, 12 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 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 <sys/file.h> 9 #include <sys/file.h>
9 10
10 #include <string> 11 #include <string>
11 #include <vector> 12 #include <vector>
12 13
13 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
15 #include "base/files/scoped_file.h" 16 #include "base/files/scoped_file.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 fchmod(file_descriptor.get(), READ_WRITE_ALL_FILE_FLAGS); 190 fchmod(file_descriptor.get(), READ_WRITE_ALL_FILE_FLAGS);
190 // Grab a lock to avoid chrome truncating the file 191 // Grab a lock to avoid chrome truncating the file
191 // underneath us. Keep the file locked as briefly as possible. 192 // underneath us. Keep the file locked as briefly as possible.
192 // Freeing file_descriptor will close the file and and remove the lock. 193 // Freeing file_descriptor will close the file and and remove the lock.
193 if (HANDLE_EINTR(flock(file_descriptor.get(), LOCK_EX)) < 0) { 194 if (HANDLE_EINTR(flock(file_descriptor.get(), LOCK_EX)) < 0) {
194 DPLOG(ERROR) << "error locking: " << filename; 195 DPLOG(ERROR) << "error locking: " << filename;
195 return false; 196 return false;
196 } 197 }
197 198
198 std::string msg = sample.ToString(); 199 std::string msg = sample.ToString();
199 int32 size = msg.length() + sizeof(int32); 200 int32_t size = msg.length() + sizeof(int32_t);
200 if (size > kMessageMaxLength) { 201 if (size > kMessageMaxLength) {
201 DPLOG(ERROR) << "cannot write message: too long: " << filename; 202 DPLOG(ERROR) << "cannot write message: too long: " << filename;
202 return false; 203 return false;
203 } 204 }
204 205
205 // The file containing the metrics samples will only be read by programs on 206 // The file containing the metrics samples will only be read by programs on
206 // the same device so we do not check endianness. 207 // the same device so we do not check endianness.
207 if (!base::WriteFileDescriptor(file_descriptor.get(), 208 if (!base::WriteFileDescriptor(file_descriptor.get(),
208 reinterpret_cast<char*>(&size), 209 reinterpret_cast<char*>(&size),
209 sizeof(size))) { 210 sizeof(size))) {
210 DPLOG(ERROR) << "error writing message length: " << filename; 211 DPLOG(ERROR) << "error writing message length: " << filename;
211 return false; 212 return false;
212 } 213 }
213 214
214 if (!base::WriteFileDescriptor( 215 if (!base::WriteFileDescriptor(
215 file_descriptor.get(), msg.c_str(), msg.size())) { 216 file_descriptor.get(), msg.c_str(), msg.size())) {
216 DPLOG(ERROR) << "error writing message: " << filename; 217 DPLOG(ERROR) << "error writing message: " << filename;
217 return false; 218 return false;
218 } 219 }
219 220
220 return true; 221 return true;
221 } 222 }
222 223
223 } // namespace metrics 224 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698