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

Side by Side Diff: device/gamepad/gamepad_test_helpers.cc

Issue 2129003002: Refactored gamepad polling to support dynamic sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unit test issue and Mac XBoxDataFetcher constructor Created 4 years, 5 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/gamepad/gamepad_test_helpers.h" 5 #include "device/gamepad/gamepad_test_helpers.h"
6 6
7 namespace device { 7 namespace device {
8 8
9 MockGamepadDataFetcher::MockGamepadDataFetcher( 9 MockGamepadDataFetcher::MockGamepadDataFetcher(
10 const blink::WebGamepads& test_data) 10 const blink::WebGamepads& test_data)
11 : test_data_(test_data), 11 : test_data_(test_data),
12 read_data_(base::WaitableEvent::ResetPolicy::AUTOMATIC, 12 read_data_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
13 base::WaitableEvent::InitialState::NOT_SIGNALED) {} 13 base::WaitableEvent::InitialState::NOT_SIGNALED) {}
14 14
15 MockGamepadDataFetcher::~MockGamepadDataFetcher() {} 15 MockGamepadDataFetcher::~MockGamepadDataFetcher() {}
16 16
17 void MockGamepadDataFetcher::GetGamepadData(blink::WebGamepads* pads, 17 GamepadSource MockGamepadDataFetcher::source() {
18 bool devices_changed_hint) { 18 return GAMEPAD_SOURCE_TEST;
19 }
20
21 void MockGamepadDataFetcher::GetGamepadData(bool devices_changed_hint) {
19 { 22 {
20 base::AutoLock lock(lock_); 23 base::AutoLock lock(lock_);
21 *pads = test_data_; 24
25 for (unsigned int i = 0; i < blink::WebGamepads::itemsLengthCap; ++i) {
26 if (test_data_.items[i].connected) {
27 PadState* pad = provider()->GetPadState(GAMEPAD_SOURCE_TEST, i);
28 if (pad)
29 memcpy(&pad->data, &test_data_.items[i], sizeof(blink::WebGamepad));
30 }
31 }
22 } 32 }
23 read_data_.Signal(); 33 read_data_.Signal();
24 } 34 }
25 35
26 void MockGamepadDataFetcher::WaitForDataRead() { 36 void MockGamepadDataFetcher::WaitForDataRead() {
27 return read_data_.Wait(); 37 return read_data_.Wait();
28 } 38 }
29 39
30 void MockGamepadDataFetcher::WaitForDataReadAndCallbacksIssued() { 40 void MockGamepadDataFetcher::WaitForDataReadAndCallbacksIssued() {
31 // The provider will read the data on the background thread (setting the 41 // The provider will read the data on the background thread (setting the
(...skipping 29 matching lines...) Expand all
61 71
62 void MockGamepadSharedBuffer::WriteBegin() {} 72 void MockGamepadSharedBuffer::WriteBegin() {}
63 73
64 void MockGamepadSharedBuffer::WriteEnd() {} 74 void MockGamepadSharedBuffer::WriteEnd() {}
65 75
66 GamepadTestHelper::GamepadTestHelper() {} 76 GamepadTestHelper::GamepadTestHelper() {}
67 77
68 GamepadTestHelper::~GamepadTestHelper() {} 78 GamepadTestHelper::~GamepadTestHelper() {}
69 79
70 } // namespace device 80 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698