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

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

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
Index: content/browser/gamepad/gamepad_service.cc
diff --git a/content/browser/gamepad/gamepad_service.cc b/content/browser/gamepad/gamepad_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..424518cbbe51800e4503602bb1a1dccc67a446ef
--- /dev/null
+++ b/content/browser/gamepad/gamepad_service.cc
@@ -0,0 +1,89 @@
+// 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.
+
+#include "content/browser/gamepad/gamepad_service.h"
+
+#include "content/browser/gamepad/data_fetcher.h"
+#include "content/browser/gamepad/gamepad_provider.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_source.h"
+#include "content/public/browser/notification_types.h"
+#include "content/public/browser/render_process_host.h"
+
+namespace content {
+
+GamepadService* GamepadService::instance_;
+
+GamepadService::GamepadService() : num_readers_(0) {
+}
+
+GamepadService::~GamepadService() {
+}
+
+GamepadService* GamepadService::GetInstance() {
+ if (!instance_) {
+ instance_ = new GamepadService();
+ instance_->AddRef();
+ }
+ return instance_;
+}
+
+void GamepadService::Start(
+ GamepadDataFetcher* data_fetcher,
+ content::RenderProcessHost* associated_rph) {
+ num_readers_++;
+ if (!provider_)
+ provider_ = new GamepadProvider(data_fetcher);
+ DCHECK(num_readers_ > 0);
+ provider_->Resume();
+
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&GamepadService::RegisterForCloseNotification,
+ this,
+ associated_rph));
+}
+
+void GamepadService::RegisterForCloseNotification(
+ content::RenderProcessHost* rph) {
+ registrar_.Add(this,
+ content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
+ content::Source<content::RenderProcessHost>(rph));
+}
+
+base::SharedMemoryHandle GamepadService::GetSharedMemoryHandle(
+ base::ProcessHandle handle) {
+ DCHECK(provider_);
+ return provider_->GetRendererSharedMemoryHandle(handle);
+}
+
+void GamepadService::Stop() {
+ --num_readers_;
+ DCHECK(provider_);
+ DCHECK(num_readers_ >= 0);
+
+ if (num_readers_ == 0)
+ provider_->Pause();
+}
+
+void GamepadService::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ switch (type) {
+ case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: {
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&GamepadService::Stop, this));
+ break;
+ }
+ default: {
+ break;
+ }
+ }
+}
+
+} // namespace content
« no previous file with comments | « content/browser/gamepad/gamepad_service.h ('k') | content/browser/renderer_host/gamepad_browser_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698