OLD | NEW |
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/system_monitor/system_monitor.h" | 12 #include "base/system_monitor/system_monitor.h" |
13 #include "base/task.h" | 13 #include "base/task.h" |
14 #include "content/browser/gamepad/data_fetcher.h" | 14 #include "content/browser/gamepad/data_fetcher.h" |
15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
16 #include "content/common/gamepad_hardware_buffer.h" | 16 #include "content/common/gamepad_hardware_buffer.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class Thread; | 19 class Thread; |
20 } | 20 } |
21 | 21 |
22 struct GamepadMsg_Updated_Params; | 22 struct GamepadMsg_Updated_Params; |
23 | 23 |
24 namespace gamepad { | 24 namespace content { |
25 | 25 |
26 class CONTENT_EXPORT Provider : | 26 class CONTENT_EXPORT GamepadProvider : |
27 public base::RefCountedThreadSafe<Provider>, | 27 public base::RefCountedThreadSafe<GamepadProvider>, |
28 public base::SystemMonitor::DevicesChangedObserver { | 28 public base::SystemMonitor::DevicesChangedObserver { |
29 public: | 29 public: |
30 explicit Provider(DataFetcher* fetcher); | 30 explicit GamepadProvider(GamepadDataFetcher* fetcher); |
31 | 31 |
32 // Starts or Stops the provider. Called from creator_loop_. | 32 // Starts or Stops the provider. Called from creator_loop_. |
33 void Start(); | 33 void Start(); |
34 void Stop(); | 34 void Stop(); |
35 base::SharedMemoryHandle GetRendererSharedMemoryHandle( | 35 base::SharedMemoryHandle GetRendererSharedMemoryHandle( |
36 base::ProcessHandle renderer_process); | 36 base::ProcessHandle renderer_process); |
37 | 37 |
38 private: | 38 private: |
39 friend class base::RefCountedThreadSafe<Provider>; | 39 friend class base::RefCountedThreadSafe<GamepadProvider>; |
40 | 40 |
41 virtual ~Provider(); | 41 virtual ~GamepadProvider(); |
42 | 42 |
43 // Method for starting the polling, runs on polling_thread_. | 43 // Method for starting the polling, runs on polling_thread_. |
44 void DoInitializePollingThread(); | 44 void DoInitializePollingThread(); |
45 | 45 |
46 // Method for polling a DataFetcher. Runs on the polling_thread_. | 46 // Method for polling a GamepadDataFetcher. Runs on the polling_thread_. |
47 void DoPoll(); | 47 void DoPoll(); |
48 void ScheduleDoPoll(); | 48 void ScheduleDoPoll(); |
49 | 49 |
50 virtual void OnDevicesChanged() OVERRIDE; | 50 virtual void OnDevicesChanged() OVERRIDE; |
51 | 51 |
52 GamepadHardwareBuffer* SharedMemoryAsHardwareBuffer(); | 52 GamepadHardwareBuffer* SharedMemoryAsHardwareBuffer(); |
53 | 53 |
54 enum { kDesiredSamplingIntervalMs = 16 }; | 54 enum { kDesiredSamplingIntervalMs = 16 }; |
55 | 55 |
56 // The Message Loop on which this object was created. | 56 // The Message Loop on which this object was created. |
57 // Typically the I/O loop, but may be something else during testing. | 57 // Typically the I/O loop, but may be something else during testing. |
58 scoped_refptr<base::MessageLoopProxy> creator_loop_; | 58 scoped_refptr<base::MessageLoopProxy> creator_loop_; |
59 scoped_ptr<DataFetcher> provided_fetcher_; | 59 scoped_ptr<GamepadDataFetcher> provided_fetcher_; |
60 | 60 |
61 // When polling_thread_ is running, members below are only to be used | 61 // When polling_thread_ is running, members below are only to be used |
62 // from that thread. | 62 // from that thread. |
63 scoped_ptr<DataFetcher> data_fetcher_; | 63 scoped_ptr<GamepadDataFetcher> data_fetcher_; |
64 base::SharedMemory gamepad_shared_memory_; | 64 base::SharedMemory gamepad_shared_memory_; |
65 bool devices_changed_; | 65 bool devices_changed_; |
66 | 66 |
67 // Polling is done on this background thread. | 67 // Polling is done on this background thread. |
68 scoped_ptr<base::Thread> polling_thread_; | 68 scoped_ptr<base::Thread> polling_thread_; |
69 | 69 |
70 static Provider* instance_; | 70 static GamepadProvider* instance_; |
71 base::WeakPtrFactory<Provider> weak_factory_; | 71 base::WeakPtrFactory<GamepadProvider> weak_factory_; |
72 | 72 |
73 DISALLOW_COPY_AND_ASSIGN(Provider); | 73 DISALLOW_COPY_AND_ASSIGN(GamepadProvider); |
74 }; | 74 }; |
75 | 75 |
76 } // namespace gamepad | 76 } // namespace content |
77 | 77 |
78 #endif // CONTENT_BROWSER_GAMEPAD_PROVIDER_H_ | 78 #endif // CONTENT_BROWSER_GAMEPAD_PROVIDER_H_ |
OLD | NEW |