Chromium Code Reviews| 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_service.h" | 5 #include "content/browser/gamepad/gamepad_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "content/browser/gamepad/gamepad_consumer.h" | 10 #include "content/browser/gamepad/gamepad_consumer.h" |
| 11 #include "content/browser/gamepad/gamepad_data_fetcher.h" | 11 #include "content/browser/gamepad/gamepad_data_fetcher.h" |
| 12 #include "content/browser/gamepad/gamepad_provider.h" | 12 #include "content/browser/gamepad/gamepad_provider.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 GamepadService* g_gamepad_service = 0; | 19 GamepadService* g_gamepad_service = 0; |
| 20 } | 20 } |
| 21 | 21 |
| 22 GamepadService::GamepadService() | 22 GamepadService::GamepadService() |
| 23 : num_active_consumers_(0), | 23 : num_active_consumers_(0), |
| 24 gesture_callback_pending_(false) { | 24 gesture_callback_pending_(false) { |
| 25 SetInstance(); | 25 SetInstance(this); |
| 26 } | 26 } |
| 27 | 27 |
| 28 GamepadService::GamepadService(scoped_ptr<GamepadDataFetcher> fetcher) | 28 GamepadService::GamepadService(scoped_ptr<GamepadDataFetcher> fetcher) |
| 29 : provider_(new GamepadProvider(fetcher.Pass())), | 29 : provider_(new GamepadProvider(fetcher.Pass())), |
| 30 num_active_consumers_(0), | 30 num_active_consumers_(0), |
| 31 gesture_callback_pending_(false) { | 31 gesture_callback_pending_(false) { |
| 32 SetInstance(); | 32 SetInstance(this); |
| 33 thread_checker_.DetachFromThread(); | 33 thread_checker_.DetachFromThread(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 GamepadService::~GamepadService() { | 36 GamepadService::~GamepadService() { |
| 37 SetInstance(NULL); | |
| 37 } | 38 } |
| 38 | 39 |
| 39 void GamepadService::SetInstance() { | 40 void GamepadService::SetInstance(GamepadService* instance) { |
| 40 CHECK(!g_gamepad_service); | 41 CHECK(!!instance != !!g_gamepad_service); |
|
bajones
2014/07/08 15:59:00
This reads really awkwardly, and makes me question
| |
| 41 g_gamepad_service = this; | 42 g_gamepad_service = instance; |
| 42 } | 43 } |
| 43 | 44 |
| 44 GamepadService* GamepadService::GetInstance() { | 45 GamepadService* GamepadService::GetInstance() { |
| 45 if (!g_gamepad_service) | 46 if (!g_gamepad_service) |
| 46 g_gamepad_service = new GamepadService; | 47 g_gamepad_service = new GamepadService; |
| 47 return g_gamepad_service; | 48 return g_gamepad_service; |
| 48 } | 49 } |
| 49 | 50 |
| 50 void GamepadService::ConsumerBecameActive(GamepadConsumer* consumer) { | 51 void GamepadService::ConsumerBecameActive(GamepadConsumer* consumer) { |
| 51 DCHECK(thread_checker_.CalledOnValidThread()); | 52 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 for (unsigned i = 0; i < blink::WebGamepads::itemsLengthCap; ++i) { | 148 for (unsigned i = 0; i < blink::WebGamepads::itemsLengthCap; ++i) { |
| 148 const blink::WebGamepad& pad = gamepads.items[i]; | 149 const blink::WebGamepad& pad = gamepads.items[i]; |
| 149 if (pad.connected) | 150 if (pad.connected) |
| 150 info.consumer->OnGamepadConnected(i, pad); | 151 info.consumer->OnGamepadConnected(i, pad); |
| 151 } | 152 } |
| 152 } | 153 } |
| 153 } | 154 } |
| 154 } | 155 } |
| 155 | 156 |
| 156 } // namespace content | 157 } // namespace content |
| OLD | NEW |