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 #include "device/serial/serial_device_enumerator_mac.h" | 5 #include "device/serial/serial_device_enumerator_mac.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_enumerator.h" | 8 #include "base/files/file_enumerator.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 std::set<std::string> valid_patterns; | 30 std::set<std::string> valid_patterns; |
31 valid_patterns.insert("/dev/*Bluetooth*"); | 31 valid_patterns.insert("/dev/*Bluetooth*"); |
32 valid_patterns.insert("/dev/*Modem*"); | 32 valid_patterns.insert("/dev/*Modem*"); |
33 valid_patterns.insert("/dev/*bluetooth*"); | 33 valid_patterns.insert("/dev/*bluetooth*"); |
34 valid_patterns.insert("/dev/*modem*"); | 34 valid_patterns.insert("/dev/*modem*"); |
35 valid_patterns.insert("/dev/*serial*"); | 35 valid_patterns.insert("/dev/*serial*"); |
36 valid_patterns.insert("/dev/tty.*"); | 36 valid_patterns.insert("/dev/tty.*"); |
37 valid_patterns.insert("/dev/cu.*"); | 37 valid_patterns.insert("/dev/cu.*"); |
38 | 38 |
39 mojo::Array<serial::DeviceInfoPtr> devices; | 39 mojo::Array<serial::DeviceInfoPtr> devices(0); |
40 base::FileEnumerator enumerator(kDevRoot, false, kFilesAndSymLinks); | 40 base::FileEnumerator enumerator(kDevRoot, false, kFilesAndSymLinks); |
41 do { | 41 do { |
42 const base::FilePath next_device_path(enumerator.Next()); | 42 const base::FilePath next_device_path(enumerator.Next()); |
43 const std::string next_device = next_device_path.value(); | 43 const std::string next_device = next_device_path.value(); |
44 if (next_device.empty()) | 44 if (next_device.empty()) |
45 break; | 45 break; |
46 | 46 |
47 std::set<std::string>::const_iterator i = valid_patterns.begin(); | 47 std::set<std::string>::const_iterator i = valid_patterns.begin(); |
48 for (; i != valid_patterns.end(); ++i) { | 48 for (; i != valid_patterns.end(); ++i) { |
49 if (MatchPattern(next_device, *i)) { | 49 if (MatchPattern(next_device, *i)) { |
50 serial::DeviceInfoPtr info(serial::DeviceInfo::New()); | 50 serial::DeviceInfoPtr info(serial::DeviceInfo::New()); |
51 info->path = next_device; | 51 info->path = next_device; |
52 devices.push_back(info.Pass()); | 52 devices.push_back(info.Pass()); |
53 break; | 53 break; |
54 } | 54 } |
55 } | 55 } |
56 } while (true); | 56 } while (true); |
57 return devices.Pass(); | 57 return devices.Pass(); |
58 } | 58 } |
59 | 59 |
60 } // namespace device | 60 } // namespace device |
OLD | NEW |