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

Side by Side Diff: device/hid/hid_service_linux.cc

Issue 947663002: Log device/hid messages to chrome://device-log. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 "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 <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/files/file.h" 12 #include "base/files/file.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/logging.h"
17 #include "base/scoped_observer.h" 16 #include "base/scoped_observer.h"
18 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_split.h" 18 #include "base/strings/string_split.h"
20 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
21 #include "base/threading/thread_restrictions.h" 20 #include "base/threading/thread_restrictions.h"
21 #include "components/device_event_log/device_event_log.h"
22 #include "device/hid/device_monitor_linux.h" 22 #include "device/hid/device_monitor_linux.h"
23 #include "device/hid/hid_connection_linux.h" 23 #include "device/hid/hid_connection_linux.h"
24 #include "device/hid/hid_device_info_linux.h" 24 #include "device/hid/hid_device_info_linux.h"
25 #include "device/udev_linux/scoped_udev.h" 25 #include "device/udev_linux/scoped_udev.h"
26 26
27 #if defined(OS_CHROMEOS) 27 #if defined(OS_CHROMEOS)
28 #include "base/sys_info.h" 28 #include "base/sys_info.h"
29 #include "chromeos/dbus/dbus_thread_manager.h" 29 #include "chromeos/dbus/dbus_thread_manager.h"
30 #include "chromeos/dbus/permission_broker_client.h" 30 #include "chromeos/dbus/permission_broker_client.h"
31 #endif // defined(OS_CHROMEOS) 31 #endif // defined(OS_CHROMEOS)
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 scoped_refptr<base::SingleThreadTaskRunner> task_runner = params->task_runner; 275 scoped_refptr<base::SingleThreadTaskRunner> task_runner = params->task_runner;
276 base::FilePath device_path(params->device_info->device_node()); 276 base::FilePath device_path(params->device_info->device_node());
277 base::File& device_file = params->device_file; 277 base::File& device_file = params->device_file;
278 int flags = 278 int flags =
279 base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_WRITE; 279 base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_WRITE;
280 device_file.Initialize(device_path, flags); 280 device_file.Initialize(device_path, flags);
281 if (!device_file.IsValid()) { 281 if (!device_file.IsValid()) {
282 base::File::Error file_error = device_file.error_details(); 282 base::File::Error file_error = device_file.error_details();
283 283
284 if (file_error == base::File::FILE_ERROR_ACCESS_DENIED) { 284 if (file_error == base::File::FILE_ERROR_ACCESS_DENIED) {
285 VLOG(1) << "Access denied opening device read-write, trying read-only."; 285 HID_LOG(EVENT)
286 << "Access denied opening device read-write, trying read-only.";
286 flags = base::File::FLAG_OPEN | base::File::FLAG_READ; 287 flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
287 device_file.Initialize(device_path, flags); 288 device_file.Initialize(device_path, flags);
288 } 289 }
289 } 290 }
290 if (!device_file.IsValid()) { 291 if (!device_file.IsValid()) {
291 LOG(ERROR) << "Failed to open '" << params->device_info->device_node() 292 HID_LOG(EVENT) << "Failed to open '" << params->device_info->device_node()
292 << "': " 293 << "': "
293 << base::File::ErrorToString(device_file.error_details()); 294 << base::File::ErrorToString(device_file.error_details());
294 task_runner->PostTask(FROM_HERE, base::Bind(params->callback, nullptr)); 295 task_runner->PostTask(FROM_HERE, base::Bind(params->callback, nullptr));
295 return; 296 return;
296 } 297 }
297 298
298 int result = fcntl(device_file.GetPlatformFile(), F_GETFL); 299 int result = fcntl(device_file.GetPlatformFile(), F_GETFL);
299 if (result == -1) { 300 if (result == -1) {
300 PLOG(ERROR) << "Failed to get flags from the device file descriptor"; 301 HID_PLOG(ERROR) << "Failed to get flags from the device file descriptor";
301 task_runner->PostTask(FROM_HERE, base::Bind(params->callback, nullptr)); 302 task_runner->PostTask(FROM_HERE, base::Bind(params->callback, nullptr));
302 return; 303 return;
303 } 304 }
304 305
305 result = fcntl(device_file.GetPlatformFile(), F_SETFL, result | O_NONBLOCK); 306 result = fcntl(device_file.GetPlatformFile(), F_SETFL, result | O_NONBLOCK);
306 if (result == -1) { 307 if (result == -1) {
307 PLOG(ERROR) << "Failed to set the non-blocking flag on the device fd"; 308 HID_PLOG(ERROR) << "Failed to set the non-blocking flag on the device fd";
308 task_runner->PostTask(FROM_HERE, base::Bind(params->callback, nullptr)); 309 task_runner->PostTask(FROM_HERE, base::Bind(params->callback, nullptr));
309 return; 310 return;
310 } 311 }
311 312
312 task_runner->PostTask(FROM_HERE, base::Bind(&HidServiceLinux::ConnectImpl, 313 task_runner->PostTask(FROM_HERE, base::Bind(&HidServiceLinux::ConnectImpl,
313 base::Passed(&params))); 314 base::Passed(&params)));
314 } 315 }
315 316
316 // static 317 // static
317 void HidServiceLinux::ConnectImpl(scoped_ptr<ConnectParams> params) { 318 void HidServiceLinux::ConnectImpl(scoped_ptr<ConnectParams> params) {
318 DCHECK(params->device_file.IsValid()); 319 DCHECK(params->device_file.IsValid());
319 params->callback.Run(make_scoped_refptr( 320 params->callback.Run(make_scoped_refptr(
320 new HidConnectionLinux(params->device_info, params->device_file.Pass(), 321 new HidConnectionLinux(params->device_info, params->device_file.Pass(),
321 params->file_task_runner))); 322 params->file_task_runner)));
322 } 323 }
323 324
324 } // namespace device 325 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698