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

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: OSX/Win fixes and review feedback. Created 8 years, 7 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() {
12 StringSet valid_patterns; 18 StringSet valid_patterns;
13 return valid_patterns; 19 return valid_patterns;
14 } 20 }
15 21
22 static bool PassesCommConfigTest(const string16& port_name) {
23 COMMCONFIG comm_config;
24 DWORD cc_size = sizeof(COMMCONFIG);
25 return GetDefaultCommConfig(port_name.c_str(), &comm_config, &cc_size) ||
26 cc_size != sizeof(COMMCONFIG);
27 }
28
16 // static 29 // static
17 SerialPortEnumerator::StringSet 30 SerialPortEnumerator::StringSet
18 SerialPortEnumerator::GenerateValidSerialPortNames() { 31 SerialPortEnumerator::GenerateValidSerialPortNames() {
19 // TODO(miket): implement 32 StringSet name_set;
20 StringSet valid_names; 33 int max_port_number = 16;
21 return valid_names; 34
35 // We ended up not using valid_patterns. TODO(miket): we might want
36 // to refactor this interface to make it more platform-independent.
37 for (int port_number = 0; port_number < max_port_number; ++port_number) {
38 string16 device_string16 = (port_number <= 9) ?
39 base::StringPrintf(L"COM%d", port_number) :
40 base::StringPrintf(L"\\\\.\\COM%d", port_number);
41
42 if (PassesCommConfigTest(device_string16)) {
43 // Keep looking for new ports as long as we're finding them.
44 int new_max_port_number = (port_number + 1) * 2;
45 if (new_max_port_number > max_port_number)
46 max_port_number = new_max_port_number;
47
48 std::string device_string(WideToASCII(device_string16));
49 name_set.insert(device_string);
50 }
51 }
52 return name_set;
22 } 53 }
23 54
24 } // namespace extensions 55 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698