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

Unified Diff: content/browser/device_orientation/accelerometer_mac.cc

Issue 10755002: Refactors DeviceOrientation to make it more extensible (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Handles null device_data in observer 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/device_orientation/accelerometer_mac.cc
diff --git a/content/browser/device_orientation/accelerometer_mac.cc b/content/browser/device_orientation/accelerometer_mac.cc
index bdc42786f84fe2a0c670e6844057bab7921eef79..88b585e2bd4be7a4bc6e0c8c99b4826cf05548b1 100644
--- a/content/browser/device_orientation/accelerometer_mac.cc
+++ b/content/browser/device_orientation/accelerometer_mac.cc
@@ -24,6 +24,12 @@ AccelerometerMac::~AccelerometerMac() {
AccelerometerMac::AccelerometerMac() {
}
+DeviceData* AccelerometerMac::GetDeviceData(DeviceData::Type device_data_type) {
+ if (device_data_type() != DeviceData::kTypeOrientation)
+ return NULL;
+ return GetOrientation();
+}
+
// Retrieve per-axis orientation values.
//
// Axes and angles are defined according to the W3C DeviceOrientation Draft.
@@ -33,13 +39,13 @@ AccelerometerMac::AccelerometerMac() {
//
// Returns false in case of error.
//
-bool AccelerometerMac::GetOrientation(Orientation* orientation) {
+Orientation* AccelerometerMac::GetOrientation() {
DCHECK(sudden_motion_sensor_.get());
// Retrieve per-axis calibrated values.
float axis_value[3];
if (!sudden_motion_sensor_->ReadSensorValues(axis_value))
- return false;
+ return NULL;
// Transform the accelerometer values to W3C draft angles.
//
@@ -63,6 +69,8 @@ bool AccelerometerMac::GetOrientation(Orientation* orientation) {
//
const double kRad2deg = 180.0 / M_PI;
+ scoped_ptr<Orientation> orientation(new Orientation());
+
orientation->set_beta(kRad2deg * atan2(-axis_value[1], axis_value[2]));
orientation->set_gamma(kRad2deg * asin(axis_value[0]));
// TODO(aousterh): should absolute_ be set to false here?
@@ -85,7 +93,7 @@ bool AccelerometerMac::GetOrientation(Orientation* orientation) {
DCHECK_GE(orientation->gamma(), -90.0);
DCHECK_LT(orientation->gamma(), 90.0);
- return true;
+ return orientation.release();
}
bool AccelerometerMac::Init() {

Powered by Google App Engine
This is Rietveld 408576698