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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 134 |
135 HidConnectFunction::~HidConnectFunction() {} | 135 HidConnectFunction::~HidConnectFunction() {} |
136 | 136 |
137 bool HidConnectFunction::Prepare() { | 137 bool HidConnectFunction::Prepare() { |
138 parameters_ = hid::Connect::Params::Create(*args_); | 138 parameters_ = hid::Connect::Params::Create(*args_); |
139 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 139 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
140 return true; | 140 return true; |
141 } | 141 } |
142 | 142 |
143 void HidConnectFunction::AsyncWorkStart() { | 143 void HidConnectFunction::AsyncWorkStart() { |
144 if (!device_manager_->GetDeviceInfo(parameters_->device_id, &device_info_)) { | 144 HidDeviceInfo device_info; |
| 145 if (!device_manager_->GetDeviceInfo(parameters_->device_id, &device_info)) { |
145 CompleteWithError(kErrorInvalidDeviceId); | 146 CompleteWithError(kErrorInvalidDeviceId); |
146 return; | 147 return; |
147 } | 148 } |
148 | 149 |
149 if (!device_manager_->HasPermission(extension(), device_info_)) { | 150 if (!device_manager_->HasPermission(extension(), device_info)) { |
150 LOG(WARNING) << "Insufficient permissions to access device."; | 151 LOG(WARNING) << "Insufficient permissions to access device."; |
151 CompleteWithError(kErrorPermissionDenied); | 152 CompleteWithError(kErrorPermissionDenied); |
152 return; | 153 return; |
153 } | 154 } |
154 | 155 |
155 #if defined(OS_CHROMEOS) | |
156 HidService* hid_service = device::DeviceClient::Get()->GetHidService(); | |
157 DCHECK(hid_service); | |
158 hid_service->RequestAccess( | |
159 device_info_.device_id, | |
160 base::Bind(&HidConnectFunction::OnRequestAccessComplete, this)); | |
161 #else | |
162 OnRequestAccessComplete(true); | |
163 #endif | |
164 } | |
165 | |
166 void HidConnectFunction::OnRequestAccessComplete(bool success) { | |
167 if (!success) { | |
168 CompleteWithError(kErrorPermissionDenied); | |
169 return; | |
170 } | |
171 | |
172 HidService* hid_service = device::DeviceClient::Get()->GetHidService(); | 156 HidService* hid_service = device::DeviceClient::Get()->GetHidService(); |
173 DCHECK(hid_service); | 157 DCHECK(hid_service); |
174 scoped_refptr<HidConnection> connection = | 158 |
175 hid_service->Connect(device_info_.device_id); | 159 hid_service->Connect( |
| 160 device_info.device_id, |
| 161 base::Bind(&HidConnectFunction::OnConnectComplete, this)); |
| 162 } |
| 163 |
| 164 void HidConnectFunction::OnConnectComplete( |
| 165 scoped_refptr<HidConnection> connection) { |
176 if (!connection.get()) { | 166 if (!connection.get()) { |
177 CompleteWithError(kErrorFailedToOpenDevice); | 167 CompleteWithError(kErrorFailedToOpenDevice); |
178 return; | 168 return; |
179 } | 169 } |
180 | 170 |
181 int connection_id = connection_manager_->Add( | 171 int connection_id = connection_manager_->Add( |
182 new HidConnectionResource(extension_->id(), connection)); | 172 new HidConnectionResource(extension_->id(), connection)); |
183 SetResult(PopulateHidConnection(connection_id, connection)); | 173 SetResult(PopulateHidConnection(connection_id, connection)); |
184 AsyncWorkCompleted(); | 174 AsyncWorkCompleted(); |
185 } | 175 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 | 344 |
355 void HidSendFeatureReportFunction::OnFinished(bool success) { | 345 void HidSendFeatureReportFunction::OnFinished(bool success) { |
356 if (!success) { | 346 if (!success) { |
357 CompleteWithError(kErrorTransfer); | 347 CompleteWithError(kErrorTransfer); |
358 return; | 348 return; |
359 } | 349 } |
360 AsyncWorkCompleted(); | 350 AsyncWorkCompleted(); |
361 } | 351 } |
362 | 352 |
363 } // namespace extensions | 353 } // namespace extensions |
OLD | NEW |