Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/vibration/vibration_message_filter.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "content/common/view_messages.h" | |
| 10 | |
| 11 namespace content { | |
| 12 | |
| 13 // Maximum duration of a vibration is 10 seconds. | |
| 14 const unsigned int kMaximumVibrationDurationMs = 10000; | |
| 15 | |
| 16 VibrationMessageFilter::VibrationMessageFilter( | |
| 17 scoped_ptr<VibrationService> vibration_service) { | |
| 18 // TODO(mvanouwerkerk): Consider instantiating this lazily - crbug.com/250810 | |
| 19 vibration_service_.reset(vibration_service.release()); | |
|
bulach
2013/06/21 12:55:54
sorry, I just realized.. this is _always_ going to
Michael van Ouwerkerk
2013/06/21 15:07:41
Done.
| |
| 20 } | |
| 21 | |
| 22 VibrationMessageFilter::~VibrationMessageFilter() { | |
| 23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 24 if (vibration_service_.get()) | |
| 25 vibration_service_->CancelVibration(); | |
| 26 } | |
| 27 | |
| 28 bool VibrationMessageFilter::OnMessageReceived( | |
| 29 const IPC::Message& message, | |
| 30 bool* message_was_ok) { | |
| 31 bool handled = true; | |
| 32 IPC_BEGIN_MESSAGE_MAP_EX(VibrationMessageFilter, | |
| 33 message, | |
| 34 *message_was_ok) | |
| 35 IPC_MESSAGE_HANDLER(ViewHostMsg_Vibrate, OnVibrate) | |
| 36 IPC_MESSAGE_HANDLER(ViewHostMsg_CancelVibration, OnCancelVibration) | |
| 37 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 38 IPC_END_MESSAGE_MAP_EX() | |
| 39 return handled; | |
| 40 } | |
| 41 | |
| 42 void VibrationMessageFilter::OnVibrate(unsigned int milliseconds) { | |
| 43 // Though the Blink implementation rejects vibration times that are too long, | |
| 44 // don't trust the values passed from the renderer. | |
| 45 if (vibration_service_.get()) { | |
| 46 vibration_service_->Vibrate( | |
| 47 std::min(milliseconds, kMaximumVibrationDurationMs)); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 void VibrationMessageFilter::OnCancelVibration() { | |
| 52 if (vibration_service_.get()) | |
| 53 vibration_service_->CancelVibration(); | |
| 54 } | |
| 55 | |
| 56 } // namespace content | |
| OLD | NEW |