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

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

Issue 771393002: Migrate HidServiceLinux and HidConnectionLinux to BrowserThread::UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Switched to an embedded thread checker. Created 6 years 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 | « chrome/browser/chrome_device_client.cc ('k') | device/hid/hid_connection_linux.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 #ifndef DEVICE_HID_HID_CONNECTION_LINUX_H_ 5 #ifndef DEVICE_HID_HID_CONNECTION_LINUX_H_
6 #define DEVICE_HID_HID_CONNECTION_LINUX_H_ 6 #define DEVICE_HID_HID_CONNECTION_LINUX_H_
7 7
8 #include <queue> 8 #include <queue>
9 9
10 #include "base/files/file.h" 10 #include "base/files/file.h"
11 #include "base/message_loop/message_pump_libevent.h" 11 #include "base/memory/weak_ptr.h"
12 #include "device/hid/hid_connection.h" 12 #include "device/hid/hid_connection.h"
13 13
14 namespace base {
15 class SingleThreadTaskRunner;
16 }
17
14 namespace device { 18 namespace device {
15 19
16 class HidConnectionLinux : public HidConnection, 20 class HidConnectionLinux : public HidConnection {
17 public base::MessagePumpLibevent::Watcher {
18 public: 21 public:
19 HidConnectionLinux(HidDeviceInfo device_info, std::string dev_node); 22 HidConnectionLinux(
23 HidDeviceInfo device_info,
24 base::File device_file,
25 scoped_refptr<base::SingleThreadTaskRunner> file_thread_runner);
20 26
21 private: 27 private:
28 class Helper;
29 friend class Helper;
22 friend class base::RefCountedThreadSafe<HidConnectionLinux>; 30 friend class base::RefCountedThreadSafe<HidConnectionLinux>;
31
32 typedef base::Callback<void(ssize_t)> InternalWriteCallback;
33 typedef base::Callback<void(int)> IoctlCallback;
34
23 ~HidConnectionLinux() override; 35 ~HidConnectionLinux() override;
24 36
25 // HidConnection implementation. 37 // HidConnection implementation.
26 void PlatformClose() override; 38 void PlatformClose() override;
27 void PlatformRead(const ReadCallback& callback) override; 39 void PlatformRead(const ReadCallback& callback) override;
28 void PlatformWrite(scoped_refptr<net::IOBuffer> buffer, 40 void PlatformWrite(scoped_refptr<net::IOBuffer> buffer,
29 size_t size, 41 size_t size,
30 const WriteCallback& callback) override; 42 const WriteCallback& callback) override;
31 void PlatformGetFeatureReport(uint8_t report_id, 43 void PlatformGetFeatureReport(uint8_t report_id,
32 const ReadCallback& callback) override; 44 const ReadCallback& callback) override;
33 void PlatformSendFeatureReport(scoped_refptr<net::IOBuffer> buffer, 45 void PlatformSendFeatureReport(scoped_refptr<net::IOBuffer> buffer,
34 size_t size, 46 size_t size,
35 const WriteCallback& callback) override; 47 const WriteCallback& callback) override;
36 48
37 // base::MessagePumpLibevent::Watcher implementation. 49 // Callbacks for blocking operations run on the FILE thread.
38 void OnFileCanReadWithoutBlocking(int fd) override; 50 void FinishWrite(size_t expected_size,
39 void OnFileCanWriteWithoutBlocking(int fd) override; 51 const WriteCallback& callback,
52 ssize_t result);
53 void FinishGetFeatureReport(uint8_t report_id,
54 scoped_refptr<net::IOBuffer> buffer,
55 const ReadCallback& callback,
56 int result);
57 void FinishSendFeatureReport(const WriteCallback& callback, int result);
40 58
41 void Disconnect(); 59 // Starts the FileDescriptorWatcher that reads input events from the device.
60 // Must be called on a thread that has a base::MessageLoopForIO.
61 void StartHelper(base::WeakPtr<HidConnectionLinux> weak_ptr);
42 62
43 void Flush(); 63 // Writes to the device. This operation may block.
64 static void BlockingWrite(
65 base::PlatformFile platform_file,
66 scoped_refptr<net::IOBuffer> buffer,
67 size_t size,
68 const InternalWriteCallback& callback,
69 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
70 // Performs an ioctl on the device. This operation may block.
71 static void BlockingIoctl(
72 base::PlatformFile platform_file,
73 int request,
74 scoped_refptr<net::IOBuffer> buffer,
75 const IoctlCallback& callback,
76 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
77
78 // Closes the device file descriptor. Must be called on the FILE thread.
79 static void CloseDevice(base::File device_file);
80
44 void ProcessInputReport(scoped_refptr<net::IOBuffer> buffer, size_t size); 81 void ProcessInputReport(scoped_refptr<net::IOBuffer> buffer, size_t size);
45 void ProcessReadQueue(); 82 void ProcessReadQueue();
46 83
47 base::File device_file_; 84 base::File device_file_;
48 base::MessagePumpLibevent::FileDescriptorWatcher device_file_watcher_; 85 scoped_ptr<Helper> helper_;
86
87 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
88 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
49 89
50 std::queue<PendingHidReport> pending_reports_; 90 std::queue<PendingHidReport> pending_reports_;
51 std::queue<PendingHidRead> pending_reads_; 91 std::queue<PendingHidRead> pending_reads_;
52 92
93 base::WeakPtrFactory<HidConnectionLinux> weak_factory_;
94
53 DISALLOW_COPY_AND_ASSIGN(HidConnectionLinux); 95 DISALLOW_COPY_AND_ASSIGN(HidConnectionLinux);
54 }; 96 };
55 97
56 } // namespace device 98 } // namespace device
57 99
58 #endif // DEVICE_HID_HID_CONNECTION_LINUX_H_ 100 #endif // DEVICE_HID_HID_CONNECTION_LINUX_H_
OLDNEW
« no previous file with comments | « chrome/browser/chrome_device_client.cc ('k') | device/hid/hid_connection_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698