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

Side by Side Diff: tools/battor_agent/battor_finder.cc

Issue 2492013005: Mojo C++ bindings: switch device/serial mojom target to use STL types. (Closed)
Patch Set: \ Created 4 years, 1 month 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
« no previous file with comments | « extensions/browser/api/serial/serial_api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 20 matching lines...) Expand all
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
39 // display name. 39 // display name.
40 for (size_t i = 0; i < devices.size(); i++) { 40 for (size_t i = 0; i < devices.size(); i++) {
41 std::string display_name = devices[i]->display_name.get(); 41 if (!devices[i]->display_name)
42 continue;
43 const auto& display_name = devices[i]->display_name.value();
42 if (display_name.find(kBattOrDisplayNamePrefix) != std::string::npos) { 44 if (display_name.find(kBattOrDisplayNamePrefix) != std::string::npos) {
43 LOG(INFO) << "Found BattOr with display name " << display_name 45 LOG(INFO) << "Found BattOr with display name " << display_name
44 << " at path " << devices[i]->path; 46 << " at path " << devices[i]->path;
45 return devices[i]->path; 47 return devices[i]->path;
46 } 48 }
47 } 49 }
48 } else { 50 } else {
49 // If we have a switch-specified path, make sure it actually exists before 51 // If we have a switch-specified path, make sure it actually exists before
50 // returning it. 52 // returning it.
51 for (size_t i = 0; i < devices.size(); i++) { 53 for (size_t i = 0; i < devices.size(); i++) {
52 if (devices[i]->path == switch_specified_path) 54 if (devices[i]->path == switch_specified_path)
53 return switch_specified_path; 55 return switch_specified_path;
54 } 56 }
55 } 57 }
56 58
57 return std::string(); 59 return std::string();
58 } 60 }
59 61
60 } // namespace battor 62 } // namespace battor
OLDNEW
« no previous file with comments | « extensions/browser/api/serial/serial_api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698