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

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

Issue 10912062: Implement the gamepad API in the IPC proxy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
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 // Owns the GamepadProvider (the background polling thread) and keeps track of
6 // the number of renderers currently using the data (and pausing the provider
7 // when not in use).
8
9 #ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H 5 #ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H
10 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H 6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H
11 7
12 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/callback_forward.h"
10 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/singleton.h" 11 #include "base/memory/singleton.h"
14 #include "base/shared_memory.h" 12 #include "base/shared_memory.h"
15 #include "content/public/browser/notification_observer.h" 13 #include "base/threading/thread_checker.h"
16 #include "content/public/browser/notification_registrar.h" 14 #include "content/common/content_export.h"
17 15
18 namespace content { 16 namespace content {
19 17
20 class GamepadDataFetcher; 18 class GamepadDataFetcher;
21 class GamepadProvider; 19 class GamepadProvider;
20 class GamepadServiceTestConstructor;
22 class RenderProcessHost; 21 class RenderProcessHost;
23 22
24 class GamepadService : public NotificationObserver { 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 {
25 public: 27 public:
26 // Returns the GamepadService singleton. 28 // Returns the GamepadService singleton.
27 static GamepadService* GetInstance(); 29 static GamepadService* GetInstance();
28 30
29 // Called on IO thread from a renderer host. Increments the number of users 31 // Increments the number of users of the provider. The Provider is running
30 // of the provider. The Provider is running when there's > 0 users, and is 32 // when there's > 0 users, and is paused when the count drops to 0.
31 // paused when the count drops to 0. There is no stop, the gamepad service 33 //
32 // registers with the RPH to be notified when the associated renderer closes 34 // Must be called on the I/O thread.
33 // (or crashes). 35 void AddConsumer();
34 void Start(GamepadDataFetcher* fetcher,
35 RenderProcessHost* associated_rph);
36 36
37 base::SharedMemoryHandle GetSharedMemoryHandle(base::ProcessHandle handle); 37 // Removes a consumer. Should be matched with an AddConsumer call.
38 //
39 // Must be called on the I/O thread.
40 void RemoveConsumer();
41
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);
46
47 // Returns the shared memory handle of the gamepad data duplicated into the
48 // given process.
49 base::SharedMemoryHandle GetSharedMemoryHandleForProcess(
50 base::ProcessHandle handle);
38 51
39 // Stop/join with the background thread in GamepadProvider |provider_|. 52 // Stop/join with the background thread in GamepadProvider |provider_|.
40 void Terminate(); 53 void Terminate();
41 54
42 private: 55 private:
43 friend struct DefaultSingletonTraits<GamepadService>; 56 friend struct DefaultSingletonTraits<GamepadService>;
57 friend class GamepadServiceTestConstructor;
58
44 GamepadService(); 59 GamepadService();
60
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);
64
45 virtual ~GamepadService(); 65 virtual ~GamepadService();
46 66
47 // Called when a renderer that Start'd us is closed/crashes.
48 void Stop(const NotificationSource& source);
49
50 // Run on UI thread to receive/stop notifications of renderer closes.
51 void RegisterForTerminationNotification(RenderProcessHost* rph);
52 void UnregisterForTerminationNotification(const NotificationSource& source);
53
54 // NotificationObserver overrides:
55 virtual void Observe(int type,
56 const NotificationSource& source,
57 const NotificationDetails& details) OVERRIDE;
58
59 // A registrar for listening notifications. Used to listen for when an
60 // associated renderer has gone away (possibly crashed). We don't trust
61 // the renderers to send a stop message because of the possibility of
62 // crashing.
63 NotificationRegistrar registrar_;
64
65 int num_readers_; 67 int num_readers_;
66 scoped_ptr<GamepadProvider> provider_; 68 scoped_ptr<GamepadProvider> provider_;
67 69
70 base::ThreadChecker thread_checker_;
71
68 DISALLOW_COPY_AND_ASSIGN(GamepadService); 72 DISALLOW_COPY_AND_ASSIGN(GamepadService);
69 }; 73 };
70 74
71 } // namespace content 75 } // namespace content
72 76
73 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H 77 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H_
OLDNEW
« no previous file with comments | « content/browser/gamepad/gamepad_provider_unittest.cc ('k') | content/browser/gamepad/gamepad_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698