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 device::HidDeviceInfo device_info; | 144 if (!device_manager_->GetDeviceInfo(parameters_->device_id, &device_info_)) { |
145 if (!device_manager_->GetDeviceInfo(parameters_->device_id, &device_info)) { | |
146 CompleteWithError(kErrorInvalidDeviceId); | 145 CompleteWithError(kErrorInvalidDeviceId); |
147 return; | 146 return; |
148 } | 147 } |
149 | 148 |
150 if (!device_manager_->HasPermission(extension(), device_info)) { | 149 if (!device_manager_->HasPermission(extension(), device_info_)) { |
151 LOG(WARNING) << "Insufficient permissions to access device."; | 150 LOG(WARNING) << "Insufficient permissions to access device."; |
152 CompleteWithError(kErrorPermissionDenied); | 151 CompleteWithError(kErrorPermissionDenied); |
153 return; | 152 return; |
154 } | 153 } |
155 | 154 |
| 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 |
156 HidService* hid_service = device::DeviceClient::Get()->GetHidService(); | 172 HidService* hid_service = device::DeviceClient::Get()->GetHidService(); |
157 DCHECK(hid_service); | 173 DCHECK(hid_service); |
158 scoped_refptr<HidConnection> connection = | 174 scoped_refptr<HidConnection> connection = |
159 hid_service->Connect(device_info.device_id); | 175 hid_service->Connect(device_info_.device_id); |
160 if (!connection.get()) { | 176 if (!connection.get()) { |
161 CompleteWithError(kErrorFailedToOpenDevice); | 177 CompleteWithError(kErrorFailedToOpenDevice); |
162 return; | 178 return; |
163 } | 179 } |
| 180 |
164 int connection_id = connection_manager_->Add( | 181 int connection_id = connection_manager_->Add( |
165 new HidConnectionResource(extension_->id(), connection)); | 182 new HidConnectionResource(extension_->id(), connection)); |
166 SetResult(PopulateHidConnection(connection_id, connection)); | 183 SetResult(PopulateHidConnection(connection_id, connection)); |
167 AsyncWorkCompleted(); | 184 AsyncWorkCompleted(); |
168 } | 185 } |
169 | 186 |
170 HidDisconnectFunction::HidDisconnectFunction() {} | 187 HidDisconnectFunction::HidDisconnectFunction() {} |
171 | 188 |
172 HidDisconnectFunction::~HidDisconnectFunction() {} | 189 HidDisconnectFunction::~HidDisconnectFunction() {} |
173 | 190 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 354 |
338 void HidSendFeatureReportFunction::OnFinished(bool success) { | 355 void HidSendFeatureReportFunction::OnFinished(bool success) { |
339 if (!success) { | 356 if (!success) { |
340 CompleteWithError(kErrorTransfer); | 357 CompleteWithError(kErrorTransfer); |
341 return; | 358 return; |
342 } | 359 } |
343 AsyncWorkCompleted(); | 360 AsyncWorkCompleted(); |
344 } | 361 } |
345 | 362 |
346 } // namespace extensions | 363 } // namespace extensions |
OLD | NEW |