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

Side by Side Diff: device/gamepad/gamepad_service.h

Issue 2466073002: Movw GamepadService out of content/browser/ and into device/ (Closed)
Patch Set: Fixed everything but one unittest Created 4 years, 1 month 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 | « device/gamepad/gamepad_provider_unittest.cc ('k') | device/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 DEVICE_GAMEPAD_GAMEPAD_SERVICE_H_
6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H_ 6 #define DEVICE_GAMEPAD_GAMEPAD_SERVICE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 10
11 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/shared_memory.h" 13 #include "base/memory/shared_memory.h"
14 #include "base/memory/singleton.h" 14 #include "base/memory/singleton.h"
15 #include "base/threading/thread_checker.h" 15
16 #include "content/common/content_export.h" 16 #include "device/gamepad/gamepad_export.h"
17 #include "device/gamepad/gamepad_provider.h" 17 #include "device/gamepad/gamepad_provider.h"
18 18
19 namespace {
20 class SingleThreadTaskRunner;
21 }
22
19 namespace blink { 23 namespace blink {
20 class WebGamepad; 24 class WebGamepad;
21 } 25 }
22 26
27 namespace content {
28 class GamepadServiceTestConstructor;
29 class RenderProcessHost;
30 }
31
23 namespace device { 32 namespace device {
24 class GamepadConsumer; 33 class GamepadConsumer;
25 class GamepadDataFetcher; 34 class GamepadDataFetcher;
26 class GamepadProvider; 35 class GamepadProvider;
27 }
28
29 namespace content {
30
31 class GamepadServiceTestConstructor;
32 class RenderProcessHost;
33 36
34 // Owns the GamepadProvider (the background polling thread) and keeps track of 37 // Owns the GamepadProvider (the background polling thread) and keeps track of
35 // the number of consumers currently using the data (and pausing the provider 38 // the number of consumers currently using the data (and pausing the provider
36 // when not in use). 39 // when not in use).
37 class CONTENT_EXPORT GamepadService 40 class DEVICE_GAMEPAD_EXPORT GamepadService
38 : public device::GamepadConnectionChangeClient { 41 : public device::GamepadConnectionChangeClient {
39 public: 42 public:
40 // Returns the GamepadService singleton. 43 // Returns the GamepadService singleton.
41 static GamepadService* GetInstance(); 44 static GamepadService* GetInstance();
42 45
43 // Increments the number of users of the provider. The Provider is running 46 // Increments the number of users of the provider. The Provider is running
44 // when there's > 0 users, and is paused when the count drops to 0. 47 // when there's > 0 users, and is paused when the count drops to 0.
45 // consumer is registered to listen for gamepad connections. If this is the 48 // consumer is registered to listen for gamepad connections. If this is the
46 // first time it is added to the set of consumers it will be treated 49 // first time it is added to the set of consumers it will be treated
47 // specially: it will not be informed about connections before a new user 50 // specially: it will not be informed about connections before a new user
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 89
87 private: 90 private:
88 friend struct base::DefaultSingletonTraits<GamepadService>; 91 friend struct base::DefaultSingletonTraits<GamepadService>;
89 friend class GamepadServiceTestConstructor; 92 friend class GamepadServiceTestConstructor;
90 friend class GamepadServiceTest; 93 friend class GamepadServiceTest;
91 94
92 GamepadService(); 95 GamepadService();
93 96
94 // Constructor for testing. This specifies the data fetcher to use for a 97 // Constructor for testing. This specifies the data fetcher to use for a
95 // provider, bypassing the default platform one. 98 // provider, bypassing the default platform one.
96 GamepadService( 99 GamepadService(std::unique_ptr<device::GamepadDataFetcher> fetcher);
97 std::unique_ptr<device::GamepadDataFetcher> fetcher);
98 100
99 virtual ~GamepadService(); 101 virtual ~GamepadService();
100 102
101 static void SetInstance(GamepadService*); 103 static void SetInstance(GamepadService*);
102 104
103 void OnUserGesture(); 105 void OnUserGesture();
104 106
105 void OnGamepadConnectionChange(bool connected, 107 void OnGamepadConnectionChange(bool connected,
106 int index, 108 int index,
107 const blink::WebGamepad& pad) override; 109 const blink::WebGamepad& pad) override;
108 110
109 void SetSanitizationEnabled(bool sanitize); 111 void SetSanitizationEnabled(bool sanitize);
110 112
111 struct ConsumerInfo { 113 struct ConsumerInfo {
112 ConsumerInfo(device::GamepadConsumer* consumer) 114 ConsumerInfo(device::GamepadConsumer* consumer)
113 : consumer(consumer), did_observe_user_gesture(false) {} 115 : consumer(consumer), did_observe_user_gesture(false) {}
114 116
115 bool operator<(const ConsumerInfo& other) const { 117 bool operator<(const ConsumerInfo& other) const {
116 return consumer < other.consumer; 118 return consumer < other.consumer;
117 } 119 }
118 120
119 device::GamepadConsumer* consumer; 121 device::GamepadConsumer* consumer;
120 mutable bool is_active; 122 mutable bool is_active;
121 mutable bool did_observe_user_gesture; 123 mutable bool did_observe_user_gesture;
122 }; 124 };
123 125
124 std::unique_ptr<device::GamepadProvider> provider_; 126 std::unique_ptr<device::GamepadProvider> provider_;
125 127
126 base::ThreadChecker thread_checker_; 128 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
127 129
128 typedef std::set<ConsumerInfo> ConsumerSet; 130 typedef std::set<ConsumerInfo> ConsumerSet;
129 ConsumerSet consumers_; 131 ConsumerSet consumers_;
130 132
131 int num_active_consumers_; 133 int num_active_consumers_;
132 134
133 bool gesture_callback_pending_; 135 bool gesture_callback_pending_;
134 136
135 DISALLOW_COPY_AND_ASSIGN(GamepadService); 137 DISALLOW_COPY_AND_ASSIGN(GamepadService);
136 }; 138 };
137 139
138 } // namespace content 140 } // namespace content
139 141
140 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H_ 142 #endif // DEVICE_GAMEPAD_GAMEPAD_SERVICE_H_
OLDNEW
« no previous file with comments | « device/gamepad/gamepad_provider_unittest.cc ('k') | device/gamepad/gamepad_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698