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

Side by Side Diff: extensions/browser/api/hid/hid_api.cc

Issue 641203003: Read HID report descriptor from sysfs and request permission on connect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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/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
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
156 HidService* hid_service = device::DeviceClient::Get()->GetHidService(); 155 hid_service_ = device::DeviceClient::Get()->GetHidService();
Yoyo Zhou 2014/10/10 23:05:24 This can be inside the ifdef
157 DCHECK(hid_service); 156 DCHECK(hid_service_);
157
158 #if defined(OS_CHROMEOS)
159 hid_service_->RequestAccess(
160 device_info_.device_id,
161 base::Bind(&HidConnectFunction::OnRequestAccessComplete, this));
162 #else
163 OnRequestAccessComplete(true);
164 #endif
165 }
166
167 void HidConnectFunction::OnRequestAccessComplete(bool success) {
168 if (!success) {
169 CompleteWithError(kErrorPermissionDenied);
170 return;
171 }
172
158 scoped_refptr<HidConnection> connection = 173 scoped_refptr<HidConnection> connection =
159 hid_service->Connect(device_info.device_id); 174 hid_service_->Connect(device_info_.device_id);
160 if (!connection.get()) { 175 if (!connection.get()) {
161 CompleteWithError(kErrorFailedToOpenDevice); 176 CompleteWithError(kErrorFailedToOpenDevice);
162 return; 177 return;
163 } 178 }
179
164 int connection_id = connection_manager_->Add( 180 int connection_id = connection_manager_->Add(
165 new HidConnectionResource(extension_->id(), connection)); 181 new HidConnectionResource(extension_->id(), connection));
166 SetResult(PopulateHidConnection(connection_id, connection)); 182 SetResult(PopulateHidConnection(connection_id, connection));
167 AsyncWorkCompleted(); 183 AsyncWorkCompleted();
168 } 184 }
169 185
170 HidDisconnectFunction::HidDisconnectFunction() {} 186 HidDisconnectFunction::HidDisconnectFunction() {}
171 187
172 HidDisconnectFunction::~HidDisconnectFunction() {} 188 HidDisconnectFunction::~HidDisconnectFunction() {}
173 189
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 353
338 void HidSendFeatureReportFunction::OnFinished(bool success) { 354 void HidSendFeatureReportFunction::OnFinished(bool success) {
339 if (!success) { 355 if (!success) {
340 CompleteWithError(kErrorTransfer); 356 CompleteWithError(kErrorTransfer);
341 return; 357 return;
342 } 358 }
343 AsyncWorkCompleted(); 359 AsyncWorkCompleted();
344 } 360 }
345 361
346 } // namespace extensions 362 } // namespace extensions
OLDNEW
« device/hid/hid_service_linux.cc ('K') | « extensions/browser/api/hid/hid_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698