Index: content/browser/gamepad/gamepad_service.cc |
diff --git a/content/browser/gamepad/gamepad_service.cc b/content/browser/gamepad/gamepad_service.cc |
index 42b1e10821607d112203d281e86698894d2a0f01..67930f6118d16de2468d3d3968b68fb5abbec077 100644 |
--- a/content/browser/gamepad/gamepad_service.cc |
+++ b/content/browser/gamepad/gamepad_service.cc |
@@ -22,23 +22,27 @@ GamepadService* g_gamepad_service = 0; |
GamepadService::GamepadService() |
: num_active_consumers_(0), |
gesture_callback_pending_(false) { |
- SetInstance(); |
+ SetInstance(this); |
} |
GamepadService::GamepadService(scoped_ptr<GamepadDataFetcher> fetcher) |
: provider_(new GamepadProvider(fetcher.Pass())), |
num_active_consumers_(0), |
gesture_callback_pending_(false) { |
- SetInstance(); |
+ SetInstance(this); |
thread_checker_.DetachFromThread(); |
} |
GamepadService::~GamepadService() { |
+ SetInstance(NULL); |
} |
-void GamepadService::SetInstance() { |
- CHECK(!g_gamepad_service); |
- g_gamepad_service = this; |
+void GamepadService::SetInstance(GamepadService* instance) { |
+ // Unit tests can create multiple instances but only one should exist at any |
+ // given time so g_gamepad_service should only go from NULL to non-NULL and |
+ // vica versa. |
+ CHECK(!!instance != !!g_gamepad_service); |
+ g_gamepad_service = instance; |
} |
GamepadService* GamepadService::GetInstance() { |