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

Side by Side Diff: extensions/browser/api/usb_private/usb_private_api.cc

Issue 507503002: Remove BrowserThread dependency from usb_service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move device/common to device/core. Created 6 years, 3 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
« no previous file with comments | « extensions/browser/api/usb_private/DEPS ('k') | extensions/shell/app_shell.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "extensions/browser/api/usb_private/usb_private_api.h" 5 #include "extensions/browser/api/usb_private/usb_private_api.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "components/usb_service/usb_device_filter.h" 12 #include "components/usb_service/usb_device_filter.h"
13 #include "components/usb_service/usb_device_handle.h" 13 #include "components/usb_service/usb_device_handle.h"
14 #include "components/usb_service/usb_service.h" 14 #include "components/usb_service/usb_service.h"
15 #include "device/core/device_client.h"
15 #include "device/usb/usb_ids.h" 16 #include "device/usb/usb_ids.h"
16 #include "extensions/common/api/usb_private.h" 17 #include "extensions/common/api/usb_private.h"
17 18
18 namespace usb_private = extensions::core_api::usb_private; 19 namespace usb_private = extensions::core_api::usb_private;
19 namespace GetDevices = usb_private::GetDevices; 20 namespace GetDevices = usb_private::GetDevices;
20 namespace GetDeviceInfo = usb_private::GetDeviceInfo; 21 namespace GetDeviceInfo = usb_private::GetDeviceInfo;
21 22
23 using content::BrowserThread;
22 using usb_service::UsbDevice; 24 using usb_service::UsbDevice;
23 using usb_service::UsbDeviceFilter; 25 using usb_service::UsbDeviceFilter;
24 using usb_service::UsbDeviceHandle; 26 using usb_service::UsbDeviceHandle;
25 using usb_service::UsbService; 27 using usb_service::UsbService;
26 28
27 namespace { 29 namespace {
28 30
29 const char kErrorInitService[] = "Failed to initialize USB service."; 31 const char kErrorInitService[] = "Failed to initialize USB service.";
30 const char kErrorNoDevice[] = "No such device."; 32 const char kErrorNoDevice[] = "No such device.";
31 const char kErrorOpen[] = "Failed to open device."; 33 const char kErrorOpen[] = "Failed to open device.";
32 34
33 } // namespace 35 } // namespace
34 36
35 namespace extensions { 37 namespace extensions {
36 38
37 UsbPrivateGetDevicesFunction::UsbPrivateGetDevicesFunction() { 39 UsbPrivateGetDevicesFunction::UsbPrivateGetDevicesFunction() {
38 } 40 }
39 41
40 UsbPrivateGetDevicesFunction::~UsbPrivateGetDevicesFunction() { 42 UsbPrivateGetDevicesFunction::~UsbPrivateGetDevicesFunction() {
41 } 43 }
42 44
43 bool UsbPrivateGetDevicesFunction::Prepare() { 45 bool UsbPrivateGetDevicesFunction::Prepare() {
44 parameters_ = GetDevices::Params::Create(*args_); 46 parameters_ = GetDevices::Params::Create(*args_);
45 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); 47 EXTENSION_FUNCTION_VALIDATE(parameters_.get());
46 return true; 48 return true;
47 } 49 }
48 50
49 void UsbPrivateGetDevicesFunction::AsyncWorkStart() { 51 void UsbPrivateGetDevicesFunction::AsyncWorkStart() {
50 UsbService* service = UsbService::GetInstance(); 52 UsbService* service = device::DeviceClient::Get()->GetUsbService();
51 if (!service) { 53 if (!service) {
52 CompleteWithError(kErrorInitService); 54 CompleteWithError(kErrorInitService);
53 return; 55 return;
54 } 56 }
55 57
56 std::vector<UsbDeviceFilter> filters; 58 std::vector<UsbDeviceFilter> filters;
57 filters.resize(parameters_->filters.size()); 59 filters.resize(parameters_->filters.size());
58 for (size_t i = 0; i < parameters_->filters.size(); ++i) { 60 for (size_t i = 0; i < parameters_->filters.size(); ++i) {
59 UsbDeviceFilter& filter = filters[i]; 61 UsbDeviceFilter& filter = filters[i];
60 const usb_private::DeviceFilter* filter_param = 62 const usb_private::DeviceFilter* filter_param =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 UsbPrivateGetDeviceInfoFunction::~UsbPrivateGetDeviceInfoFunction() { 112 UsbPrivateGetDeviceInfoFunction::~UsbPrivateGetDeviceInfoFunction() {
111 } 113 }
112 114
113 bool UsbPrivateGetDeviceInfoFunction::Prepare() { 115 bool UsbPrivateGetDeviceInfoFunction::Prepare() {
114 parameters_ = GetDeviceInfo::Params::Create(*args_); 116 parameters_ = GetDeviceInfo::Params::Create(*args_);
115 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); 117 EXTENSION_FUNCTION_VALIDATE(parameters_.get());
116 return true; 118 return true;
117 } 119 }
118 120
119 void UsbPrivateGetDeviceInfoFunction::AsyncWorkStart() { 121 void UsbPrivateGetDeviceInfoFunction::AsyncWorkStart() {
120 UsbService* service = UsbService::GetInstance(); 122 UsbService* service = device::DeviceClient::Get()->GetUsbService();
121 if (!service) { 123 if (!service) {
122 CompleteWithError(kErrorInitService); 124 CompleteWithError(kErrorInitService);
123 return; 125 return;
124 } 126 }
125 127
126 scoped_refptr<UsbDevice> device = 128 scoped_refptr<UsbDevice> device =
127 service->GetDeviceById(parameters_->device_id); 129 service->GetDeviceById(parameters_->device_id);
128 if (!device.get()) { 130 if (!device.get()) {
129 CompleteWithError(kErrorNoDevice); 131 CompleteWithError(kErrorNoDevice);
130 return; 132 return;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 165
164 if (device_handle->GetSerial(&utf16)) { 166 if (device_handle->GetSerial(&utf16)) {
165 device_info.serial_string.reset(new std::string(base::UTF16ToUTF8(utf16))); 167 device_info.serial_string.reset(new std::string(base::UTF16ToUTF8(utf16)));
166 } 168 }
167 169
168 SetResult(device_info.ToValue().release()); 170 SetResult(device_info.ToValue().release());
169 AsyncWorkCompleted(); 171 AsyncWorkCompleted();
170 } 172 }
171 173
172 } // namespace extensions 174 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/usb_private/DEPS ('k') | extensions/shell/app_shell.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698