Chromium Code Reviews| Index: content/browser/gamepad/gamepad_provider.h |
| diff --git a/content/browser/gamepad/gamepad_provider.h b/content/browser/gamepad/gamepad_provider.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0e7edcb60997a97f3d98862c7244f07fb51f9f14 |
| --- /dev/null |
| +++ b/content/browser/gamepad/gamepad_provider.h |
| @@ -0,0 +1,99 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_GAMEPAD_PROVIDER_H_ |
| +#define CONTENT_BROWSER_GAMEPAD_PROVIDER_H_ |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/shared_memory.h" |
| +#include "base/system_monitor/system_monitor.h" |
| +#include "base/task.h" |
| +#include "content/browser/gamepad/data_fetcher.h" |
| +#include "content/common/gamepad_hardware_buffer.h" |
| +#include "webkit/glue/gamepad_util.h" |
| +#if defined(OS_WIN) |
| +#include "content/browser/gamepad/data_fetcher_win.h" |
| +#endif |
| + |
| +class MessageLoop; |
| + |
| +namespace base { |
| +class Thread; |
| +} |
| + |
| +struct GamepadMsg_Updated_Params; |
| + |
| +namespace gamepad { |
| + |
| +// Define the default data fetcher that Provider will use if none is supplied. |
| +// (PlatformDataFetcher). |
| +#if defined(OS_WIN) |
| + |
| +typedef DataFetcherWindows PlatformDataFetcher; |
| + |
| +#else |
| + |
| +class EmptyDataFetcher { |
| + public: |
| + void GetGamepadData(WebKit::WebGamepads& pads, bool) { |
| + pads.length = 0; |
| + } |
| +}; |
| +typedef EmptyDataFetcher PlatformDataFetcher; |
| + |
| +#endif |
| + |
| +class Provider : public base::RefCountedThreadSafe<Provider>, |
| + public base::SystemMonitor::DevicesChangedObserver { |
| + public: |
| + 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.
|
| + |
| + // Starts or Stops the provider. Called from creator_loop_. |
| + void Start(); |
| + void Stop(); |
| + base::SharedMemoryHandle GetRendererSharedMemoryHandle( |
| + base::ProcessHandle renderer_process); |
| + |
| + private: |
| + |
|
jam
2011/11/16 00:24:58
nit: no blank line after private
scottmg
2011/11/16 18:04:35
Done.
|
| + // Method for starting the polling, runs on polling_thread_. |
| + void DoInitializePollingThread(); |
| + |
| + // Method for polling a DataFetcher. Runs on the polling_thread_. |
| + void DoPoll(); |
| + void ScheduleDoPoll(); |
| + |
| + void OnDevicesChanged() OVERRIDE; |
| + |
| + GamepadHardwareBuffer* SharedMemoryAsHardwareBuffer(); |
| + |
| + enum { kDesiredSamplingIntervalMs = 16 }; |
| + |
| + // The Message Loop on which this object was created. |
| + // Typically the I/O loop, but may be something else during testing. |
| + MessageLoop* creator_loop_; |
|
jam
2011/11/16 00:24:58
nit: we prefer MessageLoopProxy
scottmg
2011/11/16 18:04:35
Done.
|
| + scoped_ptr<DataFetcher> provided_fetcher_; |
| + |
| + // When polling_thread_ is running, members below are only to be used |
| + // from that thread. |
| + scoped_ptr<DataFetcher> data_fetcher_; |
| + base::SharedMemory gamepad_shared_memory_; |
| + bool devices_changed_; |
| + |
| + // Polling is done on this background thread. |
| + scoped_ptr<base::Thread> polling_thread_; |
| + |
| + 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.
|
| + static Provider* instance_; |
| + base::WeakPtrFactory<Provider> weak_factory_; |
| + |
| + 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.
|
| + friend class base::RefCountedThreadSafe<Provider>; |
|
jam
2011/11/16 00:24:58
nit: duplicated
scottmg
2011/11/16 18:04:35
Done.
|
| + virtual ~Provider(); |
|
jam
2011/11/16 00:24:58
nit: functions are listed before variables. usuall
scottmg
2011/11/16 18:04:35
Done.
|
| +}; |
| + |
| +} // namespace gamepad |
| + |
| +#endif // CONTENT_BROWSER_GAMEPAD_PROVIDER_H_ |