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 // StorageMonitorLinux implementation. | 5 // StorageMonitorLinux implementation. |
6 | 6 |
7 #include "components/storage_monitor/storage_monitor_linux.h" | 7 #include "components/storage_monitor/storage_monitor_linux.h" |
8 | 8 |
9 #include <mntent.h> | 9 #include <mntent.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 | 11 |
12 #include <list> | 12 #include <list> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/process/kill.h" | 17 #include "base/process/kill.h" |
18 #include "base/process/launch.h" | 18 #include "base/process/launch.h" |
| 19 #include "base/process/process.h" |
19 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
21 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
23 #include "components/storage_monitor/media_storage_util.h" | 24 #include "components/storage_monitor/media_storage_util.h" |
24 #include "components/storage_monitor/media_transfer_protocol_device_observer_lin
ux.h" | 25 #include "components/storage_monitor/media_transfer_protocol_device_observer_lin
ux.h" |
25 #include "components/storage_monitor/removable_device_constants.h" | 26 #include "components/storage_monitor/removable_device_constants.h" |
26 #include "components/storage_monitor/storage_info.h" | 27 #include "components/storage_monitor/storage_info.h" |
27 #include "components/storage_monitor/udev_util_linux.h" | 28 #include "components/storage_monitor/udev_util_linux.h" |
28 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" | 29 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 command.push_back(path.value()); | 215 command.push_back(path.value()); |
215 | 216 |
216 base::LaunchOptions options; | 217 base::LaunchOptions options; |
217 base::Process process = base::LaunchProcess(command, options); | 218 base::Process process = base::LaunchProcess(command, options); |
218 if (!process.IsValid()) | 219 if (!process.IsValid()) |
219 return StorageMonitor::EJECT_FAILURE; | 220 return StorageMonitor::EJECT_FAILURE; |
220 | 221 |
221 int exit_code = -1; | 222 int exit_code = -1; |
222 if (!process.WaitForExitWithTimeout(base::TimeDelta::FromMilliseconds(3000), | 223 if (!process.WaitForExitWithTimeout(base::TimeDelta::FromMilliseconds(3000), |
223 &exit_code)) { | 224 &exit_code)) { |
224 base::KillProcess(process.Handle(), -1, false); | 225 process.Terminate(-1, false); |
225 base::EnsureProcessTerminated(process.Pass()); | 226 base::EnsureProcessTerminated(process.Pass()); |
226 return StorageMonitor::EJECT_FAILURE; | 227 return StorageMonitor::EJECT_FAILURE; |
227 } | 228 } |
228 | 229 |
229 // TODO(gbillock): Make sure this is found in documentation | 230 // TODO(gbillock): Make sure this is found in documentation |
230 // somewhere. Experimentally it seems to hold that exit code | 231 // somewhere. Experimentally it seems to hold that exit code |
231 // 1 means device is in use. | 232 // 1 means device is in use. |
232 if (exit_code == 1) | 233 if (exit_code == 1) |
233 return StorageMonitor::EJECT_IN_USE; | 234 return StorageMonitor::EJECT_IN_USE; |
234 if (exit_code != 0) | 235 if (exit_code != 0) |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 mount_priority_map_[mount_device][mount_point] = removable; | 501 mount_priority_map_[mount_device][mount_point] = removable; |
501 receiver()->ProcessAttach(*storage_info); | 502 receiver()->ProcessAttach(*storage_info); |
502 } | 503 } |
503 | 504 |
504 StorageMonitor* StorageMonitor::CreateInternal() { | 505 StorageMonitor* StorageMonitor::CreateInternal() { |
505 const base::FilePath kDefaultMtabPath("/etc/mtab"); | 506 const base::FilePath kDefaultMtabPath("/etc/mtab"); |
506 return new StorageMonitorLinux(kDefaultMtabPath); | 507 return new StorageMonitorLinux(kDefaultMtabPath); |
507 } | 508 } |
508 | 509 |
509 } // namespace storage_monitor | 510 } // namespace storage_monitor |
OLD | NEW |