Add ICU message format support
[chromium-blink-merge.git] / device / vibration / vibration_manager_impl_android.cc
blob6171feb61b64707d5b00bbb9aa0f5dabc1999470
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 "device/vibration/vibration_manager_impl.h"
8 #include "jni/VibrationProvider_jni.h"
10 using base::android::AttachCurrentThread;
12 namespace device {
14 namespace {
15 const int64 kMinimumVibrationDurationMs = 1; // 1 millisecond
16 const int64 kMaximumVibrationDurationMs = 10000; // 10 seconds
19 VibrationManagerImplAndroid::VibrationManagerImplAndroid(
20 mojo::InterfaceRequest<VibrationManager> request)
21 : binding_(this, request.Pass()) {
22 j_vibration_provider_.Reset(
23 Java_VibrationProvider_create(AttachCurrentThread(),
24 base::android::GetApplicationContext()));
27 VibrationManagerImplAndroid::~VibrationManagerImplAndroid() {
30 // static
31 bool VibrationManagerImplAndroid::Register(JNIEnv* env) {
32 return RegisterNativesImpl(env);
35 void VibrationManagerImplAndroid::Vibrate(int64 milliseconds) {
36 // Though the Blink implementation already sanitizes vibration times, don't
37 // trust any values passed from the client.
38 int64 sanitized_milliseconds = std::max(kMinimumVibrationDurationMs,
39 std::min(milliseconds, kMaximumVibrationDurationMs));
41 Java_VibrationProvider_vibrate(AttachCurrentThread(),
42 j_vibration_provider_.obj(),
43 sanitized_milliseconds);
46 void VibrationManagerImplAndroid::Cancel() {
47 Java_VibrationProvider_cancelVibration(AttachCurrentThread(),
48 j_vibration_provider_.obj());
51 // static
52 void VibrationManagerImpl::Create(
53 mojo::InterfaceRequest<VibrationManager> request) {
54 new VibrationManagerImplAndroid(request.Pass());
57 } // namespace device