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

Side by Side 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 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
OLDNEW
(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 #include "content/browser/gamepad/gamepad_service.h"
6
7 #include "content/browser/gamepad/data_fetcher.h"
8 #include "content/browser/gamepad/gamepad_provider.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/notification_service.h"
11 #include "content/public/browser/notification_source.h"
12 #include "content/public/browser/notification_types.h"
13 #include "content/public/browser/render_process_host.h"
14
15 namespace content {
16
17 GamepadService* GamepadService::instance_;
18
19 GamepadService::GamepadService() : num_readers_(0) {
20 }
21
22 GamepadService::~GamepadService() {
23 }
24
25 GamepadService* GamepadService::GetInstance() {
26 if (!instance_) {
27 instance_ = new GamepadService();
28 instance_->AddRef();
29 }
30 return instance_;
31 }
32
33 void GamepadService::Start(
34 GamepadDataFetcher* data_fetcher,
35 content::RenderProcessHost* associated_rph) {
36 num_readers_++;
37 if (!provider_)
38 provider_ = new GamepadProvider(data_fetcher);
39 DCHECK(num_readers_ > 0);
40 provider_->Resume();
41
42 content::BrowserThread::PostTask(
43 content::BrowserThread::UI,
44 FROM_HERE,
45 base::Bind(&GamepadService::RegisterForCloseNotification,
46 this,
47 associated_rph));
48 }
49
50 void GamepadService::RegisterForCloseNotification(
51 content::RenderProcessHost* rph) {
52 registrar_.Add(this,
53 content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
54 content::Source<content::RenderProcessHost>(rph));
55 }
56
57 base::SharedMemoryHandle GamepadService::GetSharedMemoryHandle(
58 base::ProcessHandle handle) {
59 DCHECK(provider_);
60 return provider_->GetRendererSharedMemoryHandle(handle);
61 }
62
63 void GamepadService::Stop() {
64 --num_readers_;
65 DCHECK(provider_);
66 DCHECK(num_readers_ >= 0);
67
68 if (num_readers_ == 0)
69 provider_->Pause();
70 }
71
72 void GamepadService::Observe(int type,
73 const content::NotificationSource& source,
74 const content::NotificationDetails& details) {
75 switch (type) {
76 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: {
77 content::BrowserThread::PostTask(
78 content::BrowserThread::IO,
79 FROM_HERE,
80 base::Bind(&GamepadService::Stop, this));
81 break;
82 }
83 default: {
84 break;
85 }
86 }
87 }
88
89 } // namespace content
OLDNEW
« 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