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

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

Issue 825523003: Convert HidDeviceInfo from a struct to a refcounted class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added TODO to remove friend class definitions. Created 5 years, 11 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 | « device/hid/hid_connection_mac.h ('k') | device/hid/hid_connection_unittest.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_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 "device/hid/hid_connection_mac.h" 13 #include "device/hid/hid_connection_mac.h"
14 14
15 namespace device { 15 namespace device {
16 16
17 HidConnectionMac::HidConnectionMac( 17 HidConnectionMac::HidConnectionMac(
18 IOHIDDeviceRef device, 18 IOHIDDeviceRef device,
19 HidDeviceInfo device_info, 19 scoped_refptr<HidDeviceInfo> device_info,
20 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) 20 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner)
21 : HidConnection(device_info), 21 : HidConnection(device_info),
22 device_(device, base::scoped_policy::RETAIN), 22 device_(device, base::scoped_policy::RETAIN),
23 file_task_runner_(file_task_runner) { 23 file_task_runner_(file_task_runner) {
24 task_runner_ = base::ThreadTaskRunnerHandle::Get(); 24 task_runner_ = base::ThreadTaskRunnerHandle::Get();
25 DCHECK(task_runner_.get()); 25 DCHECK(task_runner_.get());
26 26
27 IOHIDDeviceScheduleWithRunLoop( 27 IOHIDDeviceScheduleWithRunLoop(
28 device_.get(), CFRunLoopGetMain(), kCFRunLoopDefaultMode); 28 device_.get(), CFRunLoopGetMain(), kCFRunLoopDefaultMode);
29 29
30 size_t expected_report_size = device_info.max_input_report_size; 30 size_t expected_report_size = device_info->max_input_report_size();
31 if (device_info.has_report_id) { 31 if (device_info->has_report_id()) {
32 expected_report_size++; 32 expected_report_size++;
33 } 33 }
34 inbound_buffer_.resize(expected_report_size); 34 inbound_buffer_.resize(expected_report_size);
35 35
36 if (inbound_buffer_.size() > 0) { 36 if (inbound_buffer_.size() > 0) {
37 AddRef(); // Hold a reference to this while this callback is registered. 37 AddRef(); // Hold a reference to this while this callback is registered.
38 IOHIDDeviceRegisterInputReportCallback( 38 IOHIDDeviceRegisterInputReportCallback(
39 device_.get(), 39 device_.get(),
40 &inbound_buffer_[0], 40 &inbound_buffer_[0],
41 inbound_buffer_.size(), 41 inbound_buffer_.size(),
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 uint8_t* report_bytes, 119 uint8_t* report_bytes,
120 CFIndex report_length) { 120 CFIndex report_length) {
121 HidConnectionMac* connection = static_cast<HidConnectionMac*>(context); 121 HidConnectionMac* connection = static_cast<HidConnectionMac*>(context);
122 if (result != kIOReturnSuccess) { 122 if (result != kIOReturnSuccess) {
123 VLOG(1) << "Failed to read input report: " 123 VLOG(1) << "Failed to read input report: "
124 << base::StringPrintf("0x%08x", result); 124 << base::StringPrintf("0x%08x", result);
125 return; 125 return;
126 } 126 }
127 127
128 scoped_refptr<net::IOBufferWithSize> buffer; 128 scoped_refptr<net::IOBufferWithSize> buffer;
129 if (connection->device_info().has_report_id) { 129 if (connection->device_info()->has_report_id()) {
130 // report_id is already contained in report_bytes 130 // report_id is already contained in report_bytes
131 buffer = new net::IOBufferWithSize(report_length); 131 buffer = new net::IOBufferWithSize(report_length);
132 memcpy(buffer->data(), report_bytes, report_length); 132 memcpy(buffer->data(), report_bytes, report_length);
133 } else { 133 } else {
134 buffer = new net::IOBufferWithSize(report_length + 1); 134 buffer = new net::IOBufferWithSize(report_length + 1);
135 buffer->data()[0] = 0; 135 buffer->data()[0] = 0;
136 memcpy(buffer->data() + 1, report_bytes, report_length); 136 memcpy(buffer->data() + 1, report_bytes, report_length);
137 } 137 }
138 138
139 connection->ProcessInputReport(buffer); 139 connection->ProcessInputReport(buffer);
(...skipping 18 matching lines...) Expand all
158 pending_reports_.pop(); 158 pending_reports_.pop();
159 if (CompleteRead(report.buffer, report.size, read.callback)) { 159 if (CompleteRead(report.buffer, report.size, read.callback)) {
160 pending_reads_.pop(); 160 pending_reads_.pop();
161 } 161 }
162 } 162 }
163 } 163 }
164 164
165 void HidConnectionMac::GetFeatureReportAsync(uint8_t report_id, 165 void HidConnectionMac::GetFeatureReportAsync(uint8_t report_id,
166 const ReadCallback& callback) { 166 const ReadCallback& callback) {
167 scoped_refptr<net::IOBufferWithSize> buffer( 167 scoped_refptr<net::IOBufferWithSize> buffer(
168 new net::IOBufferWithSize(device_info().max_feature_report_size + 1)); 168 new net::IOBufferWithSize(device_info()->max_feature_report_size() + 1));
169 CFIndex report_size = buffer->size(); 169 CFIndex report_size = buffer->size();
170 170
171 // The IOHIDDevice object is shared with the UI thread and so this function 171 // The IOHIDDevice object is shared with the UI thread and so this function
172 // should probably be called there but it may block and the asynchronous 172 // should probably be called there but it may block and the asynchronous
173 // version is NOT IMPLEMENTED. I've examined the open source implementation 173 // version is NOT IMPLEMENTED. I've examined the open source implementation
174 // of this function and believe it is a simple enough wrapper around the 174 // of this function and believe it is a simple enough wrapper around the
175 // kernel API that this is safe. 175 // kernel API that this is safe.
176 IOReturn result = 176 IOReturn result =
177 IOHIDDeviceGetReport(device_.get(), 177 IOHIDDeviceGetReport(device_.get(),
178 kIOHIDReportTypeFeature, 178 kIOHIDReportTypeFeature,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 this, 228 this,
229 base::Bind(callback, false))); 229 base::Bind(callback, false)));
230 } 230 }
231 } 231 }
232 232
233 void HidConnectionMac::ReturnAsyncResult(const base::Closure& callback) { 233 void HidConnectionMac::ReturnAsyncResult(const base::Closure& callback) {
234 callback.Run(); 234 callback.Run();
235 } 235 }
236 236
237 } // namespace device 237 } // namespace device
OLDNEW
« no previous file with comments | « device/hid/hid_connection_mac.h ('k') | device/hid/hid_connection_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698