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 kMaximumVibrationDurationMs = 10000; | |
bulach
2013/06/20 14:21:04
nit: int
Michael van Ouwerkerk
2013/06/20 17:34:09
Why int? Did you mean 'unsigned int'? The vibratio
bulach
2013/06/20 18:11:47
sorry, I should've been clearer: "unsigned int" ra
Michael van Ouwerkerk
2013/06/21 09:53:38
Done in the whole patch.
| |
15 | |
16 VibrationMessageFilter::VibrationMessageFilter( | |
17 VibrationService* vibration_service) { | |
18 // TODO(mvanouwerkerk): Consider instantiating this lazily - crbug.com/250810 | |
19 vibration_service_.reset(vibration_service); | |
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 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 |