| 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/DeviceMotionAndOrientation_jni.h" | 10 #include "jni/DeviceMotionAndOrientation_jni.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 DeviceData::Type type) { | 52 DeviceData::Type type) { |
| 53 if (type != DeviceData::kTypeOrientation) | 53 if (type != DeviceData::kTypeOrientation) |
| 54 return NULL; | 54 return NULL; |
| 55 return GetOrientation(); | 55 return GetOrientation(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 const Orientation* DataFetcherImplAndroid::GetOrientation() { | 58 const Orientation* DataFetcherImplAndroid::GetOrientation() { |
| 59 // Do we have a new orientation value? (It's safe to do this outside the lock | 59 // Do we have a new orientation value? (It's safe to do this outside the lock |
| 60 // because we only skip the lock if the value is null. We always enter the | 60 // because we only skip the lock if the value is null. We always enter the |
| 61 // lock if we're going to make use of the new value.) | 61 // lock if we're going to make use of the new value.) |
| 62 if (next_orientation_) { | 62 if (next_orientation_.get()) { |
| 63 base::AutoLock autolock(next_orientation_lock_); | 63 base::AutoLock autolock(next_orientation_lock_); |
| 64 next_orientation_.swap(current_orientation_); | 64 next_orientation_.swap(current_orientation_); |
| 65 } | 65 } |
| 66 if (!current_orientation_) | 66 if (!current_orientation_.get()) |
| 67 return new Orientation(); | 67 return new Orientation(); |
| 68 return current_orientation_.get(); | 68 return current_orientation_.get(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void DataFetcherImplAndroid::GotOrientation( | 71 void DataFetcherImplAndroid::GotOrientation( |
| 72 JNIEnv*, jobject, double alpha, double beta, double gamma) { | 72 JNIEnv*, jobject, double alpha, double beta, double gamma) { |
| 73 base::AutoLock autolock(next_orientation_lock_); | 73 base::AutoLock autolock(next_orientation_lock_); |
| 74 | 74 |
| 75 Orientation* orientation = new Orientation(); | 75 Orientation* orientation = new Orientation(); |
| 76 orientation->set_alpha(alpha); | 76 orientation->set_alpha(alpha); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 static_cast<jint>(event_type)); | 111 static_cast<jint>(event_type)); |
| 112 } | 112 } |
| 113 | 113 |
| 114 int DataFetcherImplAndroid::GetNumberActiveDeviceMotionSensors() { | 114 int DataFetcherImplAndroid::GetNumberActiveDeviceMotionSensors() { |
| 115 DCHECK(!device_orientation_.is_null()); | 115 DCHECK(!device_orientation_.is_null()); |
| 116 return Java_DeviceMotionAndOrientation_getNumberActiveDeviceMotionSensors( | 116 return Java_DeviceMotionAndOrientation_getNumberActiveDeviceMotionSensors( |
| 117 AttachCurrentThread(), device_orientation_.obj()); | 117 AttachCurrentThread(), device_orientation_.obj()); |
| 118 } | 118 } |
| 119 | 119 |
| 120 } // namespace content | 120 } // namespace content |
| OLD | NEW |