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

Side by Side Diff: content/browser/device_orientation/data_fetcher_impl_android.cc

Issue 12771008: Implement java-side browser sensor polling for device motion and device orientation DOM events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: taking into account the comments Created 7 years, 9 months 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/device_orientation/data_fetcher_impl_android.h" 5 #include "content/browser/device_orientation/data_fetcher_impl_android.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/browser/device_orientation/orientation.h" 9 #include "content/browser/device_orientation/orientation.h"
10 #include "jni/DeviceOrientation_jni.h" 10 #include "jni/DeviceMotionAndOrientation_jni.h"
11 11
12 using base::android::AttachCurrentThread; 12 using base::android::AttachCurrentThread;
13 13
14 namespace content { 14 namespace content {
15 15
16 namespace { 16 namespace {
17 17
18 // This should match ProviderImpl::kDesiredSamplingIntervalMs. 18 // This should match ProviderImpl::kDesiredSamplingIntervalMs.
19 // TODO(husky): Make that constant public so we can use it directly. 19 // TODO(husky): Make that constant public so we can use it directly.
20 const int kPeriodInMilliseconds = 100; 20 const int kPeriodInMilliseconds = 100;
21 21
22 } // namespace 22 } // namespace
23 23
24 DataFetcherImplAndroid::DataFetcherImplAndroid() { 24 DataFetcherImplAndroid::DataFetcherImplAndroid() {
25 device_orientation_.Reset( 25 device_orientation_.Reset(
26 Java_DeviceOrientation_getInstance(AttachCurrentThread())); 26 Java_DeviceMotionAndOrientation_getInstance(AttachCurrentThread()));
27 } 27 }
28 28
29 void DataFetcherImplAndroid::Init(JNIEnv* env) { 29 void DataFetcherImplAndroid::Init(JNIEnv* env) {
30 bool result = RegisterNativesImpl(env); 30 bool result = RegisterNativesImpl(env);
31 DCHECK(result); 31 DCHECK(result);
32 } 32 }
33 33
34 // TODO(timvolodine): figure out how to modify this method in case of
35 // multiple event types.
34 DataFetcher* DataFetcherImplAndroid::Create() { 36 DataFetcher* DataFetcherImplAndroid::Create() {
35 scoped_ptr<DataFetcherImplAndroid> fetcher(new DataFetcherImplAndroid); 37 scoped_ptr<DataFetcherImplAndroid> fetcher(new DataFetcherImplAndroid);
36 if (fetcher->Start(kPeriodInMilliseconds)) 38 if (fetcher->Start(DeviceData::kTypeOrientation, kPeriodInMilliseconds))
37 return fetcher.release(); 39 return fetcher.release();
38 40
39 LOG(ERROR) << "DataFetcherImplAndroid::Start failed!"; 41 LOG(ERROR) << "DataFetcherImplAndroid::Start failed!";
40 return NULL; 42 return NULL;
41 } 43 }
42 44
43 DataFetcherImplAndroid::~DataFetcherImplAndroid() { 45 DataFetcherImplAndroid::~DataFetcherImplAndroid() {
44 Stop(); 46 Stop(DeviceData::kTypeOrientation);
Peter Beverloo 2013/03/12 11:26:39 nit: add a TODO to cover that this should shut dow
timvolodine 2013/03/12 16:12:46 Done.
45 } 47 }
46 48
47 const DeviceData* DataFetcherImplAndroid::GetDeviceData( 49 const DeviceData* DataFetcherImplAndroid::GetDeviceData(
48 DeviceData::Type type) { 50 DeviceData::Type type) {
49 if (type != DeviceData::kTypeOrientation) 51 if (type != DeviceData::kTypeOrientation)
50 return NULL; 52 return NULL;
51 return GetOrientation(); 53 return GetOrientation();
52 } 54 }
53 55
54 const Orientation* DataFetcherImplAndroid::GetOrientation() { 56 const Orientation* DataFetcherImplAndroid::GetOrientation() {
(...skipping 14 matching lines...) Expand all
69 base::AutoLock autolock(next_orientation_lock_); 71 base::AutoLock autolock(next_orientation_lock_);
70 72
71 Orientation* orientation = new Orientation(); 73 Orientation* orientation = new Orientation();
72 orientation->set_alpha(alpha); 74 orientation->set_alpha(alpha);
73 orientation->set_beta(beta); 75 orientation->set_beta(beta);
74 orientation->set_gamma(gamma); 76 orientation->set_gamma(gamma);
75 orientation->set_absolute(true); 77 orientation->set_absolute(true);
76 next_orientation_ = orientation; 78 next_orientation_ = orientation;
77 } 79 }
78 80
79 bool DataFetcherImplAndroid::Start(int rate_in_milliseconds) { 81 void DataFetcherImplAndroid::GotAcceleration(
82 JNIEnv*, jobject, double x, double y, double z) {
83 // TODO(timvolodine): copy into shared memory buffer
Peter Beverloo 2013/03/12 11:26:39 It's fine to get rid of the TODO now that there's
timvolodine 2013/03/12 16:12:46 Done.
84 NOTIMPLEMENTED();
85 }
86
87 void DataFetcherImplAndroid::GotAccelerationIncludingGravity(
88 JNIEnv*, jobject, double x, double y, double z) {
89 NOTIMPLEMENTED();
90 }
91
92 void DataFetcherImplAndroid::GotRotationRate(
93 JNIEnv*, jobject, double alpha, double beta, double gamma) {
94 NOTIMPLEMENTED();
95 }
96
97 bool DataFetcherImplAndroid::Start(DeviceData::Type event_type,
98 int rate_in_milliseconds) {
80 DCHECK(!device_orientation_.is_null()); 99 DCHECK(!device_orientation_.is_null());
81 return Java_DeviceOrientation_start(AttachCurrentThread(), 100 return Java_DeviceMotionAndOrientation_start(AttachCurrentThread(),
82 device_orientation_.obj(), 101 device_orientation_.obj(),
83 reinterpret_cast<jint>(this), 102 reinterpret_cast<jint>(this),
103 event_type,
Peter Beverloo 2013/03/12 11:26:39 nit: don't we need a cast here for strictness? Pl
timvolodine 2013/03/12 16:12:46 rate_in_milliseconds below does not use any casts,
84 rate_in_milliseconds); 104 rate_in_milliseconds);
85 } 105 }
86 106
87 void DataFetcherImplAndroid::Stop() { 107 void DataFetcherImplAndroid::Stop(DeviceData::Type event_type) {
88 DCHECK(!device_orientation_.is_null()); 108 DCHECK(!device_orientation_.is_null());
89 Java_DeviceOrientation_stop(AttachCurrentThread(), device_orientation_.obj()); 109 Java_DeviceMotionAndOrientation_stop(AttachCurrentThread(),
110 device_orientation_.obj(),
111 event_type);
Peter Beverloo 2013/03/12 11:26:39 nit: dito.
timvolodine 2013/03/12 16:12:46 Done.
90 } 112 }
91 113
92 } // namespace content 114 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698