summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/browser/device_orientation/device_motion_message_filter.cc (renamed from content/browser/renderer_host/device_motion_browser_message_filter.cc)18
-rw-r--r--content/browser/device_orientation/device_motion_message_filter.h38
-rw-r--r--content/browser/device_orientation/device_orientation_message_filter.cc70
-rw-r--r--content/browser/device_orientation/device_orientation_message_filter.h37
-rw-r--r--content/browser/device_orientation/message_filter.cc8
-rw-r--r--content/browser/device_orientation/message_filter.h6
-rw-r--r--content/browser/device_orientation/orientation.cc2
-rw-r--r--content/browser/device_orientation/orientation_message_filter.cc4
-rw-r--r--content/browser/device_orientation/orientation_message_filter.h2
-rw-r--r--content/browser/renderer_host/device_motion_browser_message_filter.h39
-rw-r--r--content/browser/renderer_host/render_process_host_impl.cc6
-rw-r--r--content/common/DEPS1
-rw-r--r--content/common/content_message_generator.h4
-rw-r--r--content/common/device_motion_hardware_buffer.h1
-rw-r--r--content/common/device_orientation/OWNERS1
-rw-r--r--content/common/device_orientation/device_motion_messages.h (renamed from content/common/device_motion_messages.h)2
-rw-r--r--content/common/device_orientation/device_orientation_hardware_buffer.h18
-rw-r--r--content/common/device_orientation/device_orientation_messages.h (renamed from content/common/device_orientation_messages.h)18
-rw-r--r--content/content_browser.gypi6
-rw-r--r--content/content_common.gypi6
-rw-r--r--content/content_renderer.gypi4
-rw-r--r--content/content_tests.gypi1
-rw-r--r--content/renderer/device_orientation/device_motion_event_pump.cc99
-rw-r--r--content/renderer/device_orientation/device_motion_event_pump.h43
-rw-r--r--content/renderer/device_orientation/device_motion_event_pump_unittest.cc41
-rw-r--r--content/renderer/device_orientation/device_orientation_event_pump.cc88
-rw-r--r--content/renderer/device_orientation/device_orientation_event_pump.h54
-rw-r--r--content/renderer/device_orientation/device_orientation_event_pump_unittest.cc178
-rw-r--r--content/renderer/device_orientation/device_sensor_event_pump.cc84
-rw-r--r--content/renderer/device_orientation/device_sensor_event_pump.h60
-rw-r--r--content/renderer/device_orientation_dispatcher.cc2
-rw-r--r--content/renderer/renderer_webkitplatformsupport_impl.cc13
-rw-r--r--content/renderer/renderer_webkitplatformsupport_impl.h4
33 files changed, 746 insertions, 212 deletions
diff --git a/content/browser/renderer_host/device_motion_browser_message_filter.cc b/content/browser/device_orientation/device_motion_message_filter.cc
index 96eceba..3c619c6 100644
--- a/content/browser/renderer_host/device_motion_browser_message_filter.cc
+++ b/content/browser/device_orientation/device_motion_message_filter.cc
@@ -2,28 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/browser/renderer_host/device_motion_browser_message_filter.h"
+#include "content/browser/device_orientation/device_motion_message_filter.h"
#include "content/browser/device_orientation/device_motion_service.h"
-#include "content/common/device_motion_messages.h"
+#include "content/common/device_orientation/device_motion_messages.h"
namespace content {
-DeviceMotionBrowserMessageFilter::DeviceMotionBrowserMessageFilter()
+DeviceMotionMessageFilter::DeviceMotionMessageFilter()
: is_started_(false) {
}
-DeviceMotionBrowserMessageFilter::~DeviceMotionBrowserMessageFilter() {
+DeviceMotionMessageFilter::~DeviceMotionMessageFilter() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (is_started_)
DeviceMotionService::GetInstance()->RemoveConsumer();
}
-bool DeviceMotionBrowserMessageFilter::OnMessageReceived(
+bool DeviceMotionMessageFilter::OnMessageReceived(
const IPC::Message& message,
bool* message_was_ok) {
bool handled = true;
- IPC_BEGIN_MESSAGE_MAP_EX(DeviceMotionBrowserMessageFilter,
+ IPC_BEGIN_MESSAGE_MAP_EX(DeviceMotionMessageFilter,
message,
*message_was_ok)
IPC_MESSAGE_HANDLER(DeviceMotionHostMsg_StartPolling,
@@ -35,7 +35,7 @@ bool DeviceMotionBrowserMessageFilter::OnMessageReceived(
return handled;
}
-void DeviceMotionBrowserMessageFilter::OnDeviceMotionStartPolling() {
+void DeviceMotionMessageFilter::OnDeviceMotionStartPolling() {
DCHECK(!is_started_);
if (is_started_)
return;
@@ -44,7 +44,7 @@ void DeviceMotionBrowserMessageFilter::OnDeviceMotionStartPolling() {
DidStartDeviceMotionPolling();
}
-void DeviceMotionBrowserMessageFilter::OnDeviceMotionStopPolling() {
+void DeviceMotionMessageFilter::OnDeviceMotionStopPolling() {
DCHECK(is_started_);
if (!is_started_)
return;
@@ -52,7 +52,7 @@ void DeviceMotionBrowserMessageFilter::OnDeviceMotionStopPolling() {
DeviceMotionService::GetInstance()->RemoveConsumer();
}
-void DeviceMotionBrowserMessageFilter::DidStartDeviceMotionPolling() {
+void DeviceMotionMessageFilter::DidStartDeviceMotionPolling() {
Send(new DeviceMotionMsg_DidStartPolling(
DeviceMotionService::GetInstance()->GetSharedMemoryHandleForProcess(
PeerHandle())));
diff --git a/content/browser/device_orientation/device_motion_message_filter.h b/content/browser/device_orientation/device_motion_message_filter.h
new file mode 100644
index 0000000..3d078e3
--- /dev/null
+++ b/content/browser/device_orientation/device_motion_message_filter.h
@@ -0,0 +1,38 @@
+// Copyright 2013 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_RENDERER_HOST_DEVICE_MOTION_MESSAGE_FILTER_H_
+#define CONTENT_BROWSER_RENDERER_HOST_DEVICE_MOTION_MESSAGE_FILTER_H_
+
+#include "base/compiler_specific.h"
+#include "content/public/browser/browser_message_filter.h"
+
+namespace content {
+
+class DeviceMotionService;
+class RenderProcessHost;
+
+class DeviceMotionMessageFilter : public BrowserMessageFilter {
+ public:
+ DeviceMotionMessageFilter();
+
+ // BrowserMessageFilter implementation.
+ virtual bool OnMessageReceived(const IPC::Message& message,
+ bool* message_was_ok) OVERRIDE;
+
+ private:
+ virtual ~DeviceMotionMessageFilter();
+
+ void OnDeviceMotionStartPolling();
+ void OnDeviceMotionStopPolling();
+ void DidStartDeviceMotionPolling();
+
+ bool is_started_;
+
+ DISALLOW_COPY_AND_ASSIGN(DeviceMotionMessageFilter);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_RENDERER_HOST_DEVICE_MOTION_MESSAGE_FILTER_H_
diff --git a/content/browser/device_orientation/device_orientation_message_filter.cc b/content/browser/device_orientation/device_orientation_message_filter.cc
new file mode 100644
index 0000000..cbb1e67
--- /dev/null
+++ b/content/browser/device_orientation/device_orientation_message_filter.cc
@@ -0,0 +1,70 @@
+// Copyright 2013 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.
+
+#include "content/browser/device_orientation/device_orientation_message_filter.h"
+
+#include "content/browser/device_orientation/device_motion_service.h"
+#include "content/common/device_orientation/device_orientation_messages.h"
+
+namespace content {
+
+DeviceOrientationMessageFilter::DeviceOrientationMessageFilter()
+ : is_started_(false) {
+}
+
+DeviceOrientationMessageFilter::~DeviceOrientationMessageFilter() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ if (is_started_) {
+ // TODO(timvolodine): insert a proper call to DeviceSensorService here,
+ // similar to DeviceMotionService::GetInstance()->RemoveConsumer();
+ }
+}
+
+bool DeviceOrientationMessageFilter::OnMessageReceived(
+ const IPC::Message& message,
+ bool* message_was_ok) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(DeviceOrientationMessageFilter,
+ message,
+ *message_was_ok)
+ IPC_MESSAGE_HANDLER(DeviceOrientationHostMsg_StartPolling,
+ OnDeviceOrientationStartPolling)
+ IPC_MESSAGE_HANDLER(DeviceOrientationHostMsg_StopPolling,
+ OnDeviceOrientationStopPolling)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP_EX()
+ return handled;
+}
+
+void DeviceOrientationMessageFilter::OnDeviceOrientationStartPolling() {
+ NOTIMPLEMENTED();
+ DCHECK(!is_started_);
+ if (is_started_)
+ return;
+ is_started_ = true;
+ // TODO(timvolodine): insert a proper call to DeviceSensorService here,
+ // similar to DeviceMotionService::GetInstance()->AddConsumer();
+ DidStartDeviceOrientationPolling();
+}
+
+void DeviceOrientationMessageFilter::OnDeviceOrientationStopPolling() {
+ NOTIMPLEMENTED();
+ DCHECK(is_started_);
+ if (!is_started_)
+ return;
+ is_started_ = false;
+ // TODO(timvolodine): insert a proper call to DeviceSensorService here,
+ // similar to DeviceMotionService::GetInstance()->RemoveConsumer();
+}
+
+void DeviceOrientationMessageFilter::DidStartDeviceOrientationPolling() {
+ NOTIMPLEMENTED();
+ // TODO(timvolodine): insert a proper call to the generalized Service here,
+ // similar to
+ // Send(new DeviceOrientationMsg_DidStartPolling(
+ // DeviceMotionService::GetInstance()->GetSharedMemoryHandleForProcess(
+ // PeerHandle())));
+}
+
+} // namespace content
diff --git a/content/browser/device_orientation/device_orientation_message_filter.h b/content/browser/device_orientation/device_orientation_message_filter.h
new file mode 100644
index 0000000..b8ccb84
--- /dev/null
+++ b/content/browser/device_orientation/device_orientation_message_filter.h
@@ -0,0 +1,37 @@
+// Copyright 2013 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_DEVICE_ORIENTATION_DEVICE_ORIENTATION_MESSAGE_FILTER_H_
+#define CONTENT_BROWSER_DEVICE_ORIENTATION_DEVICE_ORIENTATION_MESSAGE_FILTER_H_
+
+#include "base/compiler_specific.h"
+#include "content/public/browser/browser_message_filter.h"
+
+namespace content {
+
+class RenderProcessHost;
+
+class DeviceOrientationMessageFilter : public BrowserMessageFilter {
+ public:
+ DeviceOrientationMessageFilter();
+
+ // BrowserMessageFilter implementation.
+ virtual bool OnMessageReceived(const IPC::Message& message,
+ bool* message_was_ok) OVERRIDE;
+
+ private:
+ virtual ~DeviceOrientationMessageFilter();
+
+ void OnDeviceOrientationStartPolling();
+ void OnDeviceOrientationStopPolling();
+ void DidStartDeviceOrientationPolling();
+
+ bool is_started_;
+
+ DISALLOW_COPY_AND_ASSIGN(DeviceOrientationMessageFilter);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_DEVICE_ORIENTATION_DEVICE_ORIENTATION_MESSAGE_FILTER_H_
diff --git a/content/browser/device_orientation/message_filter.cc b/content/browser/device_orientation/message_filter.cc
index 2843f7d..b20071d 100644
--- a/content/browser/device_orientation/message_filter.cc
+++ b/content/browser/device_orientation/message_filter.cc
@@ -10,16 +10,16 @@
namespace content {
-DeviceOrientationMessageFilter::DeviceOrientationMessageFilter(
+DeviceOrientationMessageFilterOld::DeviceOrientationMessageFilterOld(
DeviceData::Type device_data_type)
: provider_(NULL),
device_data_type_(device_data_type) {
}
-DeviceOrientationMessageFilter::~DeviceOrientationMessageFilter() {
+DeviceOrientationMessageFilterOld::~DeviceOrientationMessageFilterOld() {
}
-void DeviceOrientationMessageFilter::OnStartUpdating(int render_view_id) {
+void DeviceOrientationMessageFilterOld::OnStartUpdating(int render_view_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (!provider_.get())
@@ -29,7 +29,7 @@ void DeviceOrientationMessageFilter::OnStartUpdating(int render_view_id) {
device_data_type_, provider_.get(), render_view_id, this);
}
-void DeviceOrientationMessageFilter::OnStopUpdating(int render_view_id) {
+void DeviceOrientationMessageFilterOld::OnStopUpdating(int render_view_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
observers_map_.erase(render_view_id);
diff --git a/content/browser/device_orientation/message_filter.h b/content/browser/device_orientation/message_filter.h
index f0135f4..c5dce14 100644
--- a/content/browser/device_orientation/message_filter.h
+++ b/content/browser/device_orientation/message_filter.h
@@ -17,15 +17,15 @@ class ObserverDelegate;
class Provider;
-class DeviceOrientationMessageFilter : public BrowserMessageFilter {
+class DeviceOrientationMessageFilterOld : public BrowserMessageFilter {
public:
// BrowserMessageFilter implementation.
virtual bool OnMessageReceived(const IPC::Message& message,
bool* message_was_ok) OVERRIDE = 0;
protected:
- DeviceOrientationMessageFilter(DeviceData::Type device_data_type);
- virtual ~DeviceOrientationMessageFilter();
+ DeviceOrientationMessageFilterOld(DeviceData::Type device_data_type);
+ virtual ~DeviceOrientationMessageFilterOld();
void OnStartUpdating(int render_view_id);
void OnStopUpdating(int render_view_id);
diff --git a/content/browser/device_orientation/orientation.cc b/content/browser/device_orientation/orientation.cc
index c0dcfd0..b0b463f 100644
--- a/content/browser/device_orientation/orientation.cc
+++ b/content/browser/device_orientation/orientation.cc
@@ -6,7 +6,7 @@
#include <cmath>
-#include "content/common/device_orientation_messages.h"
+#include "content/common/device_orientation/device_orientation_messages.h"
namespace content {
diff --git a/content/browser/device_orientation/orientation_message_filter.cc b/content/browser/device_orientation/orientation_message_filter.cc
index f04a5a8..b7cde57 100644
--- a/content/browser/device_orientation/orientation_message_filter.cc
+++ b/content/browser/device_orientation/orientation_message_filter.cc
@@ -5,13 +5,13 @@
#include "content/browser/device_orientation/orientation_message_filter.h"
#include "content/browser/device_orientation/device_data.h"
-#include "content/common/device_orientation_messages.h"
+#include "content/common/device_orientation/device_orientation_messages.h"
#include "content/public/browser/browser_thread.h"
namespace content {
OrientationMessageFilter::OrientationMessageFilter()
- : DeviceOrientationMessageFilter(DeviceData::kTypeOrientation) {
+ : DeviceOrientationMessageFilterOld(DeviceData::kTypeOrientation) {
}
OrientationMessageFilter::~OrientationMessageFilter() {
diff --git a/content/browser/device_orientation/orientation_message_filter.h b/content/browser/device_orientation/orientation_message_filter.h
index 7925f0b..80181d5 100644
--- a/content/browser/device_orientation/orientation_message_filter.h
+++ b/content/browser/device_orientation/orientation_message_filter.h
@@ -11,7 +11,7 @@
namespace content {
-class OrientationMessageFilter : public DeviceOrientationMessageFilter {
+class OrientationMessageFilter : public DeviceOrientationMessageFilterOld {
public:
OrientationMessageFilter();
diff --git a/content/browser/renderer_host/device_motion_browser_message_filter.h b/content/browser/renderer_host/device_motion_browser_message_filter.h
deleted file mode 100644
index ab10226..0000000
--- a/content/browser/renderer_host/device_motion_browser_message_filter.h
+++ /dev/null
@@ -1,39 +0,0 @@
- // Copyright 2013 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_RENDERER_HOST_DEVICE_MOTION_BROWSER_MESSAGE_FILTER_H_
- #define CONTENT_BROWSER_RENDERER_HOST_DEVICE_MOTION_BROWSER_MESSAGE_FILTER_H_
-
- #include "base/compiler_specific.h"
- #include "base/memory/shared_memory.h"
- #include "content/public/browser/browser_message_filter.h"
-
- namespace content {
-
- class DeviceMotionService;
- class RenderProcessHost;
-
- class DeviceMotionBrowserMessageFilter : public BrowserMessageFilter {
- public:
- DeviceMotionBrowserMessageFilter();
-
- // BrowserMessageFilter implementation.
- virtual bool OnMessageReceived(const IPC::Message& message,
- bool* message_was_ok) OVERRIDE;
-
- private:
- virtual ~DeviceMotionBrowserMessageFilter();
-
- void OnDeviceMotionStartPolling();
- void OnDeviceMotionStopPolling();
- void DidStartDeviceMotionPolling();
-
- bool is_started_;
-
- DISALLOW_COPY_AND_ASSIGN(DeviceMotionBrowserMessageFilter);
- };
-
- } // namespace content
-
- #endif // CONTENT_BROWSER_RENDERER_HOST_DEVICE_MOTION_BROWSER_MESSAGE_FILTER_H_
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index 22b27e9..9a5eec5 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -43,6 +43,8 @@
#include "content/browser/browser_plugin/browser_plugin_geolocation_permission_context.h"
#include "content/browser/browser_plugin/browser_plugin_message_filter.h"
#include "content/browser/child_process_security_policy_impl.h"
+#include "content/browser/device_orientation/device_motion_message_filter.h"
+#include "content/browser/device_orientation/device_orientation_message_filter.h"
#include "content/browser/device_orientation/orientation_message_filter.h"
#include "content/browser/dom_storage/dom_storage_context_impl.h"
#include "content/browser/dom_storage/dom_storage_message_filter.h"
@@ -65,7 +67,6 @@
#include "content/browser/quota_dispatcher_host.h"
#include "content/browser/renderer_host/clipboard_message_filter.h"
#include "content/browser/renderer_host/database_message_filter.h"
-#include "content/browser/renderer_host/device_motion_browser_message_filter.h"
#include "content/browser/renderer_host/file_utilities_message_filter.h"
#include "content/browser/renderer_host/gamepad_browser_message_filter.h"
#include "content/browser/renderer_host/gpu_message_filter.h"
@@ -718,7 +719,8 @@ void RenderProcessHostImpl::CreateMessageFilters() {
storage_partition_impl_->GetQuotaManager(),
GetContentClient()->browser()->CreateQuotaPermissionContext()));
channel_->AddFilter(new GamepadBrowserMessageFilter());
- channel_->AddFilter(new DeviceMotionBrowserMessageFilter());
+ channel_->AddFilter(new DeviceMotionMessageFilter());
+ channel_->AddFilter(new DeviceOrientationMessageFilter());
channel_->AddFilter(new ProfilerMessageFilter(PROCESS_TYPE_RENDERER));
channel_->AddFilter(new HistogramMessageFilter());
#if defined(USE_TCMALLOC) && (defined(OS_LINUX) || defined(OS_ANDROID))
diff --git a/content/common/DEPS b/content/common/DEPS
index cdd8ade..6efe1f9 100644
--- a/content/common/DEPS
+++ b/content/common/DEPS
@@ -14,6 +14,7 @@ include_rules = [
"-third_party/WebKit",
"+third_party/WebKit/public/platform/WebCString.h",
"+third_party/WebKit/public/platform/WebDeviceMotionData.h",
+ "+third_party/WebKit/public/platform/WebDeviceOrientationData.h",
"+third_party/WebKit/public/platform/WebFloatPoint.h",
"+third_party/WebKit/public/platform/WebFloatRect.h",
"+third_party/WebKit/public/platform/WebGamepads.h",
diff --git a/content/common/content_message_generator.h b/content/common/content_message_generator.h
index ba81705..1c3b85b 100644
--- a/content/common/content_message_generator.h
+++ b/content/common/content_message_generator.h
@@ -13,8 +13,8 @@
#include "content/common/clipboard_messages.h"
#include "content/common/database_messages.h"
#include "content/common/desktop_notification_messages.h"
-#include "content/common/device_motion_messages.h"
-#include "content/common/device_orientation_messages.h"
+#include "content/common/device_orientation/device_motion_messages.h"
+#include "content/common/device_orientation/device_orientation_messages.h"
#include "content/common/devtools_messages.h"
#include "content/common/dom_storage_messages.h"
#include "content/common/drag_messages.h"
diff --git a/content/common/device_motion_hardware_buffer.h b/content/common/device_motion_hardware_buffer.h
index 7e85efe..0ff855a 100644
--- a/content/common/device_motion_hardware_buffer.h
+++ b/content/common/device_motion_hardware_buffer.h
@@ -8,6 +8,7 @@
#include "content/common/shared_memory_seqlock_buffer.h"
#include "third_party/WebKit/public/platform/WebDeviceMotionData.h"
+// TODO(timvolodine): move this file to content/common/device_orientation/.
namespace content {
typedef SharedMemorySeqLockBuffer<WebKit::WebDeviceMotionData>
diff --git a/content/common/device_orientation/OWNERS b/content/common/device_orientation/OWNERS
new file mode 100644
index 0000000..0a33f44
--- /dev/null
+++ b/content/common/device_orientation/OWNERS
@@ -0,0 +1 @@
+per-file *_hardware_buffer*.h=timvolodine@chromium.org
diff --git a/content/common/device_motion_messages.h b/content/common/device_orientation/device_motion_messages.h
index 1469c26..1441c81 100644
--- a/content/common/device_motion_messages.h
+++ b/content/common/device_orientation/device_motion_messages.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2013 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.
diff --git a/content/common/device_orientation/device_orientation_hardware_buffer.h b/content/common/device_orientation/device_orientation_hardware_buffer.h
new file mode 100644
index 0000000..c1dc831
--- /dev/null
+++ b/content/common/device_orientation/device_orientation_hardware_buffer.h
@@ -0,0 +1,18 @@
+// Copyright 2013 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_COMMON_DEVICE_ORIENTATION_DEVICE_ORIENTATION_HARDWARE_BUFFER_H_
+#define CONTENT_COMMON_DEVICE_ORIENTATION_DEVICE_ORIENTATION_HARDWARE_BUFFER_H_
+
+#include "content/common/shared_memory_seqlock_buffer.h"
+#include "third_party/WebKit/public/platform/WebDeviceOrientationData.h"
+
+namespace content {
+
+typedef SharedMemorySeqLockBuffer<WebKit::WebDeviceOrientationData>
+ DeviceOrientationHardwareBuffer;
+
+} // namespace content
+
+#endif // CONTENT_COMMON_DEVICE_ORIENTATION_DEVICE_ORIENTATION_HARDWARE_BUFFER_H_
diff --git a/content/common/device_orientation_messages.h b/content/common/device_orientation/device_orientation_messages.h
index c726c97..f4114df 100644
--- a/content/common/device_orientation_messages.h
+++ b/content/common/device_orientation/device_orientation_messages.h
@@ -1,14 +1,30 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2013 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.
// IPC messages for device orientation.
// Multiply-included message file, hence no include guard.
+#include "base/memory/shared_memory.h"
#include "ipc/ipc_message_macros.h"
#define IPC_MESSAGE_START DeviceOrientationMsgStart
+// Messages sent from the renderer to the browser.
+
+// Asks the browser process to start polling, and return a shared memory
+// handle that will hold the data from the hardware. See
+// device_orientation_hardware_buffer.h for a description of how synchronization
+// is handled. The number of Starts should match the number of Stops.
+IPC_MESSAGE_CONTROL0(DeviceOrientationHostMsg_StartPolling)
+IPC_MESSAGE_CONTROL1(DeviceOrientationMsg_DidStartPolling,
+ base::SharedMemoryHandle /* handle */)
+
+IPC_MESSAGE_CONTROL0(DeviceOrientationHostMsg_StopPolling)
+
+// TODO(timvolodine): remove the methods below once the shared memory
+// Device Orientation is implemented.
+
IPC_STRUCT_BEGIN(DeviceOrientationMsg_Updated_Params)
// These fields have the same meaning as in content::Orientation.
IPC_STRUCT_MEMBER(bool, can_provide_alpha)
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index e4d7b5e..1124248 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -400,10 +400,14 @@
'browser/device_orientation/data_fetcher_shared_memory_default.cc',
'browser/device_orientation/data_fetcher_shared_memory.h',
'browser/device_orientation/device_data.h',
+ 'browser/device_orientation/device_motion_message_filter.cc',
+ 'browser/device_orientation/device_motion_message_filter.h',
'browser/device_orientation/device_motion_provider.cc',
'browser/device_orientation/device_motion_provider.h',
'browser/device_orientation/device_motion_service.cc',
'browser/device_orientation/device_motion_service.h',
+ 'browser/device_orientation/device_orientation_message_filter.cc',
+ 'browser/device_orientation/device_orientation_message_filter.h',
'browser/device_orientation/message_filter.cc',
'browser/device_orientation/message_filter.h',
'browser/device_orientation/observer_delegate.cc',
@@ -761,8 +765,6 @@
'browser/renderer_host/compositor_impl_android.h',
'browser/renderer_host/database_message_filter.cc',
'browser/renderer_host/database_message_filter.h',
- 'browser/renderer_host/device_motion_browser_message_filter.cc',
- 'browser/renderer_host/device_motion_browser_message_filter.h',
'browser/renderer_host/dip_util.cc',
'browser/renderer_host/dip_util.h',
'browser/renderer_host/file_utilities_message_filter.cc',
diff --git a/content/content_common.gypi b/content/content_common.gypi
index cf12fda..f75f1ab 100644
--- a/content/content_common.gypi
+++ b/content/content_common.gypi
@@ -152,8 +152,10 @@
'common/cookie_data.h',
'common/database_messages.h',
'common/desktop_notification_messages.h',
- 'common/device_motion_messages.h',
- 'common/device_orientation_messages.h',
+ 'common/device_motion_hardware_buffer.h',
+ 'common/device_orientation/device_motion_messages.h',
+ 'common/device_orientation/device_orientation_hardware_buffer.h',
+ 'common/device_orientation/device_orientation_messages.h',
'common/devtools_messages.h',
'common/dom_storage_messages.h',
'common/drag_event_source_info.h',
diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi
index 249cab9..a0b130c 100644
--- a/content/content_renderer.gypi
+++ b/content/content_renderer.gypi
@@ -87,6 +87,10 @@
'renderer/device_orientation_dispatcher.h',
'renderer/device_orientation/device_motion_event_pump.cc',
'renderer/device_orientation/device_motion_event_pump.h',
+ 'renderer/device_orientation/device_orientation_event_pump.cc',
+ 'renderer/device_orientation/device_orientation_event_pump.h',
+ 'renderer/device_orientation/device_sensor_event_pump.cc',
+ 'renderer/device_orientation/device_sensor_event_pump.h',
'renderer/devtools/devtools_agent.cc',
'renderer/devtools/devtools_agent.h',
'renderer/devtools/devtools_agent_filter.cc',
diff --git a/content/content_tests.gypi b/content/content_tests.gypi
index 98127c5..0d1a7eb 100644
--- a/content/content_tests.gypi
+++ b/content/content_tests.gypi
@@ -416,6 +416,7 @@
'renderer/bmp_image_decoder_unittest.cc',
'renderer/date_time_formatter_unittest.cc',
'renderer/device_orientation/device_motion_event_pump_unittest.cc',
+ 'renderer/device_orientation/device_orientation_event_pump_unittest.cc',
'renderer/disambiguation_popup_helper_unittest.cc',
'renderer/dom_storage/dom_storage_cached_area_unittest.cc',
'renderer/gpu/input_event_filter_unittest.cc',
diff --git a/content/renderer/device_orientation/device_motion_event_pump.cc b/content/renderer/device_orientation/device_motion_event_pump.cc
index 0cfd774..e7ad8ca 100644
--- a/content/renderer/device_orientation/device_motion_event_pump.cc
+++ b/content/renderer/device_orientation/device_motion_event_pump.cc
@@ -4,25 +4,18 @@
#include "device_motion_event_pump.h"
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/shared_memory.h"
-#include "base/message_loop/message_loop.h"
-#include "content/common/device_motion_messages.h"
+#include "content/common/device_orientation/device_motion_messages.h"
#include "content/public/renderer/render_thread.h"
#include "third_party/WebKit/public/platform/WebDeviceMotionListener.h"
namespace content {
-const double DeviceMotionEventPump::kPumpDelayMillis = 40;
-
-double DeviceMotionEventPump::GetDelayMillis() {
- return kPumpDelayMillis;
+DeviceMotionEventPump::DeviceMotionEventPump()
+ : DeviceSensorEventPump(), listener_(0) {
}
-DeviceMotionEventPump::DeviceMotionEventPump()
- : listener_(0), state_(STOPPED) {
+DeviceMotionEventPump::DeviceMotionEventPump(int pump_delay_millis)
+ : DeviceSensorEventPump(pump_delay_millis), listener_(0) {
}
DeviceMotionEventPump::~DeviceMotionEventPump() {
@@ -31,45 +24,17 @@ DeviceMotionEventPump::~DeviceMotionEventPump() {
bool DeviceMotionEventPump::SetListener(
WebKit::WebDeviceMotionListener* listener) {
listener_ = listener;
- if (listener_)
- return StartFetchingDeviceMotion();
- return StopFetchingDeviceMotion();
-}
-
-void DeviceMotionEventPump::SetDeviceMotionReader(
- scoped_ptr<DeviceMotionSharedMemoryReader> reader) {
- reader_.reset(reader.release());
+ return listener_ ? RequestStart() : Stop();
}
-bool DeviceMotionEventPump::StartFetchingDeviceMotion() {
- DVLOG(2) << "start fetching device motion";
-
- if (state_ != STOPPED)
- return false;
-
- DCHECK(!timer_.IsRunning());
-
- if (RenderThread::Get()->Send(new DeviceMotionHostMsg_StartPolling())) {
- state_ = PENDING_START;
- return true;
- }
- return false;
-}
-
-bool DeviceMotionEventPump::StopFetchingDeviceMotion() {
- DVLOG(2) << "stop fetching device motion";
-
- if (state_ == STOPPED)
- return true;
-
- DCHECK((state_ == PENDING_START && !timer_.IsRunning()) ||
- (state_ == RUNNING && timer_.IsRunning()));
-
- if (timer_.IsRunning())
- timer_.Stop();
- RenderThread::Get()->Send(new DeviceMotionHostMsg_StopPolling());
- state_ = STOPPED;
- return true;
+bool DeviceMotionEventPump::OnControlMessageReceived(
+ const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(DeviceMotionEventPump, message)
+ IPC_MESSAGE_HANDLER(DeviceMotionMsg_DidStartPolling, OnDidStart)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
}
void DeviceMotionEventPump::FireEvent() {
@@ -79,39 +44,19 @@ void DeviceMotionEventPump::FireEvent() {
listener_->didChangeDeviceMotion(data);
}
-void DeviceMotionEventPump::Attach(RenderThread* thread) {
- if (!thread)
- return;
- thread->AddObserver(this);
-}
-
-void DeviceMotionEventPump::OnDidStartDeviceMotion(
- base::SharedMemoryHandle renderer_handle) {
- DVLOG(2) << "did start fetching device motion";
-
- if (state_ != PENDING_START)
- return;
-
- DCHECK(!timer_.IsRunning());
+bool DeviceMotionEventPump::InitializeReader(base::SharedMemoryHandle handle) {
if (!reader_)
reader_.reset(new DeviceMotionSharedMemoryReader());
+ return reader_->Initialize(handle);
+}
- if (reader_->Initialize(renderer_handle)) {
- timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kPumpDelayMillis),
- this, &DeviceMotionEventPump::FireEvent);
- state_ = RUNNING;
- }
+bool DeviceMotionEventPump::SendStartMessage() {
+ return RenderThread::Get()->Send(new DeviceMotionHostMsg_StartPolling());
}
-bool DeviceMotionEventPump::OnControlMessageReceived(
- const IPC::Message& message) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(DeviceMotionEventPump, message)
- IPC_MESSAGE_HANDLER(DeviceMotionMsg_DidStartPolling,
- OnDidStartDeviceMotion)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
+
+bool DeviceMotionEventPump::SendStopMessage() {
+ return RenderThread::Get()->Send(new DeviceMotionHostMsg_StopPolling());
}
} // namespace content
diff --git a/content/renderer/device_orientation/device_motion_event_pump.h b/content/renderer/device_orientation/device_motion_event_pump.h
index f2c3474..4fa453d 100644
--- a/content/renderer/device_orientation/device_motion_event_pump.h
+++ b/content/renderer/device_orientation/device_motion_event_pump.h
@@ -6,9 +6,7 @@
#define CONTENT_RENDERER_DEVICE_MOTION_EVENT_PUMP_H_
#include "base/memory/scoped_ptr.h"
-#include "base/memory/shared_memory.h"
-#include "base/timer/timer.h"
-#include "content/public/renderer/render_process_observer.h"
+#include "content/renderer/device_orientation/device_sensor_event_pump.h"
#include "content/renderer/shared_memory_seqlock_reader.h"
#include "third_party/WebKit/public/platform/WebDeviceMotionData.h"
@@ -17,54 +15,31 @@ class WebDeviceMotionListener;
}
namespace content {
-class RenderThread;
typedef SharedMemorySeqLockReader<WebKit::WebDeviceMotionData>
DeviceMotionSharedMemoryReader;
-class CONTENT_EXPORT DeviceMotionEventPump : public RenderProcessObserver {
+class CONTENT_EXPORT DeviceMotionEventPump : public DeviceSensorEventPump {
public:
DeviceMotionEventPump();
+ explicit DeviceMotionEventPump(int pump_delay_millis);
virtual ~DeviceMotionEventPump();
- static double GetDelayMillis();
-
// Sets the listener to receive updates for device motion data at
- // regular intervals.
- // Returns true if the registration was successful.
- bool SetListener(WebKit::WebDeviceMotionListener*);
-
- void SetDeviceMotionReader(scoped_ptr<DeviceMotionSharedMemoryReader>);
-
- void Attach(RenderThread* thread);
+ // regular intervals. Returns true if the registration was successful.
+ bool SetListener(WebKit::WebDeviceMotionListener* listener);
// RenderProcessObserver implementation.
virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE;
protected:
- // Delay between subsequent firing of events.
- static const double kPumpDelayMillis;
-
- // The pump is a tri-state automaton with allowed transitions as follows:
- // STOPPED -> PENDING_START
- // PENDING_START -> RUNNING
- // PENDING_START -> STOPPED
- // RUNNING -> STOPPED
- enum PumpState {
- STOPPED,
- RUNNING,
- PENDING_START
- };
-
- bool StartFetchingDeviceMotion();
- bool StopFetchingDeviceMotion();
- void OnDidStartDeviceMotion(base::SharedMemoryHandle renderer_handle);
- void FireEvent();
+ virtual void FireEvent() OVERRIDE;
+ virtual bool InitializeReader(base::SharedMemoryHandle handle) OVERRIDE;
+ virtual bool SendStartMessage() OVERRIDE;
+ virtual bool SendStopMessage() OVERRIDE;
WebKit::WebDeviceMotionListener* listener_;
scoped_ptr<DeviceMotionSharedMemoryReader> reader_;
- base::RepeatingTimer<DeviceMotionEventPump> timer_;
- PumpState state_;
};
} // namespace content
diff --git a/content/renderer/device_orientation/device_motion_event_pump_unittest.cc b/content/renderer/device_orientation/device_motion_event_pump_unittest.cc
index 2b628d4..066294b 100644
--- a/content/renderer/device_orientation/device_motion_event_pump_unittest.cc
+++ b/content/renderer/device_orientation/device_motion_event_pump_unittest.cc
@@ -42,34 +42,13 @@ class DeviceMotionEventPumpForTesting : public DeviceMotionEventPump {
public:
DeviceMotionEventPumpForTesting() { }
virtual ~DeviceMotionEventPumpForTesting() { }
- void OnDidStartDeviceMotion(base::SharedMemoryHandle handle);
- bool SetListener(WebKit::WebDeviceMotionListener*);
- bool StartFetchingDeviceMotion();
- bool StopFetchingDeviceMotion();
-};
-
-bool DeviceMotionEventPumpForTesting::StartFetchingDeviceMotion() {
- state_ = PENDING_START;
- return true;
-}
-
-bool DeviceMotionEventPumpForTesting::StopFetchingDeviceMotion() {
- if (timer_.IsRunning())
- timer_.Stop();
- state_ = STOPPED;
- return true;
-}
-bool DeviceMotionEventPumpForTesting::SetListener(
- WebKit::WebDeviceMotionListener* listener) {
- listener_ = listener;
- return (listener_) ? StartFetchingDeviceMotion() : StopFetchingDeviceMotion();
-}
-
-void DeviceMotionEventPumpForTesting::OnDidStartDeviceMotion(
- base::SharedMemoryHandle handle) {
- DeviceMotionEventPump::OnDidStartDeviceMotion(handle);
-}
+ void OnDidStart(base::SharedMemoryHandle renderer_handle) {
+ DeviceMotionEventPump::OnDidStart(renderer_handle);
+ }
+ virtual bool SendStartMessage() OVERRIDE { return true; }
+ virtual bool SendStopMessage() OVERRIDE { return true; }
+};
// Always failing in the win try bot. See http://crbug.com/256782.
#if defined(OS_WIN)
@@ -102,9 +81,9 @@ TEST_F(DeviceMotionEventPumpTest, MAYBE_DidStartPolling) {
data.allAvailableSensorsAreActive = true;
motion_pump->SetListener(listener.get());
- motion_pump->OnDidStartDeviceMotion(handle);
+ motion_pump->OnDidStart(handle);
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(
- DeviceMotionEventPump::GetDelayMillis() * 2));
+ motion_pump->GetDelayMillis() * 2));
RunAllPendingInMessageLoop();
motion_pump->SetListener(0);
@@ -159,9 +138,9 @@ TEST_F(DeviceMotionEventPumpTest, MAYBE_DidStartPollingNotAllSensorsActive) {
data.allAvailableSensorsAreActive = false;
motion_pump->SetListener(listener.get());
- motion_pump->OnDidStartDeviceMotion(handle);
+ motion_pump->OnDidStart(handle);
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(
- DeviceMotionEventPump::GetDelayMillis() * 2));
+ motion_pump->GetDelayMillis() * 2));
RunAllPendingInMessageLoop();
motion_pump->SetListener(0);
diff --git a/content/renderer/device_orientation/device_orientation_event_pump.cc b/content/renderer/device_orientation/device_orientation_event_pump.cc
new file mode 100644
index 0000000..ca45537
--- /dev/null
+++ b/content/renderer/device_orientation/device_orientation_event_pump.cc
@@ -0,0 +1,88 @@
+// Copyright 2013 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.
+
+#include "device_orientation_event_pump.h"
+
+#include <cmath>
+
+#include "content/common/device_orientation/device_orientation_messages.h"
+#include "content/public/renderer/render_thread.h"
+#include "third_party/WebKit/public/platform/WebDeviceOrientationListener.h"
+
+namespace content {
+
+const double DeviceOrientationEventPump::kOrientationThreshold = 0.1;
+
+DeviceOrientationEventPump::DeviceOrientationEventPump()
+ : DeviceSensorEventPump(), listener_(0) {
+}
+
+DeviceOrientationEventPump::DeviceOrientationEventPump(int pump_delay_millis)
+ : DeviceSensorEventPump(pump_delay_millis), listener_(0) {
+}
+
+DeviceOrientationEventPump::~DeviceOrientationEventPump() {
+}
+
+bool DeviceOrientationEventPump::SetListener(
+ WebKit::WebDeviceOrientationListener* listener) {
+ listener_ = listener;
+ return listener_ ? RequestStart() : Stop();
+}
+
+bool DeviceOrientationEventPump::OnControlMessageReceived(
+ const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(DeviceOrientationEventPump, message)
+ IPC_MESSAGE_HANDLER(DeviceOrientationMsg_DidStartPolling, OnDidStart)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void DeviceOrientationEventPump::FireEvent() {
+ DCHECK(listener_);
+ WebKit::WebDeviceOrientationData data;
+ if (reader_->GetLatestData(&data) && ShouldFireEvent(data)) {
+ memcpy(&data_, &data, sizeof(data));
+ listener_->didChangeDeviceOrientation(data);
+ }
+}
+
+static bool IsSignificantlyDifferent(bool hasAngle1, double angle1,
+ bool hasAngle2, double angle2) {
+ if (hasAngle1 != hasAngle2)
+ return true;
+ return (hasAngle1 && std::fabs(angle1 - angle2) >=
+ DeviceOrientationEventPump::kOrientationThreshold);
+}
+
+bool DeviceOrientationEventPump::ShouldFireEvent(
+ const WebKit::WebDeviceOrientationData& data) const {
+ return data.allAvailableSensorsAreActive &&
+ (IsSignificantlyDifferent(
+ data_.hasAlpha, data_.alpha, data.hasAlpha, data.alpha) ||
+ IsSignificantlyDifferent(
+ data_.hasBeta, data_.beta, data.hasBeta, data.beta) ||
+ IsSignificantlyDifferent(
+ data_.hasGamma, data_.gamma, data.hasGamma, data.gamma));
+}
+
+bool DeviceOrientationEventPump::InitializeReader(
+ base::SharedMemoryHandle handle) {
+ memset(&data_, 0, sizeof(data_));
+ if (!reader_)
+ reader_.reset(new DeviceOrientationSharedMemoryReader());
+ return reader_->Initialize(handle);
+}
+
+bool DeviceOrientationEventPump::SendStartMessage() {
+ return RenderThread::Get()->Send(new DeviceOrientationHostMsg_StartPolling());
+}
+
+bool DeviceOrientationEventPump::SendStopMessage() {
+ return RenderThread::Get()->Send(new DeviceOrientationHostMsg_StopPolling());
+}
+
+} // namespace content
diff --git a/content/renderer/device_orientation/device_orientation_event_pump.h b/content/renderer/device_orientation/device_orientation_event_pump.h
new file mode 100644
index 0000000..26658ff
--- /dev/null
+++ b/content/renderer/device_orientation/device_orientation_event_pump.h
@@ -0,0 +1,54 @@
+// Copyright 2013 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_RENDERER_DEVICE_ORIENTATION_EVENT_PUMP_H_
+#define CONTENT_RENDERER_DEVICE_ORIENTATION_EVENT_PUMP_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "content/renderer/device_orientation/device_sensor_event_pump.h"
+#include "content/renderer/shared_memory_seqlock_reader.h"
+#include "third_party/WebKit/public/platform/WebDeviceOrientationData.h"
+
+namespace WebKit {
+class WebDeviceOrientationListener;
+}
+
+namespace content {
+
+typedef SharedMemorySeqLockReader<WebKit::WebDeviceOrientationData>
+ DeviceOrientationSharedMemoryReader;
+
+class CONTENT_EXPORT DeviceOrientationEventPump : public DeviceSensorEventPump {
+ public:
+ // Angle threshold beyond which two orientation events are considered
+ // sufficiently different.
+ static const double kOrientationThreshold;
+
+ DeviceOrientationEventPump();
+ explicit DeviceOrientationEventPump(int pump_delay_millis);
+ virtual ~DeviceOrientationEventPump();
+
+ // Sets the listener to receive updates for device orientation data at
+ // regular intervals. Returns true if the registration was successful.
+ bool SetListener(WebKit::WebDeviceOrientationListener* listener);
+
+ // RenderProcessObserver implementation.
+ virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE;
+
+ protected:
+ virtual void FireEvent() OVERRIDE;
+ virtual bool InitializeReader(base::SharedMemoryHandle handle) OVERRIDE;
+ virtual bool SendStartMessage() OVERRIDE;
+ virtual bool SendStopMessage() OVERRIDE;
+
+ bool ShouldFireEvent(const WebKit::WebDeviceOrientationData& data) const;
+
+ WebKit::WebDeviceOrientationListener* listener_;
+ WebKit::WebDeviceOrientationData data_;
+ scoped_ptr<DeviceOrientationSharedMemoryReader> reader_;
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_DEVICE_ORIENTATION_EVENT_PUMP_H_
diff --git a/content/renderer/device_orientation/device_orientation_event_pump_unittest.cc b/content/renderer/device_orientation/device_orientation_event_pump_unittest.cc
new file mode 100644
index 0000000..2d137ad
--- /dev/null
+++ b/content/renderer/device_orientation/device_orientation_event_pump_unittest.cc
@@ -0,0 +1,178 @@
+// Copyright 2013 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.
+
+#include "device_orientation_event_pump.h"
+
+#include "base/logging.h"
+#include "base/message_loop/message_loop.h"
+#include "content/common/device_orientation/device_orientation_hardware_buffer.h"
+#include "content/public/test/test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/public/platform/WebDeviceOrientationListener.h"
+
+namespace content {
+
+class MockDeviceOrientationListener
+ : public WebKit::WebDeviceOrientationListener {
+ public:
+ MockDeviceOrientationListener();
+ virtual ~MockDeviceOrientationListener() { }
+ virtual void didChangeDeviceOrientation(
+ const WebKit::WebDeviceOrientationData&) OVERRIDE;
+ void ResetDidChangeOrientation();
+ bool did_change_device_orientation_;
+ WebKit::WebDeviceOrientationData data_;
+};
+
+MockDeviceOrientationListener::MockDeviceOrientationListener()
+ : did_change_device_orientation_(false) {
+ memset(&data_, 0, sizeof(data_));
+}
+
+void MockDeviceOrientationListener::didChangeDeviceOrientation(
+ const WebKit::WebDeviceOrientationData& data) {
+ memcpy(&data_, &data, sizeof(data));
+ did_change_device_orientation_ = true;
+}
+
+void MockDeviceOrientationListener::ResetDidChangeOrientation() {
+ did_change_device_orientation_ = false;
+}
+
+class DeviceOrientationEventPumpForTesting : public DeviceOrientationEventPump {
+ public:
+ DeviceOrientationEventPumpForTesting() { }
+ virtual ~DeviceOrientationEventPumpForTesting() { }
+
+ void OnDidStart(base::SharedMemoryHandle renderer_handle) {
+ DeviceOrientationEventPump::OnDidStart(renderer_handle);
+ }
+ virtual bool SendStartMessage() OVERRIDE { return true; }
+ virtual bool SendStopMessage() OVERRIDE { return true; }
+};
+
+class DeviceOrientationEventPumpTest : public testing::Test {
+ public:
+ DeviceOrientationEventPumpTest() {
+ EXPECT_TRUE(shared_memory_.CreateAndMapAnonymous(
+ sizeof(DeviceOrientationHardwareBuffer)));
+ }
+
+ protected:
+ virtual void SetUp() OVERRIDE {
+ listener_.reset(new MockDeviceOrientationListener);
+ orientation_pump_.reset(new DeviceOrientationEventPumpForTesting);
+ buffer_ = static_cast<DeviceOrientationHardwareBuffer*>(
+ shared_memory_.memory());
+ memset(buffer_, 0, sizeof(DeviceOrientationHardwareBuffer));
+ shared_memory_.ShareToProcess(base::kNullProcessHandle, &handle_);
+ }
+
+ void InitBuffer() {
+ WebKit::WebDeviceOrientationData& data = buffer_->data;
+ data.alpha = 1;
+ data.hasAlpha = true;
+ data.beta = 2;
+ data.hasBeta = true;
+ data.gamma = 3;
+ data.hasGamma = true;
+ data.allAvailableSensorsAreActive = true;
+ }
+
+ scoped_ptr<MockDeviceOrientationListener> listener_;
+ scoped_ptr<DeviceOrientationEventPumpForTesting> orientation_pump_;
+ base::SharedMemoryHandle handle_;
+ base::SharedMemory shared_memory_;
+ DeviceOrientationHardwareBuffer* buffer_;
+};
+
+// Always failing in the win try bot. See http://crbug.com/256782.
+#if defined(OS_WIN)
+#define MAYBE_DidStartPolling DISABLED_DidStartPolling
+#else
+#define MAYBE_DidStartPolling DidStartPolling
+#endif
+TEST_F(DeviceOrientationEventPumpTest, MAYBE_DidStartPolling) {
+ base::MessageLoop loop(base::MessageLoop::TYPE_UI);
+ InitBuffer();
+
+ orientation_pump_->SetListener(listener_.get());
+ orientation_pump_->OnDidStart(handle_);
+ base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(
+ orientation_pump_->GetDelayMillis() * 2));
+ RunAllPendingInMessageLoop();
+ orientation_pump_->SetListener(0);
+
+ WebKit::WebDeviceOrientationData& received_data = listener_->data_;
+ EXPECT_TRUE(listener_->did_change_device_orientation_);
+ EXPECT_TRUE(received_data.allAvailableSensorsAreActive);
+ EXPECT_EQ(1, (double)received_data.alpha);
+ EXPECT_TRUE(received_data.hasAlpha);
+ EXPECT_EQ(2, (double)received_data.beta);
+ EXPECT_TRUE(received_data.hasBeta);
+ EXPECT_EQ(3, (double)received_data.gamma);
+ EXPECT_TRUE(received_data.hasGamma);
+}
+
+// Always failing in the win try bot. See http://crbug.com/256782.
+#if defined(OS_WIN)
+#define MAYBE_UpdateRespectsOrientationThreshold \
+ DISABLED_UpdateRespectsOrientationThreshold
+#else
+#define MAYBE_UpdateRespectsOrientationThreshold \
+ UpdateRespectsOrientationThreshold
+#endif
+TEST_F(DeviceOrientationEventPumpTest,
+ MAYBE_UpdateRespectsOrientationThreshold) {
+ base::MessageLoop loop(base::MessageLoop::TYPE_UI);
+ InitBuffer();
+
+ orientation_pump_->SetListener(listener_.get());
+ orientation_pump_->OnDidStart(handle_);
+ base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(
+ orientation_pump_->GetDelayMillis() * 2));
+ RunAllPendingInMessageLoop();
+
+ WebKit::WebDeviceOrientationData& received_data = listener_->data_;
+ EXPECT_TRUE(listener_->did_change_device_orientation_);
+ EXPECT_TRUE(received_data.allAvailableSensorsAreActive);
+ EXPECT_EQ(1, (double)received_data.alpha);
+ EXPECT_TRUE(received_data.hasAlpha);
+ EXPECT_EQ(2, (double)received_data.beta);
+ EXPECT_TRUE(received_data.hasBeta);
+ EXPECT_EQ(3, (double)received_data.gamma);
+ EXPECT_TRUE(received_data.hasGamma);
+
+ buffer_->data.alpha =
+ 1 + DeviceOrientationEventPump::kOrientationThreshold / 2.0;
+ listener_->ResetDidChangeOrientation();
+
+ base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(
+ orientation_pump_->GetDelayMillis() * 2));
+ RunAllPendingInMessageLoop();
+
+ EXPECT_FALSE(listener_->did_change_device_orientation_);
+ EXPECT_TRUE(received_data.allAvailableSensorsAreActive);
+ EXPECT_EQ(1, (double)received_data.alpha);
+ EXPECT_TRUE(received_data.hasAlpha);
+ EXPECT_EQ(2, (double)received_data.beta);
+ EXPECT_TRUE(received_data.hasBeta);
+ EXPECT_EQ(3, (double)received_data.gamma);
+ EXPECT_TRUE(received_data.hasGamma);
+
+ buffer_->data.alpha =
+ 1 + DeviceOrientationEventPump::kOrientationThreshold;
+ listener_->ResetDidChangeOrientation();
+
+ base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(
+ orientation_pump_->GetDelayMillis() * 2));
+ RunAllPendingInMessageLoop();
+ orientation_pump_->SetListener(0);
+
+ EXPECT_TRUE(listener_->did_change_device_orientation_);
+ EXPECT_EQ(1 + DeviceOrientationEventPump::kOrientationThreshold,
+ (double)received_data.alpha);
+}
+
+} // namespace content
diff --git a/content/renderer/device_orientation/device_sensor_event_pump.cc b/content/renderer/device_orientation/device_sensor_event_pump.cc
new file mode 100644
index 0000000..e4c0eb05
--- /dev/null
+++ b/content/renderer/device_orientation/device_sensor_event_pump.cc
@@ -0,0 +1,84 @@
+// Copyright 2013 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.
+
+#include "device_sensor_event_pump.h"
+
+#include "base/logging.h"
+#include "content/public/renderer/render_thread.h"
+
+namespace content {
+
+const int DeviceSensorEventPump::kDefaultPumpDelayMillis = 40;
+
+int DeviceSensorEventPump::GetDelayMillis() const {
+ return pump_delay_millis_;
+}
+
+DeviceSensorEventPump::DeviceSensorEventPump()
+ : pump_delay_millis_(kDefaultPumpDelayMillis),
+ state_(STOPPED) {
+}
+
+DeviceSensorEventPump::DeviceSensorEventPump(int pump_delay_millis)
+ : pump_delay_millis_(pump_delay_millis),
+ state_(STOPPED) {
+ DCHECK(pump_delay_millis_ > 0);
+}
+
+DeviceSensorEventPump::~DeviceSensorEventPump() {
+}
+
+bool DeviceSensorEventPump::RequestStart() {
+ DVLOG(2) << "requested start";
+
+ if (state_ != STOPPED)
+ return false;
+
+ DCHECK(!timer_.IsRunning());
+
+ if (SendStartMessage()) {
+ state_ = PENDING_START;
+ return true;
+ }
+ return false;
+}
+
+bool DeviceSensorEventPump::Stop() {
+ DVLOG(2) << "stop";
+
+ if (state_ == STOPPED)
+ return true;
+
+ DCHECK((state_ == PENDING_START && !timer_.IsRunning()) ||
+ (state_ == RUNNING && timer_.IsRunning()));
+
+ if (timer_.IsRunning())
+ timer_.Stop();
+ SendStopMessage();
+ state_ = STOPPED;
+ return true;
+}
+
+void DeviceSensorEventPump::Attach(RenderThread* thread) {
+ if (!thread)
+ return;
+ thread->AddObserver(this);
+}
+
+void DeviceSensorEventPump::OnDidStart(base::SharedMemoryHandle handle) {
+ DVLOG(2) << "did start sensor event pump";
+
+ if (state_ != PENDING_START)
+ return;
+
+ DCHECK(!timer_.IsRunning());
+
+ if (InitializeReader(handle)) {
+ timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(GetDelayMillis()),
+ this, &DeviceSensorEventPump::FireEvent);
+ state_ = RUNNING;
+ }
+}
+
+} // namespace content
diff --git a/content/renderer/device_orientation/device_sensor_event_pump.h b/content/renderer/device_orientation/device_sensor_event_pump.h
new file mode 100644
index 0000000..8f0e37e
--- /dev/null
+++ b/content/renderer/device_orientation/device_sensor_event_pump.h
@@ -0,0 +1,60 @@
+// Copyright 2013 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_RENDERER_DEVICE_SENSOR_EVENT_PUMP_H_
+#define CONTENT_RENDERER_DEVICE_SENSOR_EVENT_PUMP_H_
+
+#include "base/memory/shared_memory.h"
+#include "base/timer/timer.h"
+#include "content/public/renderer/render_process_observer.h"
+
+namespace content {
+class RenderThread;
+
+class CONTENT_EXPORT DeviceSensorEventPump : public RenderProcessObserver {
+ public:
+ // Default delay between subsequent firing of events.
+ static const int kDefaultPumpDelayMillis;
+
+ int GetDelayMillis() const;
+
+ void Attach(RenderThread* thread);
+ virtual bool OnControlMessageReceived(const IPC::Message& message) = 0;
+
+ protected:
+ // Constructor for a pump with default delay.
+ DeviceSensorEventPump();
+
+ // Constructor for a pump with a given delay.
+ explicit DeviceSensorEventPump(int pump_delay_millis);
+ virtual ~DeviceSensorEventPump();
+
+ // The pump is a tri-state automaton with allowed transitions as follows:
+ // STOPPED -> PENDING_START
+ // PENDING_START -> RUNNING
+ // PENDING_START -> STOPPED
+ // RUNNING -> STOPPED
+ enum PumpState {
+ STOPPED,
+ RUNNING,
+ PENDING_START
+ };
+
+ bool RequestStart();
+ void OnDidStart(base::SharedMemoryHandle handle);
+ bool Stop();
+
+ virtual void FireEvent() = 0;
+ virtual bool InitializeReader(base::SharedMemoryHandle handle) = 0;
+ virtual bool SendStartMessage() = 0;
+ virtual bool SendStopMessage() = 0;
+
+ int pump_delay_millis_;
+ PumpState state_;
+ base::RepeatingTimer<DeviceSensorEventPump> timer_;
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_DEVICE_SENSOR_EVENT_PUMP_H_
diff --git a/content/renderer/device_orientation_dispatcher.cc b/content/renderer/device_orientation_dispatcher.cc
index 68923b3..72d8688 100644
--- a/content/renderer/device_orientation_dispatcher.cc
+++ b/content/renderer/device_orientation_dispatcher.cc
@@ -4,7 +4,7 @@
#include "content/renderer/device_orientation_dispatcher.h"
-#include "content/common/device_orientation_messages.h"
+#include "content/common/device_orientation/device_orientation_messages.h"
#include "content/renderer/render_view_impl.h"
#include "third_party/WebKit/public/web/WebDeviceOrientation.h"
#include "third_party/WebKit/public/web/WebDeviceOrientationController.h"
diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc
index 09ceac1..796cb34 100644
--- a/content/renderer/renderer_webkitplatformsupport_impl.cc
+++ b/content/renderer/renderer_webkitplatformsupport_impl.cc
@@ -32,6 +32,7 @@
#include "content/public/common/webplugininfo.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/renderer/device_orientation/device_motion_event_pump.h"
+#include "content/renderer/device_orientation/device_orientation_event_pump.h"
#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
#include "content/renderer/gamepad_shared_memory_reader.h"
#include "content/renderer/media/audio_decoder.h"
@@ -54,6 +55,7 @@
#include "net/base/net_util.h"
#include "third_party/WebKit/public/platform/WebBlobRegistry.h"
#include "third_party/WebKit/public/platform/WebDeviceMotionListener.h"
+#include "third_party/WebKit/public/platform/WebDeviceOrientationListener.h"
#include "third_party/WebKit/public/platform/WebFileInfo.h"
#include "third_party/WebKit/public/platform/WebGamepads.h"
#include "third_party/WebKit/public/platform/WebMediaStreamCenter.h"
@@ -1043,6 +1045,17 @@ void RendererWebKitPlatformSupportImpl::SetMockDeviceMotionDataForTesting(
//------------------------------------------------------------------------------
+void RendererWebKitPlatformSupportImpl::setDeviceOrientationListener(
+ WebKit::WebDeviceOrientationListener* listener) {
+ if (!device_orientation_event_pump_) {
+ device_orientation_event_pump_.reset(new DeviceOrientationEventPump);
+ device_orientation_event_pump_->Attach(RenderThreadImpl::current());
+ }
+ device_orientation_event_pump_->SetListener(listener);
+}
+
+//------------------------------------------------------------------------------
+
WebKit::WebCrypto* RendererWebKitPlatformSupportImpl::crypto() {
// Use a mock implementation for testing in-progress work.
WebKit::WebCrypto* crypto =
diff --git a/content/renderer/renderer_webkitplatformsupport_impl.h b/content/renderer/renderer_webkitplatformsupport_impl.h
index e59df5c..4cfe4f1 100644
--- a/content/renderer/renderer_webkitplatformsupport_impl.h
+++ b/content/renderer/renderer_webkitplatformsupport_impl.h
@@ -34,6 +34,7 @@ class WebGraphicsContext3DProvider;
namespace content {
class DeviceMotionEventPump;
+class DeviceOrientationEventPump;
class GamepadSharedMemoryReader;
class QuotaMessageFilter;
class RendererClipboardClient;
@@ -139,6 +140,8 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl
const WebKit::WebString& host, const WebKit::WebString& languages);
virtual void setDeviceMotionListener(
WebKit::WebDeviceMotionListener* listener) OVERRIDE;
+ virtual void setDeviceOrientationListener(
+ WebKit::WebDeviceOrientationListener* listener) OVERRIDE;
virtual WebKit::WebCrypto* crypto() OVERRIDE;
virtual void queryStorageUsageAndQuota(
const WebKit::WebURL& storage_partition,
@@ -202,6 +205,7 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl
scoped_ptr<GamepadSharedMemoryReader> gamepad_shared_memory_reader_;
scoped_ptr<DeviceMotionEventPump> device_motion_event_pump_;
+ scoped_ptr<DeviceOrientationEventPump> device_orientation_event_pump_;
scoped_refptr<base::MessageLoopProxy> child_thread_loop_;
scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_;