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"
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"
16 GamepadService::GamepadService() : num_readers_(0) {
19 GamepadService::GamepadService(scoped_ptr
<GamepadDataFetcher
> fetcher
)
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());
37 DCHECK(num_readers_
> 0);
39 provider_
.reset(new GamepadProvider
);
43 void GamepadService::RemoveConsumer() {
44 DCHECK(thread_checker_
.CalledOnValidThread());
47 DCHECK(num_readers_
>= 0);
49 if (num_readers_
== 0)
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() {
63 base::SharedMemoryHandle
GamepadService::GetSharedMemoryHandleForProcess(
64 base::ProcessHandle handle
) {
65 DCHECK(thread_checker_
.CalledOnValidThread());
66 return provider_
->GetSharedMemoryHandleForProcess(handle
);
69 } // namespace content