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

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

Issue 10755002: Refactors DeviceOrientation to make it more extensible (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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/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"
11 #include "content/browser/device_orientation/device_data.h"
11 #include "content/browser/device_orientation/orientation.h" 12 #include "content/browser/device_orientation/orientation.h"
12 #include "jni/device_orientation_jni.h" 13 #include "jni/device_orientation_jni.h"
13 14
14 using base::android::AttachCurrentThread; 15 using base::android::AttachCurrentThread;
15 using base::android::CheckException; 16 using base::android::CheckException;
16 using base::android::GetClass; 17 using base::android::GetClass;
17 using base::android::GetMethodID; 18 using base::android::GetMethodID;
18 using base::android::ScopedJavaGlobalRef; 19 using base::android::ScopedJavaGlobalRef;
19 using base::android::ScopedJavaLocalRef; 20 using base::android::ScopedJavaLocalRef;
20 21
(...skipping 26 matching lines...) Expand all
47 return fetcher.release(); 48 return fetcher.release();
48 49
49 LOG(ERROR) << "DataFetcherImplAndroid::Start failed!"; 50 LOG(ERROR) << "DataFetcherImplAndroid::Start failed!";
50 return NULL; 51 return NULL;
51 } 52 }
52 53
53 DataFetcherImplAndroid::~DataFetcherImplAndroid() { 54 DataFetcherImplAndroid::~DataFetcherImplAndroid() {
54 Stop(); 55 Stop();
55 } 56 }
56 57
58 bool DataFetcherImplAndroid::GetDeviceData(DeviceData* device_data) {
59 switch (device_data->device_data_type()) {
60 case DeviceData::kDeviceOrientationData:
61 return GetOrientation(static_cast<Orientation*>(device_data));
62 default:
63 return false;
64 }
65 }
66
57 bool DataFetcherImplAndroid::GetOrientation(Orientation* orientation) { 67 bool DataFetcherImplAndroid::GetOrientation(Orientation* orientation) {
58 // Do we have a new orientation value? (It's safe to do this outside the lock 68 // 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 69 // 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.) 70 // lock if we're going to make use of the new value.)
61 if (next_orientation_.get()) { 71 if (next_orientation_.get()) {
62 base::AutoLock autolock(next_orientation_lock_); 72 base::AutoLock autolock(next_orientation_lock_);
63 next_orientation_.swap(current_orientation_); 73 next_orientation_.swap(current_orientation_);
64 } 74 }
65 if (current_orientation_.get()) 75 if (current_orientation_.get())
66 *orientation = *current_orientation_; 76 *orientation = *current_orientation_;
(...skipping 19 matching lines...) Expand all
86 reinterpret_cast<jint>(this), 96 reinterpret_cast<jint>(this),
87 rate_in_milliseconds); 97 rate_in_milliseconds);
88 } 98 }
89 99
90 void DataFetcherImplAndroid::Stop() { 100 void DataFetcherImplAndroid::Stop() {
91 DCHECK(!g_jni_obj.Get().is_null()); 101 DCHECK(!g_jni_obj.Get().is_null());
92 Java_DeviceOrientation_stop(AttachCurrentThread(), g_jni_obj.Get().obj()); 102 Java_DeviceOrientation_stop(AttachCurrentThread(), g_jni_obj.Get().obj());
93 } 103 }
94 104
95 } // namespace device_orientation 105 } // namespace device_orientation
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698