Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | |
|
Peter Beverloo
2013/03/12 17:11:22
What does this mean? Figuring something out does
timvolodine
2013/03/13 12:32:24
Done.
| |
| 35 // multiple event types. | |
| 34 DataFetcher* DataFetcherImplAndroid::Create() { | 36 DataFetcher* DataFetcherImplAndroid::Create() { |
|
Miguel Garcia
2013/03/12 17:00:26
don't you want to at least change the interface no
timvolodine
2013/03/13 12:32:24
This probably goes out of scope of this CL, becaus
| |
| 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 // TODO(timvolodine): stop all active event types, not only |
|
Peter Beverloo
2013/03/12 17:11:22
This TODO should read "Support device motion as we
timvolodine
2013/03/13 12:32:24
Done.
| |
| 47 // device orientation, when implemented. | |
| 48 Stop(DeviceData::kTypeOrientation); | |
| 45 } | 49 } |
| 46 | 50 |
| 47 const DeviceData* DataFetcherImplAndroid::GetDeviceData( | 51 const DeviceData* DataFetcherImplAndroid::GetDeviceData( |
| 48 DeviceData::Type type) { | 52 DeviceData::Type type) { |
| 49 if (type != DeviceData::kTypeOrientation) | 53 if (type != DeviceData::kTypeOrientation) |
| 50 return NULL; | 54 return NULL; |
| 51 return GetOrientation(); | 55 return GetOrientation(); |
| 52 } | 56 } |
| 53 | 57 |
| 54 const Orientation* DataFetcherImplAndroid::GetOrientation() { | 58 const Orientation* DataFetcherImplAndroid::GetOrientation() { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 69 base::AutoLock autolock(next_orientation_lock_); | 73 base::AutoLock autolock(next_orientation_lock_); |
| 70 | 74 |
| 71 Orientation* orientation = new Orientation(); | 75 Orientation* orientation = new Orientation(); |
| 72 orientation->set_alpha(alpha); | 76 orientation->set_alpha(alpha); |
| 73 orientation->set_beta(beta); | 77 orientation->set_beta(beta); |
| 74 orientation->set_gamma(gamma); | 78 orientation->set_gamma(gamma); |
| 75 orientation->set_absolute(true); | 79 orientation->set_absolute(true); |
| 76 next_orientation_ = orientation; | 80 next_orientation_ = orientation; |
| 77 } | 81 } |
| 78 | 82 |
| 79 bool DataFetcherImplAndroid::Start(int rate_in_milliseconds) { | 83 void DataFetcherImplAndroid::GotAcceleration( |
| 84 JNIEnv*, jobject, double x, double y, double z) { | |
| 85 NOTIMPLEMENTED(); | |
| 86 } | |
| 87 | |
| 88 void DataFetcherImplAndroid::GotAccelerationIncludingGravity( | |
| 89 JNIEnv*, jobject, double x, double y, double z) { | |
| 90 NOTIMPLEMENTED(); | |
| 91 } | |
| 92 | |
| 93 void DataFetcherImplAndroid::GotRotationRate( | |
| 94 JNIEnv*, jobject, double alpha, double beta, double gamma) { | |
| 95 NOTIMPLEMENTED(); | |
| 96 } | |
| 97 | |
| 98 bool DataFetcherImplAndroid::Start(DeviceData::Type event_type, | |
| 99 int rate_in_milliseconds) { | |
| 80 DCHECK(!device_orientation_.is_null()); | 100 DCHECK(!device_orientation_.is_null()); |
| 81 return Java_DeviceOrientation_start(AttachCurrentThread(), | 101 return Java_DeviceMotionAndOrientation_start(AttachCurrentThread(), |
| 82 device_orientation_.obj(), | 102 device_orientation_.obj(), |
| 83 reinterpret_cast<jint>(this), | 103 reinterpret_cast<jint>(this), |
| 104 event_type, | |
|
Miguel Garcia
2013/03/12 17:00:26
what happened to the cast suggestion from Peter?
Peter Beverloo
2013/03/12 17:11:22
Try-jobs are running, let's see what they say. No
timvolodine
2013/03/13 12:32:24
Done.
timvolodine
2013/03/13 12:32:24
ok, added static_cast<jint>
On 2013/03/12 17:11:2
| |
| 84 rate_in_milliseconds); | 105 rate_in_milliseconds); |
| 85 } | 106 } |
| 86 | 107 |
| 87 void DataFetcherImplAndroid::Stop() { | 108 void DataFetcherImplAndroid::Stop(DeviceData::Type event_type) { |
| 88 DCHECK(!device_orientation_.is_null()); | 109 DCHECK(!device_orientation_.is_null()); |
| 89 Java_DeviceOrientation_stop(AttachCurrentThread(), device_orientation_.obj()); | 110 Java_DeviceMotionAndOrientation_stop(AttachCurrentThread(), |
| 111 device_orientation_.obj(), | |
| 112 event_type); | |
|
Peter Beverloo
2013/03/12 17:11:22
Dito to my reply to Miguel's comment on line 104.
timvolodine
2013/03/13 12:32:24
Done.
| |
| 90 } | 113 } |
| 91 | 114 |
| 92 } // namespace content | 115 } // namespace content |
| OLD | NEW |