Don't add extra app list launcher page webviews.
[chromium-blink-merge.git] / device / vibration / vibration_manager_impl_android.cc
blobca54e9e4cbe6f88f71b6d8540ddab5ae78f47e98
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.
5 #include "device/vibration/vibration_manager_impl_android.h"
7 #include "base/bind.h"
8 #include "device/vibration/vibration_manager_impl.h"
9 #include "jni/VibrationProvider_jni.h"
11 using base::android::AttachCurrentThread;
13 namespace device {
15 namespace {
16 const int64 kMinimumVibrationDurationMs = 1; // 1 millisecond
17 const int64 kMaximumVibrationDurationMs = 10000; // 10 seconds
20 // static
21 VibrationManagerImplAndroid* VibrationManagerImplAndroid::Create() {
22 return new VibrationManagerImplAndroid();
25 VibrationManagerImplAndroid::VibrationManagerImplAndroid() {
26 j_vibration_provider_.Reset(
27 Java_VibrationProvider_create(AttachCurrentThread(),
28 base::android::GetApplicationContext()));
31 VibrationManagerImplAndroid::~VibrationManagerImplAndroid() {
34 // static
35 bool VibrationManagerImplAndroid::Register(JNIEnv* env) {
36 return RegisterNativesImpl(env);
39 void VibrationManagerImplAndroid::Vibrate(int64 milliseconds) {
40 // Though the Blink implementation already sanitizes vibration times, don't
41 // trust any values passed from the client.
42 int64 sanitized_milliseconds = std::max(kMinimumVibrationDurationMs,
43 std::min(milliseconds, kMaximumVibrationDurationMs));
45 Java_VibrationProvider_vibrate(AttachCurrentThread(),
46 j_vibration_provider_.obj(),
47 sanitized_milliseconds);
50 void VibrationManagerImplAndroid::Cancel() {
51 Java_VibrationProvider_cancelVibration(AttachCurrentThread(),
52 j_vibration_provider_.obj());
55 // static
56 void VibrationManagerImpl::Create(
57 mojo::InterfaceRequest<VibrationManager> request) {
58 BindToRequest(VibrationManagerImplAndroid::Create(), &request);
61 } // namespace device