| 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 "content/browser/gamepad/gamepad_provider.h" |
| 6 |
| 5 #include <stddef.h> | 7 #include <stddef.h> |
| 6 #include <string.h> | 8 #include <string.h> |
| 7 | |
| 8 #include <cmath> | 9 #include <cmath> |
| 9 #include <set> | 10 #include <set> |
| 11 #include <utility> |
| 10 #include <vector> | 12 #include <vector> |
| 11 | 13 |
| 12 #include "base/bind.h" | 14 #include "base/bind.h" |
| 13 #include "base/location.h" | 15 #include "base/location.h" |
| 14 #include "base/logging.h" | 16 #include "base/logging.h" |
| 15 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 16 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 18 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 17 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
| 18 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
| 19 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
| 20 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 21 #include "content/browser/gamepad/gamepad_data_fetcher.h" | 23 #include "content/browser/gamepad/gamepad_data_fetcher.h" |
| 22 #include "content/browser/gamepad/gamepad_platform_data_fetcher.h" | 24 #include "content/browser/gamepad/gamepad_platform_data_fetcher.h" |
| 23 #include "content/browser/gamepad/gamepad_provider.h" | |
| 24 #include "content/browser/gamepad/gamepad_service.h" | 25 #include "content/browser/gamepad/gamepad_service.h" |
| 25 #include "content/common/gamepad_hardware_buffer.h" | 26 #include "content/common/gamepad_hardware_buffer.h" |
| 26 #include "content/common/gamepad_messages.h" | 27 #include "content/common/gamepad_messages.h" |
| 27 #include "content/common/gamepad_user_gesture.h" | 28 #include "content/common/gamepad_user_gesture.h" |
| 28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 29 | 30 |
| 30 using blink::WebGamepad; | 31 using blink::WebGamepad; |
| 31 using blink::WebGamepads; | 32 using blink::WebGamepads; |
| 32 | 33 |
| 33 namespace content { | 34 namespace content { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 47 devices_changed_(true), | 48 devices_changed_(true), |
| 48 ever_had_user_gesture_(false) { | 49 ever_had_user_gesture_(false) { |
| 49 Initialize(scoped_ptr<GamepadDataFetcher>()); | 50 Initialize(scoped_ptr<GamepadDataFetcher>()); |
| 50 } | 51 } |
| 51 | 52 |
| 52 GamepadProvider::GamepadProvider(scoped_ptr<GamepadDataFetcher> fetcher) | 53 GamepadProvider::GamepadProvider(scoped_ptr<GamepadDataFetcher> fetcher) |
| 53 : is_paused_(true), | 54 : is_paused_(true), |
| 54 have_scheduled_do_poll_(false), | 55 have_scheduled_do_poll_(false), |
| 55 devices_changed_(true), | 56 devices_changed_(true), |
| 56 ever_had_user_gesture_(false) { | 57 ever_had_user_gesture_(false) { |
| 57 Initialize(fetcher.Pass()); | 58 Initialize(std::move(fetcher)); |
| 58 } | 59 } |
| 59 | 60 |
| 60 GamepadProvider::~GamepadProvider() { | 61 GamepadProvider::~GamepadProvider() { |
| 61 base::SystemMonitor* monitor = base::SystemMonitor::Get(); | 62 base::SystemMonitor* monitor = base::SystemMonitor::Get(); |
| 62 if (monitor) | 63 if (monitor) |
| 63 monitor->RemoveDevicesChangedObserver(this); | 64 monitor->RemoveDevicesChangedObserver(this); |
| 64 | 65 |
| 65 // Use Stop() to join the polling thread, as there may be pending callbacks | 66 // Use Stop() to join the polling thread, as there may be pending callbacks |
| 66 // which dereference |polling_thread_|. | 67 // which dereference |polling_thread_|. |
| 67 polling_thread_->Stop(); | 68 polling_thread_->Stop(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 base::Unretained(this), base::Passed(&fetcher))); | 154 base::Unretained(this), base::Passed(&fetcher))); |
| 154 } | 155 } |
| 155 | 156 |
| 156 void GamepadProvider::DoInitializePollingThread( | 157 void GamepadProvider::DoInitializePollingThread( |
| 157 scoped_ptr<GamepadDataFetcher> fetcher) { | 158 scoped_ptr<GamepadDataFetcher> fetcher) { |
| 158 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); | 159 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); |
| 159 DCHECK(!data_fetcher_.get()); // Should only initialize once. | 160 DCHECK(!data_fetcher_.get()); // Should only initialize once. |
| 160 | 161 |
| 161 if (!fetcher) | 162 if (!fetcher) |
| 162 fetcher.reset(new GamepadPlatformDataFetcher); | 163 fetcher.reset(new GamepadPlatformDataFetcher); |
| 163 data_fetcher_ = fetcher.Pass(); | 164 data_fetcher_ = std::move(fetcher); |
| 164 } | 165 } |
| 165 | 166 |
| 166 void GamepadProvider::SendPauseHint(bool paused) { | 167 void GamepadProvider::SendPauseHint(bool paused) { |
| 167 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); | 168 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); |
| 168 if (data_fetcher_) | 169 if (data_fetcher_) |
| 169 data_fetcher_->PauseHint(paused); | 170 data_fetcher_->PauseHint(paused); |
| 170 } | 171 } |
| 171 | 172 |
| 172 bool GamepadProvider::PadState::Match(const WebGamepad& pad) const { | 173 bool GamepadProvider::PadState::Match(const WebGamepad& pad) const { |
| 173 return connected_ == pad.connected && | 174 return connected_ == pad.connected && |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 } | 322 } |
| 322 if (!had_gesture_before && ever_had_user_gesture_) { | 323 if (!had_gesture_before && ever_had_user_gesture_) { |
| 323 // Initialize pad_states_ for the first time. | 324 // Initialize pad_states_ for the first time. |
| 324 for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) { | 325 for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) { |
| 325 pad_states_.get()[i].SetPad(pads.items[i]); | 326 pad_states_.get()[i].SetPad(pads.items[i]); |
| 326 } | 327 } |
| 327 } | 328 } |
| 328 } | 329 } |
| 329 | 330 |
| 330 } // namespace content | 331 } // namespace content |
| OLD | NEW |