OLD | NEW |
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/hid/hid_api.h" | 5 #include "extensions/browser/api/hid/hid_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "device/core/device_client.h" | 10 #include "device/core/device_client.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 if (!device_manager) { | 114 if (!device_manager) { |
115 return RespondNow(Error(kErrorServiceUnavailable)); | 115 return RespondNow(Error(kErrorServiceUnavailable)); |
116 } | 116 } |
117 | 117 |
118 connection_manager_ = | 118 connection_manager_ = |
119 ApiResourceManager<HidConnectionResource>::Get(browser_context()); | 119 ApiResourceManager<HidConnectionResource>::Get(browser_context()); |
120 if (!connection_manager_) { | 120 if (!connection_manager_) { |
121 return RespondNow(Error(kErrorServiceUnavailable)); | 121 return RespondNow(Error(kErrorServiceUnavailable)); |
122 } | 122 } |
123 | 123 |
124 HidDeviceInfo device_info; | 124 scoped_refptr<HidDeviceInfo> device_info = |
125 if (!device_manager->GetDeviceInfo(parameters->device_id, &device_info)) { | 125 device_manager->GetDeviceInfo(parameters->device_id); |
| 126 if (!device_info) { |
126 return RespondNow(Error(kErrorInvalidDeviceId)); | 127 return RespondNow(Error(kErrorInvalidDeviceId)); |
127 } | 128 } |
128 | 129 |
129 if (!HidDeviceManager::HasPermission(extension(), device_info)) { | 130 if (!HidDeviceManager::HasPermission(extension(), device_info)) { |
130 return RespondNow(Error(kErrorPermissionDenied)); | 131 return RespondNow(Error(kErrorPermissionDenied)); |
131 } | 132 } |
132 | 133 |
133 HidService* hid_service = device::DeviceClient::Get()->GetHidService(); | 134 HidService* hid_service = device::DeviceClient::Get()->GetHidService(); |
134 if (!hid_service) { | 135 if (!hid_service) { |
135 return RespondNow(Error(kErrorServiceUnavailable)); | 136 return RespondNow(Error(kErrorServiceUnavailable)); |
136 } | 137 } |
137 | 138 |
138 hid_service->Connect( | 139 hid_service->Connect( |
139 device_info.device_id, | 140 device_info->device_id(), |
140 base::Bind(&HidConnectFunction::OnConnectComplete, this)); | 141 base::Bind(&HidConnectFunction::OnConnectComplete, this)); |
141 return RespondLater(); | 142 return RespondLater(); |
142 } | 143 } |
143 | 144 |
144 void HidConnectFunction::OnConnectComplete( | 145 void HidConnectFunction::OnConnectComplete( |
145 scoped_refptr<HidConnection> connection) { | 146 scoped_refptr<HidConnection> connection) { |
146 if (!connection.get()) { | 147 if (!connection.get()) { |
147 Respond(Error(kErrorFailedToOpenDevice)); | 148 Respond(Error(kErrorFailedToOpenDevice)); |
148 return; | 149 return; |
149 } | 150 } |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 320 |
320 void HidSendFeatureReportFunction::OnFinished(bool success) { | 321 void HidSendFeatureReportFunction::OnFinished(bool success) { |
321 if (success) { | 322 if (success) { |
322 Respond(NoArguments()); | 323 Respond(NoArguments()); |
323 } else { | 324 } else { |
324 Respond(Error(kErrorTransfer)); | 325 Respond(Error(kErrorTransfer)); |
325 } | 326 } |
326 } | 327 } |
327 | 328 |
328 } // namespace extensions | 329 } // namespace extensions |
OLD | NEW |