OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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. |
| 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 |
| 10 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H |
| 11 |
| 12 #include "base/basictypes.h" |
| 13 #include "base/memory/singleton.h" |
| 14 #include "base/shared_memory.h" |
| 15 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" |
| 17 |
| 18 namespace content { |
| 19 |
| 20 class GamepadDataFetcher; |
| 21 class GamepadProvider; |
| 22 class RenderProcessHost; |
| 23 |
| 24 class GamepadService : public NotificationObserver, |
| 25 public base::RefCountedThreadSafe<GamepadService> { |
| 26 public: |
| 27 // Returns the GamepadService singleton. |
| 28 static GamepadService* GetInstance(); |
| 29 |
| 30 // Called on IO thread from a renderer host. Increments the number of users |
| 31 // of the provider. The Provider is running when there's > 0 users, and is |
| 32 // paused when the count drops to 0. There is no stop, the gamepad service |
| 33 // registers with the RPH to be notified when the associated renderer closes |
| 34 // (or crashes). |
| 35 void Start(GamepadDataFetcher* fetcher, |
| 36 RenderProcessHost* associated_rph); |
| 37 |
| 38 base::SharedMemoryHandle GetSharedMemoryHandle(base::ProcessHandle handle); |
| 39 |
| 40 // NotificationObserver overrides: |
| 41 virtual void Observe(int type, |
| 42 const NotificationSource& source, |
| 43 const NotificationDetails& details) OVERRIDE; |
| 44 |
| 45 private: |
| 46 friend struct DefaultSingletonTraits<GamepadService>; |
| 47 friend class base::RefCountedThreadSafe<GamepadService>; |
| 48 GamepadService(); |
| 49 virtual ~GamepadService(); |
| 50 |
| 51 // Called when a renderer that Start'd us is closed/crashes. |
| 52 void Stop(); |
| 53 |
| 54 // Run on UI thread to receive notifications of renderer closes. |
| 55 void RegisterForCloseNotification(RenderProcessHost* rph); |
| 56 |
| 57 // A registrar for listening notifications. Used to listen for when an |
| 58 // associated renderer has gone away (possibly crashed). We don't trust |
| 59 // the renderers to send a stop message because of the possibility of |
| 60 // crashing. |
| 61 NotificationRegistrar registrar_; |
| 62 |
| 63 int num_readers_; |
| 64 scoped_refptr<GamepadProvider> provider_; |
| 65 |
| 66 static GamepadService* instance_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(GamepadService); |
| 69 }; |
| 70 |
| 71 } // namespace content |
| 72 |
| 73 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H |
OLD | NEW |