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