OLD | NEW |
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_provider.h" | 5 #include "device/gamepad/gamepad_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <cmath> | 9 #include <cmath> |
10 #include <utility> | 10 #include <utility> |
(...skipping 21 matching lines...) Expand all Loading... |
32 const base::Closure& c, | 32 const base::Closure& c, |
33 const scoped_refptr<base::SingleThreadTaskRunner>& m) | 33 const scoped_refptr<base::SingleThreadTaskRunner>& m) |
34 : closure(c), task_runner(m) {} | 34 : closure(c), task_runner(m) {} |
35 | 35 |
36 GamepadProvider::ClosureAndThread::ClosureAndThread( | 36 GamepadProvider::ClosureAndThread::ClosureAndThread( |
37 const ClosureAndThread& other) = default; | 37 const ClosureAndThread& other) = default; |
38 | 38 |
39 GamepadProvider::ClosureAndThread::~ClosureAndThread() {} | 39 GamepadProvider::ClosureAndThread::~ClosureAndThread() {} |
40 | 40 |
41 GamepadProvider::GamepadProvider( | 41 GamepadProvider::GamepadProvider( |
42 std::unique_ptr<GamepadSharedBuffer> buffer, | |
43 GamepadConnectionChangeClient* connection_change_client) | 42 GamepadConnectionChangeClient* connection_change_client) |
44 : is_paused_(true), | 43 : is_paused_(true), |
45 have_scheduled_do_poll_(false), | 44 have_scheduled_do_poll_(false), |
46 devices_changed_(true), | 45 devices_changed_(true), |
47 ever_had_user_gesture_(false), | 46 ever_had_user_gesture_(false), |
48 sanitize_(true), | 47 sanitize_(true), |
49 gamepad_shared_buffer_(std::move(buffer)), | 48 gamepad_shared_buffer_(new GamepadSharedBuffer()), |
50 connection_change_client_(connection_change_client) { | 49 connection_change_client_(connection_change_client) { |
51 Initialize(std::unique_ptr<GamepadDataFetcher>()); | 50 Initialize(std::unique_ptr<GamepadDataFetcher>()); |
52 } | 51 } |
53 | 52 |
54 GamepadProvider::GamepadProvider( | 53 GamepadProvider::GamepadProvider( |
55 std::unique_ptr<GamepadSharedBuffer> buffer, | |
56 GamepadConnectionChangeClient* connection_change_client, | 54 GamepadConnectionChangeClient* connection_change_client, |
57 std::unique_ptr<GamepadDataFetcher> fetcher) | 55 std::unique_ptr<GamepadDataFetcher> fetcher) |
58 : is_paused_(true), | 56 : is_paused_(true), |
59 have_scheduled_do_poll_(false), | 57 have_scheduled_do_poll_(false), |
60 devices_changed_(true), | 58 devices_changed_(true), |
61 ever_had_user_gesture_(false), | 59 ever_had_user_gesture_(false), |
62 sanitize_(true), | 60 sanitize_(true), |
63 gamepad_shared_buffer_(std::move(buffer)), | 61 gamepad_shared_buffer_(new GamepadSharedBuffer()), |
64 connection_change_client_(connection_change_client) { | 62 connection_change_client_(connection_change_client) { |
65 Initialize(std::move(fetcher)); | 63 Initialize(std::move(fetcher)); |
66 } | 64 } |
67 | 65 |
68 GamepadProvider::~GamepadProvider() { | 66 GamepadProvider::~GamepadProvider() { |
69 GamepadDataFetcherManager::GetInstance()->ClearProvider(); | 67 GamepadDataFetcherManager::GetInstance()->ClearProvider(); |
70 | 68 |
71 base::SystemMonitor* monitor = base::SystemMonitor::Get(); | 69 base::SystemMonitor* monitor = base::SystemMonitor::Get(); |
72 if (monitor) | 70 if (monitor) |
73 monitor->RemoveDevicesChangedObserver(this); | 71 monitor->RemoveDevicesChangedObserver(this); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 OnGamepadConnectionChange(false, i, buffer->items[i]); | 251 OnGamepadConnectionChange(false, i, buffer->items[i]); |
254 ClearPadState(state); | 252 ClearPadState(state); |
255 } | 253 } |
256 } | 254 } |
257 } | 255 } |
258 | 256 |
259 { | 257 { |
260 base::AutoLock lock(shared_memory_lock_); | 258 base::AutoLock lock(shared_memory_lock_); |
261 | 259 |
262 // Acquire the SeqLock. There is only ever one writer to this data. | 260 // Acquire the SeqLock. There is only ever one writer to this data. |
263 // See gamepad_hardware_buffer.h. | 261 // See gamepad_shared_buffer.h. |
264 gamepad_shared_buffer_->WriteBegin(); | 262 gamepad_shared_buffer_->WriteBegin(); |
265 buffer->length = 0; | 263 buffer->length = 0; |
266 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { | 264 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { |
267 PadState& state = pad_states_.get()[i]; | 265 PadState& state = pad_states_.get()[i]; |
268 // Must run through the map+sanitize here or CheckForUserGesture may fail. | 266 // Must run through the map+sanitize here or CheckForUserGesture may fail. |
269 MapAndSanitizeGamepadData(&state, &buffer->items[i], sanitize_); | 267 MapAndSanitizeGamepadData(&state, &buffer->items[i], sanitize_); |
270 if (state.active_state) | 268 if (state.active_state) |
271 buffer->length++; | 269 buffer->length++; |
272 } | 270 } |
273 gamepad_shared_buffer_->WriteEnd(); | 271 gamepad_shared_buffer_->WriteEnd(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 ever_had_user_gesture_ = true; | 323 ever_had_user_gesture_ = true; |
326 for (size_t i = 0; i < user_gesture_observers_.size(); i++) { | 324 for (size_t i = 0; i < user_gesture_observers_.size(); i++) { |
327 user_gesture_observers_[i].task_runner->PostTask( | 325 user_gesture_observers_[i].task_runner->PostTask( |
328 FROM_HERE, user_gesture_observers_[i].closure); | 326 FROM_HERE, user_gesture_observers_[i].closure); |
329 } | 327 } |
330 user_gesture_observers_.clear(); | 328 user_gesture_observers_.clear(); |
331 } | 329 } |
332 } | 330 } |
333 | 331 |
334 } // namespace device | 332 } // namespace device |
OLD | NEW |