OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "tools/battor_agent/battor_finder.h" | 5 #include "tools/battor_agent/battor_finder.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "device/serial/serial.mojom.h" | 9 #include "device/serial/serial.mojom.h" |
10 #include "device/serial/serial_device_enumerator.h" | 10 #include "device/serial/serial_device_enumerator.h" |
11 #include "mojo/public/cpp/bindings/array.h" | 11 #include "mojo/public/cpp/bindings/array.h" |
12 | 12 |
13 namespace battor { | 13 namespace battor { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // The USB display name prefix that all BattOrs have. | 17 // The USB display name prefix that all BattOrs have. |
18 const char kBattOrDisplayNamePrefix[] = "BattOr"; | 18 const char kBattOrDisplayNamePrefix[] = "BattOr"; |
19 | 19 |
20 // The command line switch used to hard-code a BattOr path. Hard-coding | 20 // The command line switch used to hard-code a BattOr path. Hard-coding |
21 // this path disables the normal method of finding a BattOr, which is to | 21 // this path disables the normal method of finding a BattOr, which is to |
22 // search through serial devices for one with a matching display name. | 22 // search through serial devices for one with a matching display name. |
23 const char kBattOrPathSwitch[] = "battor-path"; | 23 const char kBattOrPathSwitch[] = "battor-path"; |
24 | 24 |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 std::string BattOrFinder::FindBattOr() { | 27 std::string BattOrFinder::FindBattOr() { |
28 scoped_ptr<device::SerialDeviceEnumerator> serial_device_enumerator = | 28 std::unique_ptr<device::SerialDeviceEnumerator> serial_device_enumerator = |
29 device::SerialDeviceEnumerator::Create(); | 29 device::SerialDeviceEnumerator::Create(); |
30 | 30 |
31 mojo::Array<device::serial::DeviceInfoPtr> devices = | 31 mojo::Array<device::serial::DeviceInfoPtr> devices = |
32 serial_device_enumerator->GetDevices(); | 32 serial_device_enumerator->GetDevices(); |
33 | 33 |
34 std::string switch_specified_path = | 34 std::string switch_specified_path = |
35 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 35 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
36 kBattOrPathSwitch); | 36 kBattOrPathSwitch); |
37 if (switch_specified_path.empty()) { | 37 if (switch_specified_path.empty()) { |
38 // If we have no switch-specified path, look for a device with the right | 38 // If we have no switch-specified path, look for a device with the right |
(...skipping 12 matching lines...) Expand all Loading... |
51 for (size_t i = 0; i < devices.size(); i++) { | 51 for (size_t i = 0; i < devices.size(); i++) { |
52 if (devices[i]->path == switch_specified_path) | 52 if (devices[i]->path == switch_specified_path) |
53 return switch_specified_path; | 53 return switch_specified_path; |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 return std::string(); | 57 return std::string(); |
58 } | 58 } |
59 | 59 |
60 } // namespace battor | 60 } // namespace battor |
OLD | NEW |