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

Unified Diff: content/browser/gamepad/gamepad_service.h

Issue 8345027: Big patch to implement Chromium-side of Gamepad support (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: minor tidying Created 9 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/gamepad/gamepad_service.h
diff --git a/content/browser/gamepad/gamepad_service.h b/content/browser/gamepad/gamepad_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..2be7e3f2b44d31e4079c8a236225db8687136cb1
--- /dev/null
+++ b/content/browser/gamepad/gamepad_service.h
@@ -0,0 +1,73 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Owns the GamepadProvider (the background polling thread) and keeps track of
+// the number of renderers currently using the data (and pausing the provider
+// when not in use).
+
+#ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H
+#define CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H
+
+#include "base/basictypes.h"
+#include "base/memory/singleton.h"
+#include "base/shared_memory.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+
+namespace content {
+
+class GamepadDataFetcher;
+class GamepadProvider;
+class RenderProcessHost;
+
+class GamepadService : public NotificationObserver,
+ public base::RefCountedThreadSafe<GamepadService> {
+ public:
+ // Returns the GamepadService singleton.
+ static GamepadService* GetInstance();
+
+ // Called on IO thread from a renderer host. Increments the number of users
+ // of the provider. The Provider is running when there's > 0 users, and is
+ // paused when the count drops to 0. There is no stop, the gamepad service
+ // registers with the RPH to be notified when the associated renderer closes
+ // (or crashes).
+ void Start(GamepadDataFetcher* fetcher,
+ RenderProcessHost* associated_rph);
+
+ base::SharedMemoryHandle GetSharedMemoryHandle(base::ProcessHandle handle);
+
+ // NotificationObserver overrides:
+ virtual void Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) OVERRIDE;
+
+ private:
+ friend struct DefaultSingletonTraits<GamepadService>;
+ friend class base::RefCountedThreadSafe<GamepadService>;
+ GamepadService();
+ virtual ~GamepadService();
+
+ // Called when a renderer that Start'd us is closed/crashes.
+ void Stop();
+
+ // Run on UI thread to receive notifications of renderer closes.
+ void RegisterForCloseNotification(RenderProcessHost* rph);
+
+ // A registrar for listening notifications. Used to listen for when an
+ // associated renderer has gone away (possibly crashed). We don't trust
+ // the renderers to send a stop message because of the possibility of
+ // crashing.
+ NotificationRegistrar registrar_;
+
+ int num_readers_;
+ scoped_refptr<GamepadProvider> provider_;
+
+ static GamepadService* instance_;
+
+ DISALLOW_COPY_AND_ASSIGN(GamepadService);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_SERVICE_H
« 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