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 #include <cmath> | 5 #include <cmath> |
6 #include <set> | 6 #include <set> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/task.h" | 12 #include "base/task.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
| 15 #include "content/browser/gamepad/data_fetcher.h" |
| 16 #include "content/browser/gamepad/gamepad_provider.h" |
| 17 #include "content/browser/gamepad/platform_data_fetcher.h" |
| 18 #include "content/common/gamepad_messages.h" |
15 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
16 #include "content/browser/gamepad/gamepad_provider.h" | |
17 #include "content/browser/gamepad/data_fetcher.h" | |
18 #include "content/common/gamepad_messages.h" | |
19 | |
20 #if defined(OS_WIN) | |
21 #include "content/browser/gamepad/data_fetcher_win.h" | |
22 #elif defined(OS_MACOSX) | |
23 #include "content/browser/gamepad/data_fetcher_mac.h" | |
24 #endif | |
25 | 20 |
26 namespace content { | 21 namespace content { |
27 | 22 |
28 // Define the default data fetcher that GamepadProvider will use if none is | |
29 // supplied. (GamepadPlatformDataFetcher). | |
30 #if defined(OS_WIN) | |
31 | |
32 typedef GamepadDataFetcherWindows GamepadPlatformDataFetcher; | |
33 | |
34 #elif defined(OS_MACOSX) | |
35 | |
36 typedef GamepadDataFetcherMac GamepadPlatformDataFetcher; | |
37 | |
38 #else | |
39 | |
40 class GamepadEmptyDataFetcher : public GamepadDataFetcher { | |
41 public: | |
42 void GetGamepadData(WebKit::WebGamepads* pads, bool) { | |
43 pads->length = 0; | |
44 } | |
45 }; | |
46 typedef GamepadEmptyDataFetcher GamepadPlatformDataFetcher; | |
47 | |
48 #endif | |
49 | |
50 GamepadProvider::GamepadProvider(GamepadDataFetcher* fetcher) | 23 GamepadProvider::GamepadProvider(GamepadDataFetcher* fetcher) |
51 : is_paused_(false), | 24 : is_paused_(false), |
52 devices_changed_(true), | 25 devices_changed_(true), |
53 provided_fetcher_(fetcher), | 26 provided_fetcher_(fetcher), |
54 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 27 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
55 size_t data_size = sizeof(GamepadHardwareBuffer); | 28 size_t data_size = sizeof(GamepadHardwareBuffer); |
56 base::SystemMonitor* monitor = base::SystemMonitor::Get(); | 29 base::SystemMonitor* monitor = base::SystemMonitor::Get(); |
57 if (monitor) | 30 if (monitor) |
58 monitor->AddDevicesChangedObserver(this); | 31 monitor->AddDevicesChangedObserver(this); |
59 gamepad_shared_memory_.CreateAndMapAnonymous(data_size); | 32 gamepad_shared_memory_.CreateAndMapAnonymous(data_size); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 kDesiredSamplingIntervalMs); | 142 kDesiredSamplingIntervalMs); |
170 } | 143 } |
171 | 144 |
172 GamepadHardwareBuffer* GamepadProvider::SharedMemoryAsHardwareBuffer() { | 145 GamepadHardwareBuffer* GamepadProvider::SharedMemoryAsHardwareBuffer() { |
173 void* mem = gamepad_shared_memory_.memory(); | 146 void* mem = gamepad_shared_memory_.memory(); |
174 DCHECK(mem); | 147 DCHECK(mem); |
175 return static_cast<GamepadHardwareBuffer*>(mem); | 148 return static_cast<GamepadHardwareBuffer*>(mem); |
176 } | 149 } |
177 | 150 |
178 } // namespace content | 151 } // namespace content |
OLD | NEW |