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

Side by Side Diff: device/vibration/vibration_manager_impl.cc

Issue 583663003: Vibration API : migrate to device/vibration using mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 6 years 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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 "device/vibration/vibration_manager_impl.h"
6
7 #include "base/bind.h"
8 #include "device/vibration/vibration_provider.h"
9
10 namespace device {
11
12 namespace {
13 VibrationProvider* g_provider_override = NULL;
14 const int64 kMinimumVibrationDurationMs = 1; // 1 millisecond
15 const int64 kMaximumVibrationDurationMs = 10000; // 10 seconds
16 }
17
18 //static
19 void VibrationManagerImpl::Create(
20 mojo::InterfaceRequest<VibrationManager> request) {
21 BindToRequest(new VibrationManagerImpl(), &request);
22 }
23
24 VibrationManagerImpl::VibrationManagerImpl()
25 : provider_(g_provider_override ? g_provider_override : CreateProvider()) {
26 }
27
28 VibrationManagerImpl::~VibrationManagerImpl() {
29 }
30
31 void VibrationManagerImpl::Vibrate(int64 milliseconds) {
32 if (!provider_)
33 return;
34
35 // Though the Blink implementation already sanitizes vibration times, don't
36 // trust any values passed from the renderer.
37 int64 sanitized_milliseconds = std::max(kMinimumVibrationDurationMs,
38 std::min(milliseconds, kMaximumVibrationDurationMs));
39
40 provider_->Vibrate(sanitized_milliseconds);
41 }
42
43 void VibrationManagerImpl::Cancel() {
44 if (provider_)
45 provider_->CancelVibration();
46 }
47
48 #if !defined(OS_ANDROID)
49 // static
50 VibrationProvider* VibrationManagerImpl::CreateProvider() {
51 return NULL;
52 }
53 #endif
54
55 // static
56 void VibrationManagerImpl::SetOverrideVibrationProvider(
57 VibrationProvider* provider) {
58 g_provider_override = provider;
59 }
60
61 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698