Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Unified Diff: content/browser/vibration/vibration_browser_message_filter.cc

Issue 16781002: Vibration API: plumbing from Blink to Java. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/vibration/vibration_browser_message_filter.cc
diff --git a/content/browser/vibration/vibration_browser_message_filter.cc b/content/browser/vibration/vibration_browser_message_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3da39d8dc7375cb9ca56587928a3139f7e3f76a5
--- /dev/null
+++ b/content/browser/vibration/vibration_browser_message_filter.cc
@@ -0,0 +1,50 @@
+// Copyright (c) 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/vibration/vibration_browser_message_filter.h"
+
+#include <algorithm>
+
+#include "content/common/view_messages.h"
+
+namespace content {
+
+// Maximum duration of a vibration is 10 seconds.
+const unsigned kVibrationDurationMax = 10000;
Peter Beverloo 2013/06/13 11:27:45 kMaximumVibrationDurationMs
Michael van Ouwerkerk 2013/06/18 14:39:23 Done.
+
+VibrationBrowserMessageFilter::VibrationBrowserMessageFilter(
+ scoped_ptr<VibrationService> vibration_service) {
+ // TODO(mvanouwerkerk): Instantiate this lazily? We might want to get it early
+ // anyway so we can decide whether to expose navigator.vibrate or not.
Peter Beverloo 2013/06/13 11:27:45 I think this reasoning would be better stored in a
Michael van Ouwerkerk 2013/06/18 14:39:23 Done.
+ vibration_service_.reset(vibration_service.release());
+}
+
+VibrationBrowserMessageFilter::~VibrationBrowserMessageFilter() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ vibration_service_->CancelVibration();
+}
+
+bool VibrationBrowserMessageFilter::OnMessageReceived(
+ const IPC::Message& message,
+ bool* message_was_ok) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(VibrationBrowserMessageFilter,
+ message,
+ *message_was_ok)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_Vibrate, OnVibrate)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_CancelVibration, OnCancelVibration)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP_EX()
+ return handled;
+}
+
+void VibrationBrowserMessageFilter::OnVibrate(unsigned time) {
+ vibration_service_->Vibrate(std::min(time, kVibrationDurationMax));
+}
+
+void VibrationBrowserMessageFilter::OnCancelVibration() {
+ vibration_service_->CancelVibration();
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698