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

Side by Side Diff: components/storage_monitor/volume_mount_watcher_win.cc

Issue 1549993003: Switch to standard integer types in components/, part 4 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/storage_monitor/volume_mount_watcher_win.h" 5 #include "components/storage_monitor/volume_mount_watcher_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <stddef.h>
9 #include <stdint.h>
8 10
9 #include <dbt.h> 11 #include <dbt.h>
10 #include <fileapi.h> 12 #include <fileapi.h>
11 #include <shlobj.h> 13 #include <shlobj.h>
12 #include <winioctl.h> 14 #include <winioctl.h>
13 15
14 #include "base/bind_helpers.h" 16 #include "base/bind_helpers.h"
15 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
16 #include "base/stl_util.h" 18 #include "base/stl_util.h"
17 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 return FLOPPY; 88 return FLOPPY;
87 if (device_path.find(L"Floppy") != base::string16::npos || 89 if (device_path.find(L"Floppy") != base::string16::npos ||
88 device_path_slash.find(L"Floppy") != base::string16::npos) { 90 device_path_slash.find(L"Floppy") != base::string16::npos) {
89 return FLOPPY; 91 return FLOPPY;
90 } 92 }
91 93
92 return REMOVABLE; 94 return REMOVABLE;
93 } 95 }
94 96
95 // Returns 0 if the devicetype is not volume. 97 // Returns 0 if the devicetype is not volume.
96 uint32 GetVolumeBitMaskFromBroadcastHeader(LPARAM data) { 98 uint32_t GetVolumeBitMaskFromBroadcastHeader(LPARAM data) {
97 DEV_BROADCAST_VOLUME* dev_broadcast_volume = 99 DEV_BROADCAST_VOLUME* dev_broadcast_volume =
98 reinterpret_cast<DEV_BROADCAST_VOLUME*>(data); 100 reinterpret_cast<DEV_BROADCAST_VOLUME*>(data);
99 if (dev_broadcast_volume->dbcv_devicetype == DBT_DEVTYP_VOLUME) 101 if (dev_broadcast_volume->dbcv_devicetype == DBT_DEVTYP_VOLUME)
100 return dev_broadcast_volume->dbcv_unitmask; 102 return dev_broadcast_volume->dbcv_unitmask;
101 return 0; 103 return 0;
102 } 104 }
103 105
104 // Returns true if |data| represents a logical volume structure. 106 // Returns true if |data| represents a logical volume structure.
105 bool IsLogicalVolumeStructure(LPARAM data) { 107 bool IsLogicalVolumeStructure(LPARAM data) {
106 DEV_BROADCAST_HDR* broadcast_hdr = 108 DEV_BROADCAST_HDR* broadcast_hdr =
107 reinterpret_cast<DEV_BROADCAST_HDR*>(data); 109 reinterpret_cast<DEV_BROADCAST_HDR*>(data);
108 return broadcast_hdr != NULL && 110 return broadcast_hdr != NULL &&
109 broadcast_hdr->dbch_devicetype == DBT_DEVTYP_VOLUME; 111 broadcast_hdr->dbch_devicetype == DBT_DEVTYP_VOLUME;
110 } 112 }
111 113
112 // Gets the total volume of the |mount_point| in bytes. 114 // Gets the total volume of the |mount_point| in bytes.
113 uint64 GetVolumeSize(const base::string16& mount_point) { 115 uint64_t GetVolumeSize(const base::string16& mount_point) {
114 ULARGE_INTEGER total; 116 ULARGE_INTEGER total;
115 if (!GetDiskFreeSpaceExW(mount_point.c_str(), NULL, &total, NULL)) 117 if (!GetDiskFreeSpaceExW(mount_point.c_str(), NULL, &total, NULL))
116 return 0; 118 return 0;
117 return total.QuadPart; 119 return total.QuadPart;
118 } 120 }
119 121
120 // Gets mass storage device information given a |device_path|. On success, 122 // Gets mass storage device information given a |device_path|. On success,
121 // returns true and fills in |info|. 123 // returns true and fills in |info|.
122 // The following msdn blog entry is helpful for understanding disk volumes 124 // The following msdn blog entry is helpful for understanding disk volumes
123 // and how they are treated in Windows: 125 // and how they are treated in Windows:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 type = StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM; 167 type = StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM;
166 } 168 }
167 169
168 // NOTE: experimentally, this function returns false if there is no volume 170 // NOTE: experimentally, this function returns false if there is no volume
169 // name set. 171 // name set.
170 base::string16 volume_label; 172 base::string16 volume_label;
171 GetVolumeInformationW(device_path.value().c_str(), 173 GetVolumeInformationW(device_path.value().c_str(),
172 base::WriteInto(&volume_label, kMaxPathBufLen), 174 base::WriteInto(&volume_label, kMaxPathBufLen),
173 kMaxPathBufLen, NULL, NULL, NULL, NULL, 0); 175 kMaxPathBufLen, NULL, NULL, NULL, NULL, 0);
174 176
175 uint64 total_size_in_bytes = GetVolumeSize(mount_point); 177 uint64_t total_size_in_bytes = GetVolumeSize(mount_point);
176 std::string device_id = 178 std::string device_id =
177 StorageInfo::MakeDeviceId(type, base::UTF16ToUTF8(guid)); 179 StorageInfo::MakeDeviceId(type, base::UTF16ToUTF8(guid));
178 180
179 // TODO(gbillock): if volume_label.empty(), get the vendor/model information 181 // TODO(gbillock): if volume_label.empty(), get the vendor/model information
180 // for the volume. 182 // for the volume.
181 *info = StorageInfo(device_id, mount_point, volume_label, base::string16(), 183 *info = StorageInfo(device_id, mount_point, volume_label, base::string16(),
182 base::string16(), total_size_in_bytes); 184 base::string16(), total_size_in_bytes);
183 return true; 185 return true;
184 } 186 }
185 187
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 callback.Run(StorageMonitor::EJECT_FAILURE); 546 callback.Run(StorageMonitor::EJECT_FAILURE);
545 return; 547 return;
546 } 548 }
547 549
548 device_info_task_runner_->PostTask( 550 device_info_task_runner_->PostTask(
549 FROM_HERE, base::Bind(&EjectDeviceInThreadPool, device, callback, 551 FROM_HERE, base::Bind(&EjectDeviceInThreadPool, device, callback,
550 device_info_task_runner_, 0)); 552 device_info_task_runner_, 0));
551 } 553 }
552 554
553 } // namespace storage_monitor 555 } // namespace storage_monitor
OLDNEW
« no previous file with comments | « components/storage_monitor/volume_mount_watcher_win.h ('k') | components/suggestions/blacklist_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698