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

Side by Side Diff: device/hid/hid_connection_unittest.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.cc ('k') | device/hid/hid_connection_win.h » ('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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 base::Unretained(this))); 55 base::Unretained(this)));
56 } 56 }
57 57
58 const HidDeviceId& WaitForDevice() { 58 const HidDeviceId& WaitForDevice() {
59 run_loop_.Run(); 59 run_loop_.Run();
60 observer_.RemoveAll(); 60 observer_.RemoveAll();
61 return device_id_; 61 return device_id_;
62 } 62 }
63 63
64 private: 64 private:
65 void OnEnumerationComplete(const std::vector<HidDeviceInfo>& devices) { 65 void OnEnumerationComplete(
66 for (const HidDeviceInfo& device_info : devices) { 66 const std::vector<scoped_refptr<HidDeviceInfo>>& devices) {
67 if (device_info.serial_number == serial_number_) { 67 for (const scoped_refptr<HidDeviceInfo>& device_info : devices) {
68 device_id_ = device_info.device_id; 68 if (device_info->serial_number() == serial_number_) {
69 device_id_ = device_info->device_id();
69 run_loop_.Quit(); 70 run_loop_.Quit();
70 break; 71 break;
71 } 72 }
72 } 73 }
73 } 74 }
74 75
75 void OnDeviceAdded(const HidDeviceInfo& device_info) override { 76 void OnDeviceAdded(scoped_refptr<HidDeviceInfo> device_info) override {
76 if (device_info.serial_number == serial_number_) { 77 if (device_info->serial_number() == serial_number_) {
77 device_id_ = device_info.device_id; 78 device_id_ = device_info->device_id();
78 run_loop_.Quit(); 79 run_loop_.Quit();
79 } 80 }
80 } 81 }
81 82
82 std::string serial_number_; 83 std::string serial_number_;
83 ScopedObserver<device::HidService, device::HidService::Observer> observer_; 84 ScopedObserver<device::HidService, device::HidService::Observer> observer_;
84 base::RunLoop run_loop_; 85 base::RunLoop run_loop_;
85 HidDeviceId device_id_; 86 HidDeviceId device_id_;
86 }; 87 };
87 88
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 ASSERT_EQ(0, read_callback.buffer()->data()[0]); 219 ASSERT_EQ(0, read_callback.buffer()->data()[0]);
219 for (unsigned char j = 1; j < kBufferSize; ++j) { 220 for (unsigned char j = 1; j < kBufferSize; ++j) {
220 ASSERT_EQ(i + j - 1, read_callback.buffer()->data()[j]); 221 ASSERT_EQ(i + j - 1, read_callback.buffer()->data()[j]);
221 } 222 }
222 } 223 }
223 224
224 conn->Close(); 225 conn->Close();
225 } 226 }
226 227
227 } // namespace device 228 } // namespace device
OLDNEW
« no previous file with comments | « device/hid/hid_connection_mac.cc ('k') | device/hid/hid_connection_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698