Android Browser Compositor: Add ScheduleComposite() callback.
[chromium-blink-merge.git] / content / browser / gamepad / gamepad_service.h
blobcc40c5d0ae20721ddd5a6435308ff10e4ea65de3
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 #ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H
6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H
8 #include "base/basictypes.h"
9 #include "base/callback_forward.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/singleton.h"
12 #include "base/shared_memory.h"
13 #include "base/threading/thread_checker.h"
14 #include "content/common/content_export.h"
16 namespace content {
18 class GamepadDataFetcher;
19 class GamepadProvider;
20 class GamepadServiceTestConstructor;
21 class RenderProcessHost;
23 // Owns the GamepadProvider (the background polling thread) and keeps track of
24 // the number of consumers currently using the data (and pausing the provider
25 // when not in use).
26 class CONTENT_EXPORT GamepadService {
27 public:
28 // Returns the GamepadService singleton.
29 static GamepadService* GetInstance();
31 // Increments the number of users of the provider. The Provider is running
32 // when there's > 0 users, and is paused when the count drops to 0.
34 // Must be called on the I/O thread.
35 void AddConsumer();
37 // Removes a consumer. Should be matched with an AddConsumer call.
39 // Must be called on the I/O thread.
40 void RemoveConsumer();
42 // Registers the given closure for calling when the user has interacted with
43 // the device. This callback will only be issued once. Should only be called
44 // while a consumer is active.
45 void RegisterForUserGesture(const base::Closure& closure);
47 // Returns the shared memory handle of the gamepad data duplicated into the
48 // given process.
49 base::SharedMemoryHandle GetSharedMemoryHandleForProcess(
50 base::ProcessHandle handle);
52 // Stop/join with the background thread in GamepadProvider |provider_|.
53 void Terminate();
55 private:
56 friend struct DefaultSingletonTraits<GamepadService>;
57 friend class GamepadServiceTestConstructor;
59 GamepadService();
61 // Constructor for testing. This specifies the data fetcher to use for a
62 // provider, bypassing the default platform one.
63 GamepadService(scoped_ptr<GamepadDataFetcher> fetcher);
65 virtual ~GamepadService();
67 int num_readers_;
68 scoped_ptr<GamepadProvider> provider_;
70 base::ThreadChecker thread_checker_;
72 DISALLOW_COPY_AND_ASSIGN(GamepadService);
75 } // namespace content
77 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H_