Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / gamepad / gamepad_service.cc
blob11a6964b3ab5cf9953569d5aa0b6b8c53be6b51f
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
3 // found in the LICENSE file.
5 #include "content/browser/gamepad/gamepad_service.h"
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/memory/singleton.h"
10 #include "content/browser/gamepad/gamepad_data_fetcher.h"
11 #include "content/browser/gamepad/gamepad_provider.h"
12 #include "content/public/browser/render_process_host.h"
14 namespace content {
16 GamepadService::GamepadService() : num_readers_(0) {
19 GamepadService::GamepadService(scoped_ptr<GamepadDataFetcher> fetcher)
20 : num_readers_(0),
21 provider_(new GamepadProvider(fetcher.Pass())) {
22 thread_checker_.DetachFromThread();
25 GamepadService::~GamepadService() {
28 GamepadService* GamepadService::GetInstance() {
29 return Singleton<GamepadService,
30 LeakySingletonTraits<GamepadService> >::get();
33 void GamepadService::AddConsumer() {
34 DCHECK(thread_checker_.CalledOnValidThread());
36 num_readers_++;
37 DCHECK(num_readers_ > 0);
38 if (!provider_)
39 provider_.reset(new GamepadProvider);
40 provider_->Resume();
43 void GamepadService::RemoveConsumer() {
44 DCHECK(thread_checker_.CalledOnValidThread());
46 --num_readers_;
47 DCHECK(num_readers_ >= 0);
49 if (num_readers_ == 0)
50 provider_->Pause();
53 void GamepadService::RegisterForUserGesture(const base::Closure& closure) {
54 DCHECK(num_readers_ > 0);
55 DCHECK(thread_checker_.CalledOnValidThread());
56 provider_->RegisterForUserGesture(closure);
59 void GamepadService::Terminate() {
60 provider_.reset();
63 base::SharedMemoryHandle GamepadService::GetSharedMemoryHandleForProcess(
64 base::ProcessHandle handle) {
65 DCHECK(thread_checker_.CalledOnValidThread());
66 return provider_->GetSharedMemoryHandleForProcess(handle);
69 } // namespace content