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

Side by Side Diff: chrome/browser/extensions/api/serial/serial_port_enumerator_win.cc

Issue 10392181: Implement serial API for Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: From -> At. Created 8 years, 6 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/serial/serial_port_enumerator.h" 5 #include "chrome/browser/extensions/api/serial/serial_port_enumerator.h"
6 6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/string_util.h"
9 #include "base/stringprintf.h"
10
11 #include <windows.h>
12
7 namespace extensions { 13 namespace extensions {
8 14
9 // static 15 // static
10 SerialPortEnumerator::StringSet SerialPortEnumerator::GenerateValidPatterns() { 16 SerialPortEnumerator::StringSet
11 // TODO(miket): implement 17 SerialPortEnumerator::GenerateValidPatterns() {
18 const char* VALID_PATTERNS[] = {
19 "COM*",
20 "\\\\.\\COM*",
21 };
22
12 StringSet valid_patterns; 23 StringSet valid_patterns;
24 for (size_t i = 0; i < arraysize(VALID_PATTERNS); ++i)
25 valid_patterns.insert(VALID_PATTERNS[i]);
26
13 return valid_patterns; 27 return valid_patterns;
14 } 28 }
15 29
30 static bool PassesCommConfigTest(const string16& port_name) {
31 COMMCONFIG comm_config;
32 DWORD cc_size = sizeof(COMMCONFIG);
33 return GetDefaultCommConfig(port_name.c_str(), &comm_config, &cc_size) ||
34 cc_size != sizeof(COMMCONFIG);
35 }
36
16 // static 37 // static
17 SerialPortEnumerator::StringSet 38 SerialPortEnumerator::StringSet
18 SerialPortEnumerator::GenerateValidSerialPortNames() { 39 SerialPortEnumerator::GenerateValidSerialPortNames() {
19 // TODO(miket): implement 40 StringSet name_set;
20 StringSet valid_names; 41 int max_port_number = 16;
21 return valid_names; 42
43 // We ended up not using valid_patterns. TODO(miket): we might want
44 // to refactor this interface to make it more platform-independent.
45 for (int port_number = 0; port_number < max_port_number; ++port_number) {
46 string16 device_string16;
47 device_string16 = base::StringPrintf(L"\\\\.\\COM%d", port_number);
48 if (PassesCommConfigTest(device_string16)) {
49 // Keep looking for new ports as long as we're finding them.
50 int new_max_port_number = (port_number + 1) * 2;
51 if (new_max_port_number > max_port_number)
52 max_port_number = new_max_port_number;
53
54 std::string device_string(WideToASCII(device_string16));
55 name_set.insert(device_string);
56 }
57 }
58 return name_set;
22 } 59 }
23 60
24 } // namespace extensions 61 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698