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

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: Moves construction of DeviceData objects out of ProviderImpl 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"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 DeviceData* DataFetcherImplAndroid::GetDeviceData(
58 DeviceData::DeviceDataType* device_data_type) {
59 switch (device_data_type) {
bulach 2012/07/12 10:43:27 nit: as above..
aousterh 2012/07/12 17:13:57 Actually for this one, I will (hopefully) be addin
60 case DeviceData::kDeviceOrientationData:
61 return GetOrientation();
62 default:
63 return NULL;
64 }
65 }
66
67 Orientation* DataFetcherImplAndroid::GetOrientation() {
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 }
75 scoped_ptr<Orientation> orientation(new Orientation());
65 if (current_orientation_.get()) 76 if (current_orientation_.get())
66 *orientation = *current_orientation_; 77 *orientation = *current_orientation_;
67 return true; 78 return orientation.release();
68 } 79 }
69 80
70 void DataFetcherImplAndroid::GotOrientation( 81 void DataFetcherImplAndroid::GotOrientation(
71 JNIEnv*, jobject, double alpha, double beta, double gamma) { 82 JNIEnv*, jobject, double alpha, double beta, double gamma) {
72 base::AutoLock autolock(next_orientation_lock_); 83 base::AutoLock autolock(next_orientation_lock_);
73 84
74 Orientation* orientation = new Orientation(); 85 Orientation* orientation = new Orientation();
75 orientation->set_alpha(alpha); 86 orientation->set_alpha(alpha);
76 orientation->set_beta(beta); 87 orientation->set_beta(beta);
77 orientation->set_gamma(gamma); 88 orientation->set_gamma(gamma);
78 orientation->set_absolute(true); 89 orientation->set_absolute(true);
79 next_orientation_.reset(orientation); 90 next_orientation_.reset(orientation);
80 } 91 }
81 92
82 bool DataFetcherImplAndroid::Start(int rate_in_milliseconds) { 93 bool DataFetcherImplAndroid::Start(int rate_in_milliseconds) {
83 DCHECK(!g_jni_obj.Get().is_null()); 94 DCHECK(!g_jni_obj.Get().is_null());
84 return Java_DeviceOrientation_start(AttachCurrentThread(), 95 return Java_DeviceOrientation_start(AttachCurrentThread(),
85 g_jni_obj.Get().obj(), 96 g_jni_obj.Get().obj(),
86 reinterpret_cast<jint>(this), 97 reinterpret_cast<jint>(this),
87 rate_in_milliseconds); 98 rate_in_milliseconds);
88 } 99 }
89 100
90 void DataFetcherImplAndroid::Stop() { 101 void DataFetcherImplAndroid::Stop() {
91 DCHECK(!g_jni_obj.Get().is_null()); 102 DCHECK(!g_jni_obj.Get().is_null());
92 Java_DeviceOrientation_stop(AttachCurrentThread(), g_jni_obj.Get().obj()); 103 Java_DeviceOrientation_stop(AttachCurrentThread(), g_jni_obj.Get().obj());
93 } 104 }
94 105
95 } // namespace device_orientation 106 } // namespace device_orientation
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698