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

Side by Side Diff: content/browser/gamepad/gamepad_provider.h

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 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 // Pause and resume the background polling thread. Can be called from any
37 // thread.
38 void Pause();
39 void Resume();
40
38 private: 41 private:
39 friend class base::RefCountedThreadSafe<GamepadProvider>; 42 friend class base::RefCountedThreadSafe<GamepadProvider>;
40 43
41 virtual ~GamepadProvider(); 44 virtual ~GamepadProvider();
42 45
43 // Method for starting the polling, runs on polling_thread_. 46 // Method for starting the polling, runs on polling_thread_.
44 void DoInitializePollingThread(); 47 void DoInitializePollingThread();
45 48
46 // Method for polling a GamepadDataFetcher. Runs on the polling_thread_. 49 // Method for polling a GamepadDataFetcher. Runs on the polling_thread_.
47 void DoPoll(); 50 void DoPoll();
48 void ScheduleDoPoll(); 51 void ScheduleDoPoll();
49 52
50 virtual void OnDevicesChanged() OVERRIDE; 53 virtual void OnDevicesChanged() OVERRIDE;
51 54
52 GamepadHardwareBuffer* SharedMemoryAsHardwareBuffer(); 55 GamepadHardwareBuffer* SharedMemoryAsHardwareBuffer();
53 56
54 enum { kDesiredSamplingIntervalMs = 16 }; 57 enum { kDesiredSamplingIntervalMs = 16 };
55 58
59 // Keeps track of when the background thread is paused. Access to is_paused_
60 // must be guarded by is_paused_lock_.
61 base::Lock is_paused_lock_;
62 bool is_paused_;
63
64 // Updated based on notification from SystemMonitor when the system devices
65 // have been updated, and this notification is passed on to the data fetcher
66 // to enable it to avoid redundant (and possibly expensive) is-connected
67 // tests. Access to devices_changed_ must be guarded by
68 // devices_changed_lock_.
69 base::Lock devices_changed_lock_;
70 bool devices_changed_;
71
56 // The Message Loop on which this object was created. 72 // The Message Loop on which this object was created.
57 // Typically the I/O loop, but may be something else during testing. 73 // Typically the I/O loop, but may be something else during testing.
58 scoped_refptr<base::MessageLoopProxy> creator_loop_;
59 scoped_ptr<GamepadDataFetcher> provided_fetcher_; 74 scoped_ptr<GamepadDataFetcher> provided_fetcher_;
60 75
61 // When polling_thread_ is running, members below are only to be used 76 // When polling_thread_ is running, members below are only to be used
62 // from that thread. 77 // from that thread.
63 scoped_ptr<GamepadDataFetcher> data_fetcher_; 78 scoped_ptr<GamepadDataFetcher> data_fetcher_;
64 base::SharedMemory gamepad_shared_memory_; 79 base::SharedMemory gamepad_shared_memory_;
65 bool devices_changed_;
66 80
67 // Polling is done on this background thread. 81 // Polling is done on this background thread.
68 scoped_ptr<base::Thread> polling_thread_; 82 scoped_ptr<base::Thread> polling_thread_;
69 83
70 static GamepadProvider* instance_; 84 static GamepadProvider* instance_;
71 base::WeakPtrFactory<GamepadProvider> weak_factory_; 85 base::WeakPtrFactory<GamepadProvider> weak_factory_;
72 86
73 DISALLOW_COPY_AND_ASSIGN(GamepadProvider); 87 DISALLOW_COPY_AND_ASSIGN(GamepadProvider);
74 }; 88 };
75 89
76 } // namespace content 90 } // namespace content
77 91
78 #endif // CONTENT_BROWSER_GAMEPAD_PROVIDER_H_ 92 #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