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/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 return fetcher.release(); | 47 return fetcher.release(); |
| 48 | 48 |
| 49 LOG(ERROR) << "DataFetcherImplAndroid::Start failed!"; | 49 LOG(ERROR) << "DataFetcherImplAndroid::Start failed!"; |
| 50 return NULL; | 50 return NULL; |
| 51 } | 51 } |
| 52 | 52 |
| 53 DataFetcherImplAndroid::~DataFetcherImplAndroid() { | 53 DataFetcherImplAndroid::~DataFetcherImplAndroid() { |
| 54 Stop(); | 54 Stop(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 bool DataFetcherImplAndroid::GetOrientation(Orientation* orientation) { | 57 const DeviceData* DataFetcherImplAndroid::GetDeviceData( |
| 58 DeviceData::Type type) { | |
| 59 if (type != DeviceData::kTypeOrientation) | |
| 60 return NULL; | |
| 61 return GetOrientation(); | |
| 62 } | |
| 63 | |
| 64 const Orientation* DataFetcherImplAndroid::GetOrientation() { | |
| 58 // Do we have a new orientation value? (It's safe to do this outside the lock | 65 // Do we have a new orientation value? (It's safe to do this outside the lock |
| 59 // because we only skip the lock if the value is null. We always enter the | 66 // because we only skip the lock if the value is null. We always enter the |
| 60 // lock if we're going to make use of the new value.) | 67 // lock if we're going to make use of the new value.) |
| 61 if (next_orientation_.get()) { | 68 if (next_orientation_.get()) { |
| 62 base::AutoLock autolock(next_orientation_lock_); | 69 base::AutoLock autolock(next_orientation_lock_); |
| 63 next_orientation_.swap(current_orientation_); | 70 next_orientation_.swap(current_orientation_); |
| 64 } | 71 } |
| 72 scoped_refptr<Orientation> orientation(new Orientation()); | |
| 65 if (current_orientation_.get()) | 73 if (current_orientation_.get()) |
| 66 *orientation = *current_orientation_; | 74 *orientation = *current_orientation_; |
| 67 return true; | 75 return orientation; |
|
hans
2012/08/03 13:05:41
i think we can simplify this to something like:
i
aousterh
2012/08/03 13:42:18
Done.
| |
| 68 } | 76 } |
| 69 | 77 |
| 70 void DataFetcherImplAndroid::GotOrientation( | 78 void DataFetcherImplAndroid::GotOrientation( |
| 71 JNIEnv*, jobject, double alpha, double beta, double gamma) { | 79 JNIEnv*, jobject, double alpha, double beta, double gamma) { |
| 72 base::AutoLock autolock(next_orientation_lock_); | 80 base::AutoLock autolock(next_orientation_lock_); |
| 73 | 81 |
| 74 Orientation* orientation = new Orientation(); | 82 Orientation* orientation = new Orientation(); |
| 75 orientation->set_alpha(alpha); | 83 orientation->set_alpha(alpha); |
| 76 orientation->set_beta(beta); | 84 orientation->set_beta(beta); |
| 77 orientation->set_gamma(gamma); | 85 orientation->set_gamma(gamma); |
| 78 orientation->set_absolute(true); | 86 orientation->set_absolute(true); |
| 79 next_orientation_.reset(orientation); | 87 next_orientation_.reset(orientation); |
| 80 } | 88 } |
| 81 | 89 |
| 82 bool DataFetcherImplAndroid::Start(int rate_in_milliseconds) { | 90 bool DataFetcherImplAndroid::Start(int rate_in_milliseconds) { |
| 83 DCHECK(!g_jni_obj.Get().is_null()); | 91 DCHECK(!g_jni_obj.Get().is_null()); |
| 84 return Java_DeviceOrientation_start(AttachCurrentThread(), | 92 return Java_DeviceOrientation_start(AttachCurrentThread(), |
| 85 g_jni_obj.Get().obj(), | 93 g_jni_obj.Get().obj(), |
| 86 reinterpret_cast<jint>(this), | 94 reinterpret_cast<jint>(this), |
| 87 rate_in_milliseconds); | 95 rate_in_milliseconds); |
| 88 } | 96 } |
| 89 | 97 |
| 90 void DataFetcherImplAndroid::Stop() { | 98 void DataFetcherImplAndroid::Stop() { |
| 91 DCHECK(!g_jni_obj.Get().is_null()); | 99 DCHECK(!g_jni_obj.Get().is_null()); |
| 92 Java_DeviceOrientation_stop(AttachCurrentThread(), g_jni_obj.Get().obj()); | 100 Java_DeviceOrientation_stop(AttachCurrentThread(), g_jni_obj.Get().obj()); |
| 93 } | 101 } |
| 94 | 102 |
| 95 } // namespace device_orientation | 103 } // namespace device_orientation |
| OLD | NEW |