summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-01 10:08:16 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-01 10:08:16 +0000
commit2a92b328ee90599295bac5249b5a47e5a37607ff (patch)
treef499c6f44a5a755ec1e95329cdc9ba8cbeeab2a0 /content
parent45e29542b27c0d03a418acbf25359e4cf797f8b9 (diff)
downloadchromium_src-2a92b328ee90599295bac5249b5a47e5a37607ff.zip
chromium_src-2a92b328ee90599295bac5249b5a47e5a37607ff.tar.gz
chromium_src-2a92b328ee90599295bac5249b5a47e5a37607ff.tar.bz2
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
Diffstat (limited to 'content')
-rw-r--r--content/browser/gamepad/gamepad_provider.cc1
-rw-r--r--content/browser/gamepad/gamepad_provider.h16
-rw-r--r--content/browser/gamepad/gamepad_provider_unittest.cc14
-rw-r--r--content/browser/gamepad/platform_data_fetcher_linux.cc56
-rw-r--r--content/browser/gamepad/platform_data_fetcher_linux.h1
5 files changed, 46 insertions, 42 deletions
diff --git a/content/browser/gamepad/gamepad_provider.cc b/content/browser/gamepad/gamepad_provider.cc
index 3c533c3..0106079 100644
--- a/content/browser/gamepad/gamepad_provider.cc
+++ b/content/browser/gamepad/gamepad_provider.cc
@@ -14,6 +14,7 @@
#include "content/browser/gamepad/data_fetcher.h"
#include "content/browser/gamepad/gamepad_provider.h"
#include "content/browser/gamepad/platform_data_fetcher.h"
+#include "content/common/gamepad_hardware_buffer.h"
#include "content/common/gamepad_messages.h"
#include "content/public/browser/browser_thread.h"
diff --git a/content/browser/gamepad/gamepad_provider.h b/content/browser/gamepad/gamepad_provider.h
index b1bdb74..fba11f5 100644
--- a/content/browser/gamepad/gamepad_provider.h
+++ b/content/browser/gamepad/gamepad_provider.h
@@ -11,21 +11,20 @@
#include "base/shared_memory.h"
#include "base/synchronization/lock.h"
#include "base/system_monitor/system_monitor.h"
-#include "content/browser/gamepad/data_fetcher.h"
#include "content/common/content_export.h"
-#include "content/common/gamepad_hardware_buffer.h"
namespace base {
class Thread;
}
-struct GamepadMsg_Updated_Params;
-
namespace content {
+class GamepadDataFetcher;
+struct GamepadHardwareBuffer;
+
class CONTENT_EXPORT GamepadProvider :
- public base::RefCountedThreadSafe<GamepadProvider>,
- public base::SystemMonitor::DevicesChangedObserver {
+ public base::RefCountedThreadSafe<GamepadProvider>,
+ public base::SystemMonitor::DevicesChangedObserver {
public:
explicit GamepadProvider(GamepadDataFetcher* fetcher);
@@ -37,6 +36,9 @@ class CONTENT_EXPORT GamepadProvider :
void Pause();
void Resume();
+ // base::SystemMonitor::DevicesChangedObserver implementation.
+ virtual void OnDevicesChanged() OVERRIDE;
+
private:
friend class base::RefCountedThreadSafe<GamepadProvider>;
@@ -49,8 +51,6 @@ class CONTENT_EXPORT GamepadProvider :
void DoPoll();
void ScheduleDoPoll();
- virtual void OnDevicesChanged() OVERRIDE;
-
GamepadHardwareBuffer* SharedMemoryAsHardwareBuffer();
enum { kDesiredSamplingIntervalMs = 16 };
diff --git a/content/browser/gamepad/gamepad_provider_unittest.cc b/content/browser/gamepad/gamepad_provider_unittest.cc
index 51b1130..269c9d0 100644
--- a/content/browser/gamepad/gamepad_provider_unittest.cc
+++ b/content/browser/gamepad/gamepad_provider_unittest.cc
@@ -1,4 +1,4 @@
-// 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
// found in the LICENSE file.
@@ -6,9 +6,12 @@
#include "base/process_util.h"
#include "base/synchronization/waitable_event.h"
#include "base/system_monitor/system_monitor.h"
+#include "content/browser/gamepad/data_fetcher.h"
#include "content/browser/gamepad/gamepad_provider.h"
+#include "content/common/gamepad_hardware_buffer.h"
#include "content/common/gamepad_messages.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.h"
namespace content {
@@ -18,8 +21,9 @@ using WebKit::WebGamepads;
class MockDataFetcher : public GamepadDataFetcher {
public:
- MockDataFetcher(WebGamepads& test_data) : read_data_(false, false) {
- test_data_ = test_data;
+ explicit MockDataFetcher(const WebGamepads& test_data)
+ : test_data_(test_data),
+ read_data_(false, false) {
}
virtual void GetGamepadData(WebGamepads* pads,
bool devices_changed_hint) OVERRIDE {
@@ -36,7 +40,7 @@ class MockDataFetcher : public GamepadDataFetcher {
// Main test fixture
class GamepadProviderTest : public testing::Test {
public:
- GamepadProvider* CreateProvider(WebGamepads& test_data) {
+ GamepadProvider* CreateProvider(const WebGamepads& test_data) {
#if defined(OS_MACOSX)
base::SystemMonitor::AllocateSystemIOPorts();
#endif
@@ -102,4 +106,4 @@ TEST_F(GamepadProviderTest, DISABLED_PollingAccess) {
} // namespace
-} // namespace content
+} // namespace content
diff --git a/content/browser/gamepad/platform_data_fetcher_linux.cc b/content/browser/gamepad/platform_data_fetcher_linux.cc
index 1269c03..649f211 100644
--- a/content/browser/gamepad/platform_data_fetcher_linux.cc
+++ b/content/browser/gamepad/platform_data_fetcher_linux.cc
@@ -30,6 +30,33 @@ void CloseFileDescriptorIfValid(int 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 content {
@@ -108,33 +135,6 @@ void GamepadPlatformDataFetcherLinux::OnFileCanReadWithoutBlocking(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.
void GamepadPlatformDataFetcherLinux::RefreshDevice(udev_device* dev) {
int index;
@@ -228,7 +228,7 @@ void GamepadPlatformDataFetcherLinux::ReadDeviceData(size_t index) {
return;
}
- int& fd = device_fds_[index];
+ const int& fd = device_fds_[index];
WebGamepad& pad = data_.items[index];
DCHECK_GE(fd, 0);
diff --git a/content/browser/gamepad/platform_data_fetcher_linux.h b/content/browser/gamepad/platform_data_fetcher_linux.h
index 7339eee..b48592c 100644
--- a/content/browser/gamepad/platform_data_fetcher_linux.h
+++ b/content/browser/gamepad/platform_data_fetcher_linux.h
@@ -39,7 +39,6 @@ class GamepadPlatformDataFetcherLinux :
virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
private:
- bool IsGamepad(udev_device* dev, int* index, std::string* path);
void RefreshDevice(udev_device* dev);
void EnumerateDevices();
void ReadDeviceData(size_t index);