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> |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 connection->Read(base::Bind(&HidReceiveFunction::OnFinished, this)); | 283 connection->Read(base::Bind(&HidReceiveFunction::OnFinished, this)); |
284 } | 284 } |
285 | 285 |
286 void HidReceiveFunction::OnFinished(bool success, | 286 void HidReceiveFunction::OnFinished(bool success, |
287 scoped_refptr<net::IOBuffer> buffer, | 287 scoped_refptr<net::IOBuffer> buffer, |
288 size_t size) { | 288 size_t size) { |
289 if (success) { | 289 if (success) { |
290 DCHECK_GE(size, 1u); | 290 DCHECK_GE(size, 1u); |
291 int report_id = reinterpret_cast<uint8_t*>(buffer->data())[0]; | 291 int report_id = reinterpret_cast<uint8_t*>(buffer->data())[0]; |
292 | 292 |
293 Respond( | 293 Respond(TwoArguments(base::MakeUnique<base::FundamentalValue>(report_id), |
294 TwoArguments(base::MakeUnique<base::FundamentalValue>(report_id), | 294 base::BinaryValue::CreateWithCopiedBuffer( |
295 base::WrapUnique(base::BinaryValue::CreateWithCopiedBuffer( | 295 buffer->data() + 1, size - 1))); |
296 buffer->data() + 1, size - 1)))); | |
297 } else { | 296 } else { |
298 Respond(Error(kErrorTransfer)); | 297 Respond(Error(kErrorTransfer)); |
299 } | 298 } |
300 } | 299 } |
301 | 300 |
302 HidSendFunction::HidSendFunction() {} | 301 HidSendFunction::HidSendFunction() {} |
303 | 302 |
304 HidSendFunction::~HidSendFunction() {} | 303 HidSendFunction::~HidSendFunction() {} |
305 | 304 |
306 bool HidSendFunction::ValidateParameters() { | 305 bool HidSendFunction::ValidateParameters() { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 connection->GetFeatureReport( | 342 connection->GetFeatureReport( |
344 static_cast<uint8_t>(parameters_->report_id), | 343 static_cast<uint8_t>(parameters_->report_id), |
345 base::Bind(&HidReceiveFeatureReportFunction::OnFinished, this)); | 344 base::Bind(&HidReceiveFeatureReportFunction::OnFinished, this)); |
346 } | 345 } |
347 | 346 |
348 void HidReceiveFeatureReportFunction::OnFinished( | 347 void HidReceiveFeatureReportFunction::OnFinished( |
349 bool success, | 348 bool success, |
350 scoped_refptr<net::IOBuffer> buffer, | 349 scoped_refptr<net::IOBuffer> buffer, |
351 size_t size) { | 350 size_t size) { |
352 if (success) { | 351 if (success) { |
353 Respond(OneArgument(base::WrapUnique( | 352 Respond(OneArgument( |
354 base::BinaryValue::CreateWithCopiedBuffer(buffer->data(), size)))); | 353 base::BinaryValue::CreateWithCopiedBuffer(buffer->data(), size))); |
355 } else { | 354 } else { |
356 Respond(Error(kErrorTransfer)); | 355 Respond(Error(kErrorTransfer)); |
357 } | 356 } |
358 } | 357 } |
359 | 358 |
360 HidSendFeatureReportFunction::HidSendFeatureReportFunction() {} | 359 HidSendFeatureReportFunction::HidSendFeatureReportFunction() {} |
361 | 360 |
362 HidSendFeatureReportFunction::~HidSendFeatureReportFunction() {} | 361 HidSendFeatureReportFunction::~HidSendFeatureReportFunction() {} |
363 | 362 |
364 bool HidSendFeatureReportFunction::ValidateParameters() { | 363 bool HidSendFeatureReportFunction::ValidateParameters() { |
(...skipping 16 matching lines...) Expand all Loading... |
381 | 380 |
382 void HidSendFeatureReportFunction::OnFinished(bool success) { | 381 void HidSendFeatureReportFunction::OnFinished(bool success) { |
383 if (success) { | 382 if (success) { |
384 Respond(NoArguments()); | 383 Respond(NoArguments()); |
385 } else { | 384 } else { |
386 Respond(Error(kErrorTransfer)); | 385 Respond(Error(kErrorTransfer)); |
387 } | 386 } |
388 } | 387 } |
389 | 388 |
390 } // namespace extensions | 389 } // namespace extensions |
OLD | NEW |