| 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 "device/hid/hid_service_linux.h" | 5 #include "device/hid/hid_service_linux.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> |
| 11 | 12 |
| 12 #include "base/bind.h" | 13 #include "base/bind.h" |
| 13 #include "base/files/file.h" | 14 #include "base/files/file.h" |
| 14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
| 16 #include "base/location.h" | 17 #include "base/location.h" |
| 17 #include "base/macros.h" | 18 #include "base/macros.h" |
| 18 #include "base/scoped_observer.h" | 19 #include "base/scoped_observer.h" |
| 19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_split.h" | 21 #include "base/strings/string_split.h" |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 } | 304 } |
| 304 } | 305 } |
| 305 if (!device_file.IsValid()) { | 306 if (!device_file.IsValid()) { |
| 306 HID_LOG(EVENT) << "Failed to open '" << params->device_info->device_node() | 307 HID_LOG(EVENT) << "Failed to open '" << params->device_info->device_node() |
| 307 << "': " | 308 << "': " |
| 308 << base::File::ErrorToString(device_file.error_details()); | 309 << base::File::ErrorToString(device_file.error_details()); |
| 309 task_runner->PostTask(FROM_HERE, base::Bind(params->callback, nullptr)); | 310 task_runner->PostTask(FROM_HERE, base::Bind(params->callback, nullptr)); |
| 310 return; | 311 return; |
| 311 } | 312 } |
| 312 | 313 |
| 313 FinishOpen(params.Pass()); | 314 FinishOpen(std::move(params)); |
| 314 } | 315 } |
| 315 | 316 |
| 316 #endif // defined(OS_CHROMEOS) | 317 #endif // defined(OS_CHROMEOS) |
| 317 | 318 |
| 318 // static | 319 // static |
| 319 void HidServiceLinux::FinishOpen(scoped_ptr<ConnectParams> params) { | 320 void HidServiceLinux::FinishOpen(scoped_ptr<ConnectParams> params) { |
| 320 base::ThreadRestrictions::AssertIOAllowed(); | 321 base::ThreadRestrictions::AssertIOAllowed(); |
| 321 scoped_refptr<base::SingleThreadTaskRunner> task_runner = params->task_runner; | 322 scoped_refptr<base::SingleThreadTaskRunner> task_runner = params->task_runner; |
| 322 | 323 |
| 323 if (!base::SetNonBlocking(params->device_file.GetPlatformFile())) { | 324 if (!base::SetNonBlocking(params->device_file.GetPlatformFile())) { |
| 324 HID_PLOG(ERROR) << "Failed to set the non-blocking flag on the device fd"; | 325 HID_PLOG(ERROR) << "Failed to set the non-blocking flag on the device fd"; |
| 325 task_runner->PostTask(FROM_HERE, base::Bind(params->callback, nullptr)); | 326 task_runner->PostTask(FROM_HERE, base::Bind(params->callback, nullptr)); |
| 326 return; | 327 return; |
| 327 } | 328 } |
| 328 | 329 |
| 329 task_runner->PostTask( | 330 task_runner->PostTask( |
| 330 FROM_HERE, | 331 FROM_HERE, |
| 331 base::Bind(&HidServiceLinux::CreateConnection, base::Passed(¶ms))); | 332 base::Bind(&HidServiceLinux::CreateConnection, base::Passed(¶ms))); |
| 332 } | 333 } |
| 333 | 334 |
| 334 // static | 335 // static |
| 335 void HidServiceLinux::CreateConnection(scoped_ptr<ConnectParams> params) { | 336 void HidServiceLinux::CreateConnection(scoped_ptr<ConnectParams> params) { |
| 336 DCHECK(params->device_file.IsValid()); | 337 DCHECK(params->device_file.IsValid()); |
| 337 params->callback.Run(make_scoped_refptr( | 338 params->callback.Run(make_scoped_refptr(new HidConnectionLinux( |
| 338 new HidConnectionLinux(params->device_info, params->device_file.Pass(), | 339 params->device_info, std::move(params->device_file), |
| 339 params->file_task_runner))); | 340 params->file_task_runner))); |
| 340 } | 341 } |
| 341 | 342 |
| 342 } // namespace device | 343 } // namespace device |
| OLD | NEW |