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

Side by Side Diff: device/hid/hid_connection_mac.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 (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_mac.h" 5 #include "device/hid/hid_connection_mac.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
13 #include "components/device_event_log/device_event_log.h"
13 #include "device/hid/hid_connection_mac.h" 14 #include "device/hid/hid_connection_mac.h"
14 15
15 namespace device { 16 namespace device {
16 17
17 HidConnectionMac::HidConnectionMac( 18 HidConnectionMac::HidConnectionMac(
18 IOHIDDeviceRef device, 19 IOHIDDeviceRef device,
19 scoped_refptr<HidDeviceInfo> device_info, 20 scoped_refptr<HidDeviceInfo> device_info,
20 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) 21 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner)
21 : HidConnection(device_info), 22 : HidConnection(device_info),
22 device_(device, base::scoped_policy::RETAIN), 23 device_(device, base::scoped_policy::RETAIN),
(...skipping 29 matching lines...) Expand all
52 IOHIDDeviceRegisterInputReportCallback( 53 IOHIDDeviceRegisterInputReportCallback(
53 device_.get(), &inbound_buffer_[0], inbound_buffer_.size(), NULL, this); 54 device_.get(), &inbound_buffer_[0], inbound_buffer_.size(), NULL, this);
54 // Release the reference taken when this callback was registered. 55 // Release the reference taken when this callback was registered.
55 Release(); 56 Release();
56 } 57 }
57 58
58 IOHIDDeviceUnscheduleFromRunLoop( 59 IOHIDDeviceUnscheduleFromRunLoop(
59 device_.get(), CFRunLoopGetMain(), kCFRunLoopDefaultMode); 60 device_.get(), CFRunLoopGetMain(), kCFRunLoopDefaultMode);
60 IOReturn result = IOHIDDeviceClose(device_.get(), 0); 61 IOReturn result = IOHIDDeviceClose(device_.get(), 0);
61 if (result != kIOReturnSuccess) { 62 if (result != kIOReturnSuccess) {
62 VLOG(1) << "Failed to close HID device: " 63 HID_LOG(EVENT) << "Failed to close HID device: " << base::StringPrintf(
63 << base::StringPrintf("0x%04x", result); 64 "0x%04x", result);
stevenjb 2015/02/23 21:45:29 nit: We do this a lot here, maybe wrap the StringP
Reilly Grant (use Gerrit) 2015/02/23 22:40:38 Done.
64 } 65 }
65 66
66 while (!pending_reads_.empty()) { 67 while (!pending_reads_.empty()) {
67 pending_reads_.front().callback.Run(false, NULL, 0); 68 pending_reads_.front().callback.Run(false, NULL, 0);
68 pending_reads_.pop(); 69 pending_reads_.pop();
69 } 70 }
70 } 71 }
71 72
72 void HidConnectionMac::PlatformRead(const ReadCallback& callback) { 73 void HidConnectionMac::PlatformRead(const ReadCallback& callback) {
73 DCHECK(thread_checker().CalledOnValidThread()); 74 DCHECK(thread_checker().CalledOnValidThread());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // static 114 // static
114 void HidConnectionMac::InputReportCallback(void* context, 115 void HidConnectionMac::InputReportCallback(void* context,
115 IOReturn result, 116 IOReturn result,
116 void* sender, 117 void* sender,
117 IOHIDReportType type, 118 IOHIDReportType type,
118 uint32_t report_id, 119 uint32_t report_id,
119 uint8_t* report_bytes, 120 uint8_t* report_bytes,
120 CFIndex report_length) { 121 CFIndex report_length) {
121 HidConnectionMac* connection = static_cast<HidConnectionMac*>(context); 122 HidConnectionMac* connection = static_cast<HidConnectionMac*>(context);
122 if (result != kIOReturnSuccess) { 123 if (result != kIOReturnSuccess) {
123 VLOG(1) << "Failed to read input report: " 124 HID_LOG(EVENT) << "Failed to read input report: " << base::StringPrintf(
124 << base::StringPrintf("0x%08x", result); 125 "0x%08x", result);
125 return; 126 return;
126 } 127 }
127 128
128 scoped_refptr<net::IOBufferWithSize> buffer; 129 scoped_refptr<net::IOBufferWithSize> buffer;
129 if (connection->device_info()->has_report_id()) { 130 if (connection->device_info()->has_report_id()) {
130 // report_id is already contained in report_bytes 131 // report_id is already contained in report_bytes
131 buffer = new net::IOBufferWithSize(report_length); 132 buffer = new net::IOBufferWithSize(report_length);
132 memcpy(buffer->data(), report_bytes, report_length); 133 memcpy(buffer->data(), report_bytes, report_length);
133 } else { 134 } else {
134 buffer = new net::IOBufferWithSize(report_length + 1); 135 buffer = new net::IOBufferWithSize(report_length + 1);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 report_id, 180 report_id,
180 reinterpret_cast<uint8_t*>(buffer->data()), 181 reinterpret_cast<uint8_t*>(buffer->data()),
181 &report_size); 182 &report_size);
182 if (result == kIOReturnSuccess) { 183 if (result == kIOReturnSuccess) {
183 task_runner_->PostTask( 184 task_runner_->PostTask(
184 FROM_HERE, 185 FROM_HERE,
185 base::Bind(&HidConnectionMac::ReturnAsyncResult, 186 base::Bind(&HidConnectionMac::ReturnAsyncResult,
186 this, 187 this,
187 base::Bind(callback, true, buffer, report_size))); 188 base::Bind(callback, true, buffer, report_size)));
188 } else { 189 } else {
189 VLOG(1) << "Failed to get feature report: " 190 HID_LOG(EVENT) << "Failed to get feature report: " << base::StringPrintf(
190 << base::StringPrintf("0x%08x", result); 191 "0x%08x", result);
191 task_runner_->PostTask(FROM_HERE, 192 task_runner_->PostTask(FROM_HERE,
192 base::Bind(&HidConnectionMac::ReturnAsyncResult, 193 base::Bind(&HidConnectionMac::ReturnAsyncResult,
193 this, 194 this,
194 base::Bind(callback, false, nullptr, 0))); 195 base::Bind(callback, false, nullptr, 0)));
195 } 196 }
196 } 197 }
197 198
198 void HidConnectionMac::SetReportAsync(IOHIDReportType report_type, 199 void HidConnectionMac::SetReportAsync(IOHIDReportType report_type,
199 scoped_refptr<net::IOBuffer> buffer, 200 scoped_refptr<net::IOBuffer> buffer,
200 size_t size, 201 size_t size,
(...skipping 14 matching lines...) Expand all
215 // of this function and believe it is a simple enough wrapper around the 216 // of this function and believe it is a simple enough wrapper around the
216 // kernel API that this is safe. 217 // kernel API that this is safe.
217 IOReturn result = 218 IOReturn result =
218 IOHIDDeviceSetReport(device_.get(), report_type, report_id, data, size); 219 IOHIDDeviceSetReport(device_.get(), report_type, report_id, data, size);
219 if (result == kIOReturnSuccess) { 220 if (result == kIOReturnSuccess) {
220 task_runner_->PostTask(FROM_HERE, 221 task_runner_->PostTask(FROM_HERE,
221 base::Bind(&HidConnectionMac::ReturnAsyncResult, 222 base::Bind(&HidConnectionMac::ReturnAsyncResult,
222 this, 223 this,
223 base::Bind(callback, true))); 224 base::Bind(callback, true)));
224 } else { 225 } else {
225 VLOG(1) << "Failed to set report: " << base::StringPrintf("0x%08x", result); 226 HID_LOG(EVENT) << "Failed to set report: " << base::StringPrintf("0x%08x",
227 result);
226 task_runner_->PostTask(FROM_HERE, 228 task_runner_->PostTask(FROM_HERE,
227 base::Bind(&HidConnectionMac::ReturnAsyncResult, 229 base::Bind(&HidConnectionMac::ReturnAsyncResult,
228 this, 230 this,
229 base::Bind(callback, false))); 231 base::Bind(callback, false)));
230 } 232 }
231 } 233 }
232 234
233 void HidConnectionMac::ReturnAsyncResult(const base::Closure& callback) { 235 void HidConnectionMac::ReturnAsyncResult(const base::Closure& callback) {
234 callback.Run(); 236 callback.Run();
235 } 237 }
236 238
237 } // namespace device 239 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698