Commit 2a92b328 authored by thestig@chromium.org's avatar thestig@chromium.org

Cleanup: More random cleanup for gamepad code.

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/9514017

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124398 0039d316-1c4b-4281-b951-d872f2087c98
parent 45e29542
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "content/browser/gamepad/data_fetcher.h" #include "content/browser/gamepad/data_fetcher.h"
#include "content/browser/gamepad/gamepad_provider.h" #include "content/browser/gamepad/gamepad_provider.h"
#include "content/browser/gamepad/platform_data_fetcher.h" #include "content/browser/gamepad/platform_data_fetcher.h"
#include "content/common/gamepad_hardware_buffer.h"
#include "content/common/gamepad_messages.h" #include "content/common/gamepad_messages.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
......
...@@ -11,21 +11,20 @@ ...@@ -11,21 +11,20 @@
#include "base/shared_memory.h" #include "base/shared_memory.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/system_monitor/system_monitor.h" #include "base/system_monitor/system_monitor.h"
#include "content/browser/gamepad/data_fetcher.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/common/gamepad_hardware_buffer.h"
namespace base { namespace base {
class Thread; class Thread;
} }
struct GamepadMsg_Updated_Params;
namespace content { namespace content {
class GamepadDataFetcher;
struct GamepadHardwareBuffer;
class CONTENT_EXPORT GamepadProvider : class CONTENT_EXPORT GamepadProvider :
public base::RefCountedThreadSafe<GamepadProvider>, public base::RefCountedThreadSafe<GamepadProvider>,
public base::SystemMonitor::DevicesChangedObserver { public base::SystemMonitor::DevicesChangedObserver {
public: public:
explicit GamepadProvider(GamepadDataFetcher* fetcher); explicit GamepadProvider(GamepadDataFetcher* fetcher);
...@@ -37,6 +36,9 @@ class CONTENT_EXPORT GamepadProvider : ...@@ -37,6 +36,9 @@ class CONTENT_EXPORT GamepadProvider :
void Pause(); void Pause();
void Resume(); void Resume();
// base::SystemMonitor::DevicesChangedObserver implementation.
virtual void OnDevicesChanged() OVERRIDE;
private: private:
friend class base::RefCountedThreadSafe<GamepadProvider>; friend class base::RefCountedThreadSafe<GamepadProvider>;
...@@ -49,8 +51,6 @@ class CONTENT_EXPORT GamepadProvider : ...@@ -49,8 +51,6 @@ class CONTENT_EXPORT GamepadProvider :
void DoPoll(); void DoPoll();
void ScheduleDoPoll(); void ScheduleDoPoll();
virtual void OnDevicesChanged() OVERRIDE;
GamepadHardwareBuffer* SharedMemoryAsHardwareBuffer(); GamepadHardwareBuffer* SharedMemoryAsHardwareBuffer();
enum { kDesiredSamplingIntervalMs = 16 }; enum { kDesiredSamplingIntervalMs = 16 };
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -6,9 +6,12 @@ ...@@ -6,9 +6,12 @@
#include "base/process_util.h" #include "base/process_util.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/system_monitor/system_monitor.h" #include "base/system_monitor/system_monitor.h"
#include "content/browser/gamepad/data_fetcher.h"
#include "content/browser/gamepad/gamepad_provider.h" #include "content/browser/gamepad/gamepad_provider.h"
#include "content/common/gamepad_hardware_buffer.h"
#include "content/common/gamepad_messages.h" #include "content/common/gamepad_messages.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.h"
namespace content { namespace content {
...@@ -18,8 +21,9 @@ using WebKit::WebGamepads; ...@@ -18,8 +21,9 @@ using WebKit::WebGamepads;
class MockDataFetcher : public GamepadDataFetcher { class MockDataFetcher : public GamepadDataFetcher {
public: public:
MockDataFetcher(WebGamepads& test_data) : read_data_(false, false) { explicit MockDataFetcher(const WebGamepads& test_data)
test_data_ = test_data; : test_data_(test_data),
read_data_(false, false) {
} }
virtual void GetGamepadData(WebGamepads* pads, virtual void GetGamepadData(WebGamepads* pads,
bool devices_changed_hint) OVERRIDE { bool devices_changed_hint) OVERRIDE {
...@@ -36,7 +40,7 @@ class MockDataFetcher : public GamepadDataFetcher { ...@@ -36,7 +40,7 @@ class MockDataFetcher : public GamepadDataFetcher {
// Main test fixture // Main test fixture
class GamepadProviderTest : public testing::Test { class GamepadProviderTest : public testing::Test {
public: public:
GamepadProvider* CreateProvider(WebGamepads& test_data) { GamepadProvider* CreateProvider(const WebGamepads& test_data) {
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
base::SystemMonitor::AllocateSystemIOPorts(); base::SystemMonitor::AllocateSystemIOPorts();
#endif #endif
...@@ -102,4 +106,4 @@ TEST_F(GamepadProviderTest, DISABLED_PollingAccess) { ...@@ -102,4 +106,4 @@ TEST_F(GamepadProviderTest, DISABLED_PollingAccess) {
} // namespace } // namespace
} // namespace content } // namespace content
...@@ -30,6 +30,33 @@ void CloseFileDescriptorIfValid(int fd) { ...@@ -30,6 +30,33 @@ void CloseFileDescriptorIfValid(int fd) {
close(fd); close(fd);
} }
bool IsGamepad(udev_device* dev, int* index, std::string* path) {
if (!udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK"))
return false;
const char* node_path = udev_device_get_devnode(dev);
if (!node_path)
return false;
static const char kJoystickRoot[] = "/dev/input/js";
bool is_gamepad = StartsWithASCII(node_path, kJoystickRoot, true);
if (!is_gamepad)
return false;
int tmp_idx = -1;
const int base_len = sizeof(kJoystickRoot) - 1;
base::StringPiece str(&node_path[base_len], strlen(node_path) - base_len);
if (!base::StringToInt(str, &tmp_idx))
return false;
if (tmp_idx < 0 ||
tmp_idx >= static_cast<int>(WebKit::WebGamepads::itemsLengthCap)) {
return false;
}
*index = tmp_idx;
*path = node_path;
return true;
}
} // namespace } // namespace
namespace content { namespace content {
...@@ -108,33 +135,6 @@ void GamepadPlatformDataFetcherLinux::OnFileCanReadWithoutBlocking(int fd) { ...@@ -108,33 +135,6 @@ void GamepadPlatformDataFetcherLinux::OnFileCanReadWithoutBlocking(int fd) {
void GamepadPlatformDataFetcherLinux::OnFileCanWriteWithoutBlocking(int fd) { void GamepadPlatformDataFetcherLinux::OnFileCanWriteWithoutBlocking(int fd) {
} }
bool GamepadPlatformDataFetcherLinux::IsGamepad(udev_device* dev,
int* index,
std::string* path) {
if (!udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK"))
return false;
const char* node_path = udev_device_get_devnode(dev);
if (!node_path)
return false;
static const char kJoystickRoot[] = "/dev/input/js";
bool is_gamepad = StartsWithASCII(node_path, kJoystickRoot, true);
if (!is_gamepad)
return false;
int tmp_idx = -1;
const int base_len = sizeof(kJoystickRoot) - 1;
base::StringPiece str(&node_path[base_len], strlen(node_path) - base_len);
if (!base::StringToInt(str, &tmp_idx))
return false;
if (tmp_idx < 0 || tmp_idx >= static_cast<int>(WebGamepads::itemsLengthCap))
return false;
*index = tmp_idx;
*path = node_path;
return true;
}
// Used during enumeration, and monitor notifications. // Used during enumeration, and monitor notifications.
void GamepadPlatformDataFetcherLinux::RefreshDevice(udev_device* dev) { void GamepadPlatformDataFetcherLinux::RefreshDevice(udev_device* dev) {
int index; int index;
...@@ -228,7 +228,7 @@ void GamepadPlatformDataFetcherLinux::ReadDeviceData(size_t index) { ...@@ -228,7 +228,7 @@ void GamepadPlatformDataFetcherLinux::ReadDeviceData(size_t index) {
return; return;
} }
int& fd = device_fds_[index]; const int& fd = device_fds_[index];
WebGamepad& pad = data_.items[index]; WebGamepad& pad = data_.items[index];
DCHECK_GE(fd, 0); DCHECK_GE(fd, 0);
......
...@@ -39,7 +39,6 @@ class GamepadPlatformDataFetcherLinux : ...@@ -39,7 +39,6 @@ class GamepadPlatformDataFetcherLinux :
virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
private: private:
bool IsGamepad(udev_device* dev, int* index, std::string* path);
void RefreshDevice(udev_device* dev); void RefreshDevice(udev_device* dev);
void EnumerateDevices(); void EnumerateDevices();
void ReadDeviceData(size_t index); void ReadDeviceData(size_t index);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment