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

Side by Side Diff: components/metrics/machine_id_provider_win.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/machine_id_provider.h" 5 #include "components/metrics/machine_id_provider.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <stdint.h>
8 #include <winioctl.h> 9 #include <winioctl.h>
9 10
10 #include "base/base_paths.h" 11 #include "base/base_paths.h"
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
12 #include "base/path_service.h" 13 #include "base/path_service.h"
13 #include "base/threading/thread_restrictions.h" 14 #include "base/threading/thread_restrictions.h"
14 #include "base/win/scoped_handle.h" 15 #include "base/win/scoped_handle.h"
15 16
16 namespace metrics { 17 namespace metrics {
17 18
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 sizeof(STORAGE_PROPERTY_QUERY), 67 sizeof(STORAGE_PROPERTY_QUERY),
67 &header, 68 &header,
68 sizeof(STORAGE_DESCRIPTOR_HEADER), 69 sizeof(STORAGE_DESCRIPTOR_HEADER),
69 &bytes_returned, 70 &bytes_returned,
70 NULL); 71 NULL);
71 72
72 if (!status) 73 if (!status)
73 return std::string(); 74 return std::string();
74 75
75 // Query for the actual serial number. 76 // Query for the actual serial number.
76 std::vector<int8> output_buf(header.Size); 77 std::vector<int8_t> output_buf(header.Size);
77 status = DeviceIoControl(drive_handle.Get(), 78 status = DeviceIoControl(drive_handle.Get(),
78 IOCTL_STORAGE_QUERY_PROPERTY, 79 IOCTL_STORAGE_QUERY_PROPERTY,
79 &query, 80 &query,
80 sizeof(STORAGE_PROPERTY_QUERY), 81 sizeof(STORAGE_PROPERTY_QUERY),
81 &output_buf[0], 82 &output_buf[0],
82 output_buf.size(), 83 output_buf.size(),
83 &bytes_returned, 84 &bytes_returned,
84 NULL); 85 NULL);
85 86
86 if (!status) 87 if (!status)
87 return std::string(); 88 return std::string();
88 89
89 const STORAGE_DEVICE_DESCRIPTOR* device_descriptor = 90 const STORAGE_DEVICE_DESCRIPTOR* device_descriptor =
90 reinterpret_cast<STORAGE_DEVICE_DESCRIPTOR*>(&output_buf[0]); 91 reinterpret_cast<STORAGE_DEVICE_DESCRIPTOR*>(&output_buf[0]);
91 92
92 // The serial number is stored in the |output_buf| as a null-terminated 93 // The serial number is stored in the |output_buf| as a null-terminated
93 // string starting at the specified offset. 94 // string starting at the specified offset.
94 const DWORD offset = device_descriptor->SerialNumberOffset; 95 const DWORD offset = device_descriptor->SerialNumberOffset;
95 if (offset >= output_buf.size()) 96 if (offset >= output_buf.size())
96 return std::string(); 97 return std::string();
97 98
98 // Make sure that the null-terminator exists. 99 // Make sure that the null-terminator exists.
99 const std::vector<int8>::iterator serial_number_begin = 100 const std::vector<int8_t>::iterator serial_number_begin =
100 output_buf.begin() + offset; 101 output_buf.begin() + offset;
101 const std::vector<int8>::iterator null_location = 102 const std::vector<int8_t>::iterator null_location =
102 std::find(serial_number_begin, output_buf.end(), '\0'); 103 std::find(serial_number_begin, output_buf.end(), '\0');
103 if (null_location == output_buf.end()) 104 if (null_location == output_buf.end())
104 return std::string(); 105 return std::string();
105 106
106 const char* serial_number = 107 const char* serial_number =
107 reinterpret_cast<const char*>(&output_buf[offset]); 108 reinterpret_cast<const char*>(&output_buf[offset]);
108 109
109 return std::string(serial_number); 110 return std::string(serial_number);
110 } 111 }
111 112
112 // static 113 // static
113 MachineIdProvider* MachineIdProvider::CreateInstance() { 114 MachineIdProvider* MachineIdProvider::CreateInstance() {
114 return new MachineIdProvider(); 115 return new MachineIdProvider();
115 } 116 }
116 117
117 } // namespace metrics 118 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/leak_detector/ranked_list_unittest.cc ('k') | components/metrics/metrics_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698