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

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: Clarified destructor behavior, cleaned up OS X error logging. 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
18 namespace {
19
20 std::string HexErrorCode(IOReturn error_code) {
21 return base::StringPrintf("0x%04x", error_code);
22 }
23
24 } // namespace
25
17 HidConnectionMac::HidConnectionMac( 26 HidConnectionMac::HidConnectionMac(
18 IOHIDDeviceRef device, 27 IOHIDDeviceRef device,
19 scoped_refptr<HidDeviceInfo> device_info, 28 scoped_refptr<HidDeviceInfo> device_info,
20 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) 29 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner)
21 : HidConnection(device_info), 30 : HidConnection(device_info),
22 device_(device, base::scoped_policy::RETAIN), 31 device_(device, base::scoped_policy::RETAIN),
23 file_task_runner_(file_task_runner) { 32 file_task_runner_(file_task_runner) {
24 task_runner_ = base::ThreadTaskRunnerHandle::Get(); 33 task_runner_ = base::ThreadTaskRunnerHandle::Get();
25 DCHECK(task_runner_.get()); 34 DCHECK(task_runner_.get());
26 35
(...skipping 25 matching lines...) Expand all
52 IOHIDDeviceRegisterInputReportCallback( 61 IOHIDDeviceRegisterInputReportCallback(
53 device_.get(), &inbound_buffer_[0], inbound_buffer_.size(), NULL, this); 62 device_.get(), &inbound_buffer_[0], inbound_buffer_.size(), NULL, this);
54 // Release the reference taken when this callback was registered. 63 // Release the reference taken when this callback was registered.
55 Release(); 64 Release();
56 } 65 }
57 66
58 IOHIDDeviceUnscheduleFromRunLoop( 67 IOHIDDeviceUnscheduleFromRunLoop(
59 device_.get(), CFRunLoopGetMain(), kCFRunLoopDefaultMode); 68 device_.get(), CFRunLoopGetMain(), kCFRunLoopDefaultMode);
60 IOReturn result = IOHIDDeviceClose(device_.get(), 0); 69 IOReturn result = IOHIDDeviceClose(device_.get(), 0);
61 if (result != kIOReturnSuccess) { 70 if (result != kIOReturnSuccess) {
62 VLOG(1) << "Failed to close HID device: " 71 HID_LOG(EVENT) << "Failed to close HID device: " << HexErrorCode(result);
63 << base::StringPrintf("0x%04x", result);
64 } 72 }
65 73
66 while (!pending_reads_.empty()) { 74 while (!pending_reads_.empty()) {
67 pending_reads_.front().callback.Run(false, NULL, 0); 75 pending_reads_.front().callback.Run(false, NULL, 0);
68 pending_reads_.pop(); 76 pending_reads_.pop();
69 } 77 }
70 } 78 }
71 79
72 void HidConnectionMac::PlatformRead(const ReadCallback& callback) { 80 void HidConnectionMac::PlatformRead(const ReadCallback& callback) {
73 DCHECK(thread_checker().CalledOnValidThread()); 81 DCHECK(thread_checker().CalledOnValidThread());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // static 121 // static
114 void HidConnectionMac::InputReportCallback(void* context, 122 void HidConnectionMac::InputReportCallback(void* context,
115 IOReturn result, 123 IOReturn result,
116 void* sender, 124 void* sender,
117 IOHIDReportType type, 125 IOHIDReportType type,
118 uint32_t report_id, 126 uint32_t report_id,
119 uint8_t* report_bytes, 127 uint8_t* report_bytes,
120 CFIndex report_length) { 128 CFIndex report_length) {
121 HidConnectionMac* connection = static_cast<HidConnectionMac*>(context); 129 HidConnectionMac* connection = static_cast<HidConnectionMac*>(context);
122 if (result != kIOReturnSuccess) { 130 if (result != kIOReturnSuccess) {
123 VLOG(1) << "Failed to read input report: " 131 HID_LOG(EVENT) << "Failed to read input report: " << HexErrorCode(result);
124 << base::StringPrintf("0x%08x", result);
125 return; 132 return;
126 } 133 }
127 134
128 scoped_refptr<net::IOBufferWithSize> buffer; 135 scoped_refptr<net::IOBufferWithSize> buffer;
129 if (connection->device_info()->has_report_id()) { 136 if (connection->device_info()->has_report_id()) {
130 // report_id is already contained in report_bytes 137 // report_id is already contained in report_bytes
131 buffer = new net::IOBufferWithSize(report_length); 138 buffer = new net::IOBufferWithSize(report_length);
132 memcpy(buffer->data(), report_bytes, report_length); 139 memcpy(buffer->data(), report_bytes, report_length);
133 } else { 140 } else {
134 buffer = new net::IOBufferWithSize(report_length + 1); 141 buffer = new net::IOBufferWithSize(report_length + 1);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 report_id, 186 report_id,
180 reinterpret_cast<uint8_t*>(buffer->data()), 187 reinterpret_cast<uint8_t*>(buffer->data()),
181 &report_size); 188 &report_size);
182 if (result == kIOReturnSuccess) { 189 if (result == kIOReturnSuccess) {
183 task_runner_->PostTask( 190 task_runner_->PostTask(
184 FROM_HERE, 191 FROM_HERE,
185 base::Bind(&HidConnectionMac::ReturnAsyncResult, 192 base::Bind(&HidConnectionMac::ReturnAsyncResult,
186 this, 193 this,
187 base::Bind(callback, true, buffer, report_size))); 194 base::Bind(callback, true, buffer, report_size)));
188 } else { 195 } else {
189 VLOG(1) << "Failed to get feature report: " 196 HID_LOG(EVENT) << "Failed to get feature report: " << HexErrorCode(result);
190 << base::StringPrintf("0x%08x", result);
191 task_runner_->PostTask(FROM_HERE, 197 task_runner_->PostTask(FROM_HERE,
192 base::Bind(&HidConnectionMac::ReturnAsyncResult, 198 base::Bind(&HidConnectionMac::ReturnAsyncResult,
193 this, 199 this,
194 base::Bind(callback, false, nullptr, 0))); 200 base::Bind(callback, false, nullptr, 0)));
195 } 201 }
196 } 202 }
197 203
198 void HidConnectionMac::SetReportAsync(IOHIDReportType report_type, 204 void HidConnectionMac::SetReportAsync(IOHIDReportType report_type,
199 scoped_refptr<net::IOBuffer> buffer, 205 scoped_refptr<net::IOBuffer> buffer,
200 size_t size, 206 size_t size,
(...skipping 14 matching lines...) Expand all
215 // of this function and believe it is a simple enough wrapper around the 221 // of this function and believe it is a simple enough wrapper around the
216 // kernel API that this is safe. 222 // kernel API that this is safe.
217 IOReturn result = 223 IOReturn result =
218 IOHIDDeviceSetReport(device_.get(), report_type, report_id, data, size); 224 IOHIDDeviceSetReport(device_.get(), report_type, report_id, data, size);
219 if (result == kIOReturnSuccess) { 225 if (result == kIOReturnSuccess) {
220 task_runner_->PostTask(FROM_HERE, 226 task_runner_->PostTask(FROM_HERE,
221 base::Bind(&HidConnectionMac::ReturnAsyncResult, 227 base::Bind(&HidConnectionMac::ReturnAsyncResult,
222 this, 228 this,
223 base::Bind(callback, true))); 229 base::Bind(callback, true)));
224 } else { 230 } else {
225 VLOG(1) << "Failed to set report: " << base::StringPrintf("0x%08x", result); 231 HID_LOG(EVENT) << "Failed to set report: " << HexErrorCode(result);
226 task_runner_->PostTask(FROM_HERE, 232 task_runner_->PostTask(FROM_HERE,
227 base::Bind(&HidConnectionMac::ReturnAsyncResult, 233 base::Bind(&HidConnectionMac::ReturnAsyncResult,
228 this, 234 this,
229 base::Bind(callback, false))); 235 base::Bind(callback, false)));
230 } 236 }
231 } 237 }
232 238
233 void HidConnectionMac::ReturnAsyncResult(const base::Closure& callback) { 239 void HidConnectionMac::ReturnAsyncResult(const base::Closure& callback) {
234 callback.Run(); 240 callback.Run();
235 } 241 }
236 242
237 } // namespace device 243 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698