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

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

Issue 240263003: HID : read-only device access fallback when read/write fails (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: oops Created 6 years, 8 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
« no previous file with comments | « no previous file | device/hid/hid_connection_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_connection_linux.h" 5 #include "device/hid/hid_connection_linux.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <libudev.h> 9 #include <libudev.h>
10 #include <linux/hidraw.h> 10 #include <linux/hidraw.h>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 LOG(ERROR) << "Cannot open HID device as hidraw device."; 57 LOG(ERROR) << "Cannot open HID device as hidraw device.";
58 return; 58 return;
59 } 59 }
60 60
61 int flags = base::File::FLAG_OPEN | 61 int flags = base::File::FLAG_OPEN |
62 base::File::FLAG_READ | 62 base::File::FLAG_READ |
63 base::File::FLAG_WRITE; 63 base::File::FLAG_WRITE;
64 64
65 base::File device_file(base::FilePath(dev_node), flags); 65 base::File device_file(base::FilePath(dev_node), flags);
66 if (!device_file.IsValid()) { 66 if (!device_file.IsValid()) {
67 LOG(ERROR) << device_file.error_details(); 67 base::File::Error file_error = device_file.error_details();
68 return; 68
69 if (file_error == base::File::FILE_ERROR_ACCESS_DENIED) {
70 flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
71
72 base::File device_file(base::FilePath(dev_node), flags);
73 if (!device_file.IsValid()) {
74 LOG(ERROR) << device_file.error_details();
75 return;
76 }
77 } else {
78 LOG(ERROR) << file_error;
79 return;
80 }
69 } 81 }
70 if (fcntl(device_file.GetPlatformFile(), F_SETFL, 82 if (fcntl(device_file.GetPlatformFile(), F_SETFL,
71 fcntl(device_file.GetPlatformFile(), F_GETFL) | O_NONBLOCK)) { 83 fcntl(device_file.GetPlatformFile(), F_GETFL) | O_NONBLOCK)) {
72 PLOG(ERROR) << "Failed to set non-blocking flag to device file."; 84 PLOG(ERROR) << "Failed to set non-blocking flag to device file.";
73 return; 85 return;
74 } 86 }
75 device_file_ = device_file.Pass(); 87 device_file_ = device_file.Pass();
76 88
77 if (!base::MessageLoopForIO::current()->WatchFileDescriptor( 89 if (!base::MessageLoopForIO::current()->WatchFileDescriptor(
78 device_file_.GetPlatformFile(), 90 device_file_.GetPlatformFile(),
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 return true; 250 return true;
239 } 251 }
240 } 252 }
241 } 253 }
242 254
243 return false; 255 return false;
244 } 256 }
245 257
246 } // namespace device 258 } // namespace device
247 259
OLDNEW
« no previous file with comments | « no previous file | device/hid/hid_connection_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698