| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/values.h" |
| 14 #include "device/base/device_client.h" | 15 #include "device/base/device_client.h" |
| 15 #include "device/hid/hid_connection.h" | 16 #include "device/hid/hid_connection.h" |
| 16 #include "device/hid/hid_device_filter.h" | 17 #include "device/hid/hid_device_filter.h" |
| 17 #include "device/hid/hid_device_info.h" | 18 #include "device/hid/hid_device_info.h" |
| 18 #include "device/hid/hid_service.h" | 19 #include "device/hid/hid_service.h" |
| 19 #include "extensions/browser/api/api_resource_manager.h" | 20 #include "extensions/browser/api/api_resource_manager.h" |
| 20 #include "extensions/browser/api/device_permissions_prompt.h" | 21 #include "extensions/browser/api/device_permissions_prompt.h" |
| 21 #include "extensions/browser/api/extensions_api_client.h" | 22 #include "extensions/browser/api/extensions_api_client.h" |
| 22 #include "extensions/common/api/hid.h" | 23 #include "extensions/common/api/hid.h" |
| 23 #include "net/base/io_buffer.h" | 24 #include "net/base/io_buffer.h" |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 connection->Read(base::Bind(&HidReceiveFunction::OnFinished, this)); | 262 connection->Read(base::Bind(&HidReceiveFunction::OnFinished, this)); |
| 262 } | 263 } |
| 263 | 264 |
| 264 void HidReceiveFunction::OnFinished(bool success, | 265 void HidReceiveFunction::OnFinished(bool success, |
| 265 scoped_refptr<net::IOBuffer> buffer, | 266 scoped_refptr<net::IOBuffer> buffer, |
| 266 size_t size) { | 267 size_t size) { |
| 267 if (success) { | 268 if (success) { |
| 268 DCHECK_GE(size, 1u); | 269 DCHECK_GE(size, 1u); |
| 269 int report_id = reinterpret_cast<uint8_t*>(buffer->data())[0]; | 270 int report_id = reinterpret_cast<uint8_t*>(buffer->data())[0]; |
| 270 | 271 |
| 271 Respond(TwoArguments(base::MakeUnique<base::Value>(report_id), | 272 Respond(TwoArguments( |
| 272 base::BinaryValue::CreateWithCopiedBuffer( | 273 base::MakeUnique<base::Value>(report_id), |
| 273 buffer->data() + 1, size - 1))); | 274 base::Value::CreateWithCopiedBuffer(buffer->data() + 1, size - 1))); |
| 274 } else { | 275 } else { |
| 275 Respond(Error(kErrorTransfer)); | 276 Respond(Error(kErrorTransfer)); |
| 276 } | 277 } |
| 277 } | 278 } |
| 278 | 279 |
| 279 HidSendFunction::HidSendFunction() {} | 280 HidSendFunction::HidSendFunction() {} |
| 280 | 281 |
| 281 HidSendFunction::~HidSendFunction() {} | 282 HidSendFunction::~HidSendFunction() {} |
| 282 | 283 |
| 283 bool HidSendFunction::ReadParameters() { | 284 bool HidSendFunction::ReadParameters() { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 connection->GetFeatureReport( | 323 connection->GetFeatureReport( |
| 323 static_cast<uint8_t>(parameters_->report_id), | 324 static_cast<uint8_t>(parameters_->report_id), |
| 324 base::Bind(&HidReceiveFeatureReportFunction::OnFinished, this)); | 325 base::Bind(&HidReceiveFeatureReportFunction::OnFinished, this)); |
| 325 } | 326 } |
| 326 | 327 |
| 327 void HidReceiveFeatureReportFunction::OnFinished( | 328 void HidReceiveFeatureReportFunction::OnFinished( |
| 328 bool success, | 329 bool success, |
| 329 scoped_refptr<net::IOBuffer> buffer, | 330 scoped_refptr<net::IOBuffer> buffer, |
| 330 size_t size) { | 331 size_t size) { |
| 331 if (success) { | 332 if (success) { |
| 332 Respond(OneArgument( | 333 Respond( |
| 333 base::BinaryValue::CreateWithCopiedBuffer(buffer->data(), size))); | 334 OneArgument(base::Value::CreateWithCopiedBuffer(buffer->data(), size))); |
| 334 } else { | 335 } else { |
| 335 Respond(Error(kErrorTransfer)); | 336 Respond(Error(kErrorTransfer)); |
| 336 } | 337 } |
| 337 } | 338 } |
| 338 | 339 |
| 339 HidSendFeatureReportFunction::HidSendFeatureReportFunction() {} | 340 HidSendFeatureReportFunction::HidSendFeatureReportFunction() {} |
| 340 | 341 |
| 341 HidSendFeatureReportFunction::~HidSendFeatureReportFunction() {} | 342 HidSendFeatureReportFunction::~HidSendFeatureReportFunction() {} |
| 342 | 343 |
| 343 bool HidSendFeatureReportFunction::ReadParameters() { | 344 bool HidSendFeatureReportFunction::ReadParameters() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 361 | 362 |
| 362 void HidSendFeatureReportFunction::OnFinished(bool success) { | 363 void HidSendFeatureReportFunction::OnFinished(bool success) { |
| 363 if (success) { | 364 if (success) { |
| 364 Respond(NoArguments()); | 365 Respond(NoArguments()); |
| 365 } else { | 366 } else { |
| 366 Respond(Error(kErrorTransfer)); | 367 Respond(Error(kErrorTransfer)); |
| 367 } | 368 } |
| 368 } | 369 } |
| 369 | 370 |
| 370 } // namespace extensions | 371 } // namespace extensions |
| OLD | NEW |