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

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

Issue 8760023: Add GamepadService, owns 1 gamepad bg thread (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: merge HEAD 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..a6e90d3acca3c6c9044c25c69d5f97088c5cd791
--- /dev/null
+++ b/content/browser/gamepad/gamepad_service.cc
@@ -0,0 +1,76 @@
+// 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 "base/bind.h"
+#include "base/memory/singleton.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() : num_readers_(0) {
+}
+
+GamepadService::~GamepadService() {
+}
+
+GamepadService* GamepadService::GetInstance() {
+ return Singleton<GamepadService>::get();
+}
+
+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,
+ base::Unretained(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) {
+ return provider_->GetRendererSharedMemoryHandle(handle);
+}
+
+void GamepadService::Stop() {
+ --num_readers_;
+ DCHECK(num_readers_ >= 0);
+
+ if (num_readers_ == 0)
+ provider_->Pause();
+}
+
+void GamepadService::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED);
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&GamepadService::Stop, base::Unretained(this)));
+}
+
+} // 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