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

Side by Side Diff: content/browser/gamepad/gamepad_provider.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 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
« no previous file with comments | « no previous file | content/browser/gamepad/gamepad_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_GAMEPAD_PROVIDER_H_ 5 #ifndef CONTENT_BROWSER_GAMEPAD_PROVIDER_H_
6 #define CONTENT_BROWSER_GAMEPAD_PROVIDER_H_ 6 #define CONTENT_BROWSER_GAMEPAD_PROVIDER_H_
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
11 #include "base/shared_memory.h" 11 #include "base/shared_memory.h"
12 #include "base/synchronization/lock.h"
12 #include "base/system_monitor/system_monitor.h" 13 #include "base/system_monitor/system_monitor.h"
13 #include "base/task.h" 14 #include "base/task.h"
14 #include "content/browser/gamepad/data_fetcher.h" 15 #include "content/browser/gamepad/data_fetcher.h"
15 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
16 #include "content/common/gamepad_hardware_buffer.h" 17 #include "content/common/gamepad_hardware_buffer.h"
17 18
18 namespace base { 19 namespace base {
19 class Thread; 20 class Thread;
20 } 21 }
21 22
22 struct GamepadMsg_Updated_Params; 23 struct GamepadMsg_Updated_Params;
23 24
24 namespace content { 25 namespace content {
25 26
26 class CONTENT_EXPORT GamepadProvider : 27 class CONTENT_EXPORT GamepadProvider :
27 public base::RefCountedThreadSafe<GamepadProvider>, 28 public base::RefCountedThreadSafe<GamepadProvider>,
28 public base::SystemMonitor::DevicesChangedObserver { 29 public base::SystemMonitor::DevicesChangedObserver {
29 public: 30 public:
30 explicit GamepadProvider(GamepadDataFetcher* fetcher); 31 explicit GamepadProvider(GamepadDataFetcher* fetcher);
31 32
32 // Starts or Stops the provider. Called from creator_loop_.
33 void Start();
34 void Stop();
35 base::SharedMemoryHandle GetRendererSharedMemoryHandle( 33 base::SharedMemoryHandle GetRendererSharedMemoryHandle(
36 base::ProcessHandle renderer_process); 34 base::ProcessHandle renderer_process);
37 35
36 void Pause();
37 void Resume();
38
38 private: 39 private:
39 friend class base::RefCountedThreadSafe<GamepadProvider>; 40 friend class base::RefCountedThreadSafe<GamepadProvider>;
40 41
41 virtual ~GamepadProvider(); 42 virtual ~GamepadProvider();
42 43
43 // Method for starting the polling, runs on polling_thread_. 44 // Method for starting the polling, runs on polling_thread_.
44 void DoInitializePollingThread(); 45 void DoInitializePollingThread();
45 46
46 // Method for polling a GamepadDataFetcher. Runs on the polling_thread_. 47 // Method for polling a GamepadDataFetcher. Runs on the polling_thread_.
47 void DoPoll(); 48 void DoPoll();
48 void ScheduleDoPoll(); 49 void ScheduleDoPoll();
49 50
50 virtual void OnDevicesChanged() OVERRIDE; 51 virtual void OnDevicesChanged() OVERRIDE;
51 52
52 GamepadHardwareBuffer* SharedMemoryAsHardwareBuffer(); 53 GamepadHardwareBuffer* SharedMemoryAsHardwareBuffer();
53 54
54 enum { kDesiredSamplingIntervalMs = 16 }; 55 enum { kDesiredSamplingIntervalMs = 16 };
55 56
57 base::Lock is_paused_lock_;
58 bool is_paused_;
59
60 base::Lock devices_changed_lock_;
61 bool devices_changed_;
62
56 // The Message Loop on which this object was created. 63 // The Message Loop on which this object was created.
57 // Typically the I/O loop, but may be something else during testing. 64 // Typically the I/O loop, but may be something else during testing.
58 scoped_refptr<base::MessageLoopProxy> creator_loop_; 65 scoped_refptr<base::MessageLoopProxy> creator_loop_;
59 scoped_ptr<GamepadDataFetcher> provided_fetcher_; 66 scoped_ptr<GamepadDataFetcher> provided_fetcher_;
60 67
61 // When polling_thread_ is running, members below are only to be used 68 // When polling_thread_ is running, members below are only to be used
62 // from that thread. 69 // from that thread.
63 scoped_ptr<GamepadDataFetcher> data_fetcher_; 70 scoped_ptr<GamepadDataFetcher> data_fetcher_;
64 base::SharedMemory gamepad_shared_memory_; 71 base::SharedMemory gamepad_shared_memory_;
65 bool devices_changed_;
66 72
67 // Polling is done on this background thread. 73 // Polling is done on this background thread.
68 scoped_ptr<base::Thread> polling_thread_; 74 scoped_ptr<base::Thread> polling_thread_;
69 75
70 static GamepadProvider* instance_; 76 static GamepadProvider* instance_;
71 base::WeakPtrFactory<GamepadProvider> weak_factory_; 77 base::WeakPtrFactory<GamepadProvider> weak_factory_;
72 78
73 DISALLOW_COPY_AND_ASSIGN(GamepadProvider); 79 DISALLOW_COPY_AND_ASSIGN(GamepadProvider);
74 }; 80 };
75 81
76 } // namespace content 82 } // namespace content
77 83
78 #endif // CONTENT_BROWSER_GAMEPAD_PROVIDER_H_ 84 #endif // CONTENT_BROWSER_GAMEPAD_PROVIDER_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/gamepad/gamepad_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698