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

Side by Side Diff: device/serial/serial_device_enumerator_win.cc

Issue 311313002: Convert SerialDeviceInfo to a Mojo struct. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 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_win.h" 5 #include "device/serial/serial_device_enumerator_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/memory/linked_ptr.h"
10 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
14 #include "base/win/registry.h" 13 #include "base/win/registry.h"
15 14
16 namespace device { 15 namespace device {
17 16
18 // static 17 // static
19 scoped_ptr<SerialDeviceEnumerator> SerialDeviceEnumerator::Create() { 18 scoped_ptr<SerialDeviceEnumerator> SerialDeviceEnumerator::Create() {
20 return scoped_ptr<SerialDeviceEnumerator>(new SerialDeviceEnumeratorWin()); 19 return scoped_ptr<SerialDeviceEnumerator>(new SerialDeviceEnumeratorWin());
21 } 20 }
22 21
23 SerialDeviceEnumeratorWin::SerialDeviceEnumeratorWin() {} 22 SerialDeviceEnumeratorWin::SerialDeviceEnumeratorWin() {}
24 23
25 SerialDeviceEnumeratorWin::~SerialDeviceEnumeratorWin() {} 24 SerialDeviceEnumeratorWin::~SerialDeviceEnumeratorWin() {}
26 25
27 // TODO(rockot): Query the system for more information than just device paths. 26 // TODO(rockot): Query the system for more information than just device paths.
28 // This may or may not require using a different strategy than scanning the 27 // This may or may not require using a different strategy than scanning the
29 // registry location below. 28 // registry location below.
30 void SerialDeviceEnumeratorWin::GetDevices(SerialDeviceInfoList* devices) { 29 mojo::Array<SerialDeviceInfoPtr> SerialDeviceEnumeratorWin::GetDevices() {
31 devices->clear();
32
33 base::win::RegistryValueIterator iter_key( 30 base::win::RegistryValueIterator iter_key(
34 HKEY_LOCAL_MACHINE, L"HARDWARE\\DEVICEMAP\\SERIALCOMM\\"); 31 HKEY_LOCAL_MACHINE, L"HARDWARE\\DEVICEMAP\\SERIALCOMM\\");
32 mojo::Array<SerialDeviceInfoPtr> devices;
35 for (; iter_key.Valid(); ++iter_key) { 33 for (; iter_key.Valid(); ++iter_key) {
36 base::string16 value(iter_key.Value()); 34 SerialDeviceInfoPtr info(SerialDeviceInfo::New());
37 linked_ptr<SerialDeviceInfo> info(new SerialDeviceInfo); 35 info->path = mojo::String::From(base::UTF16ToASCII(iter_key.Value()));
darin (slow to review) 2014/06/16 16:59:19 nit: mojo::String::From(..) is unnecessary here
Sam McNally 2014/06/17 07:07:20 Done.
38 info->path = base::UTF16ToASCII(value); 36 devices.push_back(info.Pass());
39 devices->push_back(info);
40 } 37 }
38 return devices.Pass();
41 } 39 }
42 40
43 } // namespace device 41 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698