Chromium Code Reviews| 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/shared_memory.h" | |
| 11 #include "base/system_monitor/system_monitor.h" | |
| 12 #include "base/task.h" | |
| 13 #include "content/browser/gamepad/data_fetcher.h" | |
| 14 #include "content/common/gamepad_hardware_buffer.h" | |
| 15 #include "webkit/glue/gamepad_util.h" | |
| 16 #if defined(OS_WIN) | |
| 17 #include "content/browser/gamepad/data_fetcher_win.h" | |
| 18 #endif | |
| 19 | |
| 20 class MessageLoop; | |
| 21 | |
| 22 namespace base { | |
| 23 class Thread; | |
| 24 } | |
| 25 | |
| 26 struct GamepadMsg_Updated_Params; | |
| 27 | |
| 28 namespace gamepad { | |
| 29 | |
| 30 // Define the default data fetcher that Provider will use if none is supplied. | |
| 31 // (PlatformDataFetcher). | |
| 32 #if defined(OS_WIN) | |
| 33 | |
| 34 typedef DataFetcherWindows PlatformDataFetcher; | |
| 35 | |
| 36 #else | |
| 37 | |
| 38 class EmptyDataFetcher { | |
| 39 public: | |
| 40 void GetGamepadData(WebKit::WebGamepads& pads, bool) { | |
| 41 pads.length = 0; | |
| 42 } | |
| 43 }; | |
| 44 typedef EmptyDataFetcher PlatformDataFetcher; | |
| 45 | |
| 46 #endif | |
| 47 | |
| 48 class Provider : public base::RefCountedThreadSafe<Provider>, | |
| 49 public base::SystemMonitor::DevicesChangedObserver { | |
| 50 public: | |
| 51 Provider(DataFetcher* fetcher = NULL); | |
|
jam
2011/11/16 00:24:58
nit: use explicit and no default parameters, per s
scottmg
2011/11/16 18:04:35
Done.
| |
| 52 | |
| 53 // Starts or Stops the provider. Called from creator_loop_. | |
| 54 void Start(); | |
| 55 void Stop(); | |
| 56 base::SharedMemoryHandle GetRendererSharedMemoryHandle( | |
| 57 base::ProcessHandle renderer_process); | |
| 58 | |
| 59 private: | |
| 60 | |
|
jam
2011/11/16 00:24:58
nit: no blank line after private
scottmg
2011/11/16 18:04:35
Done.
| |
| 61 // Method for starting the polling, runs on polling_thread_. | |
| 62 void DoInitializePollingThread(); | |
| 63 | |
| 64 // Method for polling a DataFetcher. Runs on the polling_thread_. | |
| 65 void DoPoll(); | |
| 66 void ScheduleDoPoll(); | |
| 67 | |
| 68 void OnDevicesChanged() OVERRIDE; | |
| 69 | |
| 70 GamepadHardwareBuffer* SharedMemoryAsHardwareBuffer(); | |
| 71 | |
| 72 enum { kDesiredSamplingIntervalMs = 16 }; | |
| 73 | |
| 74 // The Message Loop on which this object was created. | |
| 75 // Typically the I/O loop, but may be something else during testing. | |
| 76 MessageLoop* creator_loop_; | |
|
jam
2011/11/16 00:24:58
nit: we prefer MessageLoopProxy
scottmg
2011/11/16 18:04:35
Done.
| |
| 77 scoped_ptr<DataFetcher> provided_fetcher_; | |
| 78 | |
| 79 // When polling_thread_ is running, members below are only to be used | |
| 80 // from that thread. | |
| 81 scoped_ptr<DataFetcher> data_fetcher_; | |
| 82 base::SharedMemory gamepad_shared_memory_; | |
| 83 bool devices_changed_; | |
| 84 | |
| 85 // Polling is done on this background thread. | |
| 86 scoped_ptr<base::Thread> polling_thread_; | |
| 87 | |
| 88 friend class base::RefCountedThreadSafe<Provider>; | |
|
jam
2011/11/16 00:24:58
nit: friend statements usually go right after the
scottmg
2011/11/16 18:04:35
Done.
| |
| 89 static Provider* instance_; | |
| 90 base::WeakPtrFactory<Provider> weak_factory_; | |
| 91 | |
| 92 DISALLOW_COPY_AND_ASSIGN(Provider); | |
|
jam
2011/11/16 00:24:58
nit: this usually goes last
scottmg
2011/11/16 18:04:35
Done.
| |
| 93 friend class base::RefCountedThreadSafe<Provider>; | |
|
jam
2011/11/16 00:24:58
nit: duplicated
scottmg
2011/11/16 18:04:35
Done.
| |
| 94 virtual ~Provider(); | |
|
jam
2011/11/16 00:24:58
nit: functions are listed before variables. usuall
scottmg
2011/11/16 18:04:35
Done.
| |
| 95 }; | |
| 96 | |
| 97 } // namespace gamepad | |
| 98 | |
| 99 #endif // CONTENT_BROWSER_GAMEPAD_PROVIDER_H_ | |
| OLD | NEW |