| OLD | NEW | 
|    1 // Copyright (c) 2012 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/public/browser/browser_thread.h" | 
 |   16 #include "content/browser/gamepad/gamepad_provider.h" | 
|   15 #include "content/browser/gamepad/data_fetcher.h" |   17 #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" |   18 #include "content/common/gamepad_messages.h" | 
|   19 #include "content/public/browser/browser_thread.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 | 
|   20  |   25  | 
|   21 namespace content { |   26 namespace content { | 
|   22  |   27  | 
 |   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  | 
|   23 GamepadProvider::GamepadProvider(GamepadDataFetcher* fetcher) |   50 GamepadProvider::GamepadProvider(GamepadDataFetcher* fetcher) | 
|   24     : is_paused_(false), |   51     : is_paused_(false), | 
|   25       devices_changed_(true), |   52       devices_changed_(true), | 
|   26       provided_fetcher_(fetcher), |   53       provided_fetcher_(fetcher), | 
|   27       ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |   54       ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 
|   28   size_t data_size = sizeof(GamepadHardwareBuffer); |   55   size_t data_size = sizeof(GamepadHardwareBuffer); | 
|   29   base::SystemMonitor* monitor = base::SystemMonitor::Get(); |   56   base::SystemMonitor* monitor = base::SystemMonitor::Get(); | 
|   30   if (monitor) |   57   if (monitor) | 
|   31     monitor->AddDevicesChangedObserver(this); |   58     monitor->AddDevicesChangedObserver(this); | 
|   32   bool res = gamepad_shared_memory_.CreateAndMapAnonymous(data_size); |   59   bool res = gamepad_shared_memory_.CreateAndMapAnonymous(data_size); | 
|   33   DCHECK(res); |   60   DCHECK(res); | 
|   34   GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); |   61   GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); | 
|   35   memset(hwbuf, 0, sizeof(GamepadHardwareBuffer)); |   62   memset(hwbuf, 0, sizeof(GamepadHardwareBuffer)); | 
|   36  |   63  | 
|   37   polling_thread_.reset(new base::Thread("Gamepad polling thread")); |   64   polling_thread_.reset(new base::Thread("Gamepad polling thread")); | 
|   38   polling_thread_->StartWithOptions( |   65   polling_thread_->Start(); | 
|   39       base::Thread::Options(MessageLoop::TYPE_IO, 0)); |  | 
|   40  |   66  | 
|   41   MessageLoop* polling_loop = polling_thread_->message_loop(); |   67   MessageLoop* polling_loop = polling_thread_->message_loop(); | 
|   42   polling_loop->PostTask( |   68   polling_loop->PostTask( | 
|   43       FROM_HERE, |   69       FROM_HERE, | 
|   44       base::Bind(&GamepadProvider::DoInitializePollingThread, this)); |   70       base::Bind(&GamepadProvider::DoInitializePollingThread, this)); | 
|   45 } |   71 } | 
|   46  |   72  | 
|   47 GamepadProvider::~GamepadProvider() { |   73 GamepadProvider::~GamepadProvider() { | 
|   48   base::SystemMonitor* monitor = base::SystemMonitor::Get(); |   74   base::SystemMonitor* monitor = base::SystemMonitor::Get(); | 
|   49   if (monitor) |   75   if (monitor) | 
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  144       kDesiredSamplingIntervalMs); |  170       kDesiredSamplingIntervalMs); | 
|  145 } |  171 } | 
|  146  |  172  | 
|  147 GamepadHardwareBuffer* GamepadProvider::SharedMemoryAsHardwareBuffer() { |  173 GamepadHardwareBuffer* GamepadProvider::SharedMemoryAsHardwareBuffer() { | 
|  148   void* mem = gamepad_shared_memory_.memory(); |  174   void* mem = gamepad_shared_memory_.memory(); | 
|  149   DCHECK(mem); |  175   DCHECK(mem); | 
|  150   return static_cast<GamepadHardwareBuffer*>(mem); |  176   return static_cast<GamepadHardwareBuffer*>(mem); | 
|  151 } |  177 } | 
|  152  |  178  | 
|  153 }  // namespace content |  179 }  // namespace content | 
| OLD | NEW |