Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1004)

Side by Side Diff: content/browser/gamepad/gamepad_service.h

Issue 200873002: Gamepad API: add support for connection events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/gamepad/gamepad_provider.cc ('k') | content/browser/gamepad/gamepad_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H 5 #ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H
6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H 6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/callback_forward.h" 9 #include "base/callback_forward.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/shared_memory.h" 11 #include "base/memory/shared_memory.h"
12 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
13 #include "base/threading/thread_checker.h" 13 #include "base/threading/thread_checker.h"
14 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
15 15
16 namespace blink {
17 class WebGamepad;
18 }
19
16 namespace content { 20 namespace content {
17 21
22 class GamepadConsumer;
18 class GamepadDataFetcher; 23 class GamepadDataFetcher;
19 class GamepadProvider; 24 class GamepadProvider;
20 class GamepadServiceTestConstructor; 25 class GamepadServiceTestConstructor;
21 class RenderProcessHost; 26 class RenderProcessHost;
22 27
23 // Owns the GamepadProvider (the background polling thread) and keeps track of 28 // Owns the GamepadProvider (the background polling thread) and keeps track of
24 // the number of consumers currently using the data (and pausing the provider 29 // the number of consumers currently using the data (and pausing the provider
25 // when not in use). 30 // when not in use).
26 class CONTENT_EXPORT GamepadService { 31 class CONTENT_EXPORT GamepadService {
27 public: 32 public:
28 // Returns the GamepadService singleton. 33 // Returns the GamepadService singleton.
29 static GamepadService* GetInstance(); 34 static GamepadService* GetInstance();
30 35
31 // Increments the number of users of the provider. The Provider is running 36 // 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. 37 // when there's > 0 users, and is paused when the count drops to 0.
33 // 38 //
34 // Must be called on the I/O thread. 39 // Must be called on the I/O thread.
35 void AddConsumer(); 40 void AddConsumer(GamepadConsumer* consumer);
36 41
37 // Removes a consumer. Should be matched with an AddConsumer call. 42 // Removes a consumer. Should be matched with an AddConsumer call.
38 // 43 //
39 // Must be called on the I/O thread. 44 // Must be called on the I/O thread.
40 void RemoveConsumer(); 45 void RemoveConsumer(GamepadConsumer* consumer);
41 46
42 // Registers the given closure for calling when the user has interacted with 47 // 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 48 // the device. This callback will only be issued once. Should only be called
44 // while a consumer is active. 49 // while a consumer is active.
45 void RegisterForUserGesture(const base::Closure& closure); 50 void RegisterForUserGesture(const base::Closure& closure);
46 51
47 // Returns the shared memory handle of the gamepad data duplicated into the 52 // Returns the shared memory handle of the gamepad data duplicated into the
48 // given process. 53 // given process.
49 base::SharedMemoryHandle GetSharedMemoryHandleForProcess( 54 base::SharedMemoryHandle GetSharedMemoryHandleForProcess(
50 base::ProcessHandle handle); 55 base::ProcessHandle handle);
51 56
52 // Stop/join with the background thread in GamepadProvider |provider_|. 57 // Stop/join with the background thread in GamepadProvider |provider_|.
53 void Terminate(); 58 void Terminate();
54 59
60 void OnUserGesture();
61 void DidReportUserGesture();
62
63 void OnGamepadConnected(int index, const blink::WebGamepad& pad);
64 void OnGamepadDisconnected(int index, const blink::WebGamepad& pad);
65
55 private: 66 private:
56 friend struct DefaultSingletonTraits<GamepadService>; 67 friend struct DefaultSingletonTraits<GamepadService>;
57 friend class GamepadServiceTestConstructor; 68 friend class GamepadServiceTestConstructor;
58 69
59 GamepadService(); 70 GamepadService();
60 71
61 // Constructor for testing. This specifies the data fetcher to use for a 72 // Constructor for testing. This specifies the data fetcher to use for a
62 // provider, bypassing the default platform one. 73 // provider, bypassing the default platform one.
63 GamepadService(scoped_ptr<GamepadDataFetcher> fetcher); 74 GamepadService(scoped_ptr<GamepadDataFetcher> fetcher);
64 75
65 virtual ~GamepadService(); 76 virtual ~GamepadService();
66 77
67 int num_readers_; 78 struct ConsumerInfo {
79 explicit ConsumerInfo(GamepadConsumer* consumer)
80 : consumer(consumer),
81 did_observe_user_gesture(false) {
82 }
83
84 friend bool operator<(const ConsumerInfo& a, const ConsumerInfo& b) {
85 return a.consumer < b.consumer;
86 }
87
88 GamepadConsumer* consumer;
89 bool did_observe_user_gesture;
90 };
91
92 typedef std::set<ConsumerInfo, std::less<ConsumerInfo> > ConsumerSet;
93 ConsumerSet consumers_;
94
68 scoped_ptr<GamepadProvider> provider_; 95 scoped_ptr<GamepadProvider> provider_;
69 96
70 base::ThreadChecker thread_checker_; 97 base::ThreadChecker thread_checker_;
71 98
72 DISALLOW_COPY_AND_ASSIGN(GamepadService); 99 DISALLOW_COPY_AND_ASSIGN(GamepadService);
73 }; 100 };
74 101
75 } // namespace content 102 } // namespace content
76 103
77 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H_ 104 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H_
OLDNEW
« no previous file with comments | « content/browser/gamepad/gamepad_provider.cc ('k') | content/browser/gamepad/gamepad_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698