| Index: chrome/browser/extensions/api/serial/serial_port_enumerator_win.cc
|
| diff --git a/chrome/browser/extensions/api/serial/serial_port_enumerator_win.cc b/chrome/browser/extensions/api/serial/serial_port_enumerator_win.cc
|
| index ea1f822a3363ff95ca380ad09f74def12bb99c5b..84817aa86ccbd5c6c2d9b14cde570bd7770b1884 100644
|
| --- a/chrome/browser/extensions/api/serial/serial_port_enumerator_win.cc
|
| +++ b/chrome/browser/extensions/api/serial/serial_port_enumerator_win.cc
|
| @@ -4,21 +4,58 @@
|
|
|
| #include "chrome/browser/extensions/api/serial/serial_port_enumerator.h"
|
|
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/string_util.h"
|
| +#include "base/stringprintf.h"
|
| +
|
| +#include <windows.h>
|
| +
|
| namespace extensions {
|
|
|
| // static
|
| -SerialPortEnumerator::StringSet SerialPortEnumerator::GenerateValidPatterns() {
|
| - // TODO(miket): implement
|
| +SerialPortEnumerator::StringSet
|
| +SerialPortEnumerator::GenerateValidPatterns() {
|
| + const char* VALID_PATTERNS[] = {
|
| + "COM*",
|
| + "\\\\.\\COM*",
|
| + };
|
| +
|
| StringSet valid_patterns;
|
| + for (size_t i = 0; i < arraysize(VALID_PATTERNS); ++i)
|
| + valid_patterns.insert(VALID_PATTERNS[i]);
|
| +
|
| return valid_patterns;
|
| }
|
|
|
| +static bool PassesCommConfigTest(const string16& port_name) {
|
| + COMMCONFIG comm_config;
|
| + DWORD cc_size = sizeof(COMMCONFIG);
|
| + return GetDefaultCommConfig(port_name.c_str(), &comm_config, &cc_size) ||
|
| + cc_size != sizeof(COMMCONFIG);
|
| +}
|
| +
|
| // static
|
| SerialPortEnumerator::StringSet
|
| SerialPortEnumerator::GenerateValidSerialPortNames() {
|
| - // TODO(miket): implement
|
| - StringSet valid_names;
|
| - return valid_names;
|
| + StringSet name_set;
|
| + int max_port_number = 16;
|
| +
|
| + // We ended up not using valid_patterns. TODO(miket): we might want
|
| + // to refactor this interface to make it more platform-independent.
|
| + for (int port_number = 0; port_number < max_port_number; ++port_number) {
|
| + string16 device_string16;
|
| + device_string16 = base::StringPrintf(L"\\\\.\\COM%d", port_number);
|
| + if (PassesCommConfigTest(device_string16)) {
|
| + // Keep looking for new ports as long as we're finding them.
|
| + int new_max_port_number = (port_number + 1) * 2;
|
| + if (new_max_port_number > max_port_number)
|
| + max_port_number = new_max_port_number;
|
| +
|
| + std::string device_string(WideToASCII(device_string16));
|
| + name_set.insert(device_string);
|
| + }
|
| + }
|
| + return name_set;
|
| }
|
|
|
| } // namespace extensions
|
|
|