| Index: third_party/sudden_motion_sensor/sudden_motion_sensor_mac.cc
 | 
| diff --git a/content/browser/device_orientation/accelerometer_mac.cc b/third_party/sudden_motion_sensor/sudden_motion_sensor_mac.cc
 | 
| similarity index 79%
 | 
| copy from content/browser/device_orientation/accelerometer_mac.cc
 | 
| copy to third_party/sudden_motion_sensor/sudden_motion_sensor_mac.cc
 | 
| index eec575167e4e7100e7f92999958ec8fe8c5f4416..0e1ce2fafbd875b1d1092e88d95ffe18b8e7faca 100644
 | 
| --- a/content/browser/device_orientation/accelerometer_mac.cc
 | 
| +++ b/third_party/sudden_motion_sensor/sudden_motion_sensor_mac.cc
 | 
| @@ -48,7 +48,7 @@
 | 
|  //    Wakefield, MA 01880
 | 
|  //    (781) 665-0053
 | 
|  
 | 
| -#include "content/browser/device_orientation/accelerometer_mac.h"
 | 
| +#include "sudden_motion_sensor_mac.h"
 | 
|  
 | 
|  #include <math.h>
 | 
|  #include <sys/sysctl.h>
 | 
| @@ -56,11 +56,8 @@
 | 
|  #include "base/logging.h"
 | 
|  #include "base/mac/scoped_cftyperef.h"
 | 
|  #include "base/memory/scoped_ptr.h"
 | 
| -#include "content/browser/device_orientation/orientation.h"
 | 
|  
 | 
| -namespace device_orientation {
 | 
| -
 | 
| -struct AccelerometerMac::GenericMacbookSensor {
 | 
| +struct SuddenMotionSensor::GenericMacbookSensor {
 | 
|    // Name of device to be read.
 | 
|    const char* service_name;
 | 
|  
 | 
| @@ -80,7 +77,7 @@ struct AccelerometerMac::GenericMacbookSensor {
 | 
|    unsigned int record_size;
 | 
|  };
 | 
|  
 | 
| -struct AccelerometerMac::AxisData {
 | 
| +struct SuddenMotionSensor::AxisData {
 | 
|    // Location of the first byte representing the axis in the sensor data.
 | 
|    int index;
 | 
|  
 | 
| @@ -89,7 +86,7 @@ struct AccelerometerMac::AxisData {
 | 
|  };
 | 
|  
 | 
|  // Sudden Motion Sensor descriptor.
 | 
| -struct AccelerometerMac::SensorDescriptor {
 | 
| +struct SuddenMotionSensor::SensorDescriptor {
 | 
|    // Prefix of model to be tested.
 | 
|    const char* model_name;
 | 
|  
 | 
| @@ -101,8 +98,7 @@ struct AccelerometerMac::SensorDescriptor {
 | 
|  };
 | 
|  
 | 
|  // Typical sensor parameters in MacBook models.
 | 
| -const AccelerometerMac::GenericMacbookSensor
 | 
| -  AccelerometerMac::kGenericSensor = {
 | 
| +const SuddenMotionSensor::GenericMacbookSensor SuddenMotionSensor::kGenericSensor = {
 | 
|    "SMCMotionSensor", 2,
 | 
|    0, 251,
 | 
|    5, 40
 | 
| @@ -111,8 +107,8 @@ const AccelerometerMac::GenericMacbookSensor
 | 
|  // Supported sensor descriptors. Add entries here to enhance compatibility.
 | 
|  // Tested in order; place more specific entries before more general ones. (All
 | 
|  // non-tested entries from SMSLib have been removed.)
 | 
| -const AccelerometerMac::SensorDescriptor
 | 
| -    AccelerometerMac::kSupportedSensors[] = {
 | 
| +const SuddenMotionSensor::SensorDescriptor
 | 
| +    SuddenMotionSensor::kSupportedSensors[] = {
 | 
|    // Tested by tommyw on a 13" MacBook.
 | 
|    { "MacBook1,1",    NULL, { { 0, true  }, { 2, true  }, { 4, false } } },
 | 
|  
 | 
| @@ -212,31 +208,23 @@ const AccelerometerMac::SensorDescriptor
 | 
|    { "",              NULL, { { 0, true  }, { 2, true  }, { 4, false } } }
 | 
|  };
 | 
|  
 | 
| -// Create a AccelerometerMac object and return NULL if no valid sensor found.
 | 
| -DataFetcher* AccelerometerMac::Create() {
 | 
| -  scoped_ptr<AccelerometerMac> accelerometer(new AccelerometerMac);
 | 
| +// Create a SuddenMotionSensor object and return NULL if no valid sensor found.
 | 
| +SuddenMotionSensor* SuddenMotionSensor::Create() {
 | 
| +  scoped_ptr<SuddenMotionSensor> accelerometer(new SuddenMotionSensor);
 | 
|    return accelerometer->Init() ? accelerometer.release() : NULL;
 | 
|  }
 | 
|  
 | 
| -AccelerometerMac::~AccelerometerMac() {
 | 
| +SuddenMotionSensor::~SuddenMotionSensor() {
 | 
|    IOServiceClose(io_connection_);
 | 
|  }
 | 
|  
 | 
| -AccelerometerMac::AccelerometerMac()
 | 
| +SuddenMotionSensor::SuddenMotionSensor()
 | 
|      : sensor_(NULL),
 | 
|        io_connection_(0) {
 | 
|  }
 | 
|  
 | 
|  //  Retrieve per-axis accelerometer values.
 | 
| -//
 | 
| -//  Axes and angles are defined according to the W3C DeviceOrientation Draft.
 | 
| -//  See here: http://dev.w3.org/geo/api/spec-source-orientation.html
 | 
| -//
 | 
| -//  Note: only beta and gamma angles are provided. Alpha is set to zero.
 | 
| -//
 | 
| -//  Returns false in case of error or non-properly initialized object.
 | 
| -//
 | 
| -bool AccelerometerMac::GetOrientation(Orientation* orientation) {
 | 
| +bool SuddenMotionSensor::ReadSensorValues(float axes[3]) {
 | 
|    DCHECK(sensor_);
 | 
|  
 | 
|    // Reset output record memory buffer.
 | 
| @@ -285,61 +273,16 @@ bool AccelerometerMac::GetOrientation(Orientation* orientation) {
 | 
|        axis_value[i] = -axis_value[i];
 | 
|    }
 | 
|  
 | 
| -  // Transform the accelerometer values to W3C draft angles.
 | 
| -  //
 | 
| -  // Accelerometer values are just dot products of the sensor axes
 | 
| -  // by the gravity vector 'g' with the result for the z axis inverted.
 | 
| -  //
 | 
| -  // To understand this transformation calculate the 3rd row of the z-x-y
 | 
| -  // Euler angles rotation matrix (because of the 'g' vector, only 3rd row
 | 
| -  // affects to the result). Note that z-x-y matrix means R = Ry * Rx * Rz.
 | 
| -  // Then, assume alpha = 0 and you get this:
 | 
| -  //
 | 
| -  // x_acc = sin(gamma)
 | 
| -  // y_acc = - cos(gamma) * sin(beta)
 | 
| -  // z_acc = cos(beta) * cos(gamma)
 | 
| -  //
 | 
| -  // After that the rest is just a bit of trigonometry.
 | 
| -  //
 | 
| -  // Also note that alpha can't be provided but it's assumed to be always zero.
 | 
| -  // This is necessary in order to provide enough information to solve
 | 
| -  // the equations.
 | 
| -  //
 | 
| -  const double kRad2deg = 180.0 / M_PI;
 | 
| -
 | 
| -  orientation->alpha_ = 0.0;
 | 
| -  orientation->beta_  = kRad2deg * atan2(-axis_value[1], axis_value[2]);
 | 
| -  orientation->gamma_ = kRad2deg * asin(axis_value[0]);
 | 
| -  orientation->absolute_ = false;
 | 
| -
 | 
| -  // Make sure that the interval boundaries comply with the specification. At
 | 
| -  // this point, beta is [-180, 180] and gamma is [-90, 90], but the spec has
 | 
| -  // the upper bound open on both.
 | 
| -  if (orientation->beta_ == 180.0) {
 | 
| -    orientation->beta_ = -180.0;  // -180 == 180 (upside-down)
 | 
| -  }
 | 
| -  if (orientation->gamma_ == 90.0) {
 | 
| -    static double just_less_than_90 = nextafter(90, 0);
 | 
| -    orientation->gamma_ = just_less_than_90;
 | 
| -  }
 | 
| -
 | 
| -  // At this point, DCHECKing is paranoia. Never hurts.
 | 
| -  DCHECK_GE(orientation->beta_, -180.0);
 | 
| -  DCHECK_LT(orientation->beta_,  180.0);
 | 
| -  DCHECK_GE(orientation->gamma_, -90.0);
 | 
| -  DCHECK_LT(orientation->gamma_,  90.0);
 | 
| -
 | 
| -  orientation->can_provide_alpha_ = false;
 | 
| -  orientation->can_provide_beta_  = true;
 | 
| -  orientation->can_provide_gamma_ = true;
 | 
| -  orientation->can_provide_absolute_ = false;
 | 
| +  axes[0] = axis_value[0];
 | 
| +  axes[1] = axis_value[1];
 | 
| +  axes[2] = axis_value[2];
 | 
|  
 | 
|    return true;
 | 
|  }
 | 
|  
 | 
|  // Probe the local hardware looking for a supported sensor device
 | 
|  // and initialize an I/O connection to it.
 | 
| -bool AccelerometerMac::Init() {
 | 
| +bool SuddenMotionSensor::Init() {
 | 
|    // Request model name from the kernel.
 | 
|    char local_model[32];  // size from SMSLib
 | 
|    size_t local_model_size = sizeof(local_model);
 | 
| @@ -426,12 +369,12 @@ bool AccelerometerMac::Init() {
 | 
|    output_record_.resize(kGenericSensor.record_size, 0x00);
 | 
|  
 | 
|    // Try to retrieve the current orientation.
 | 
| -  Orientation test_orientation;
 | 
| -  return GetOrientation(&test_orientation);
 | 
| +  float test_axes[3];
 | 
| +  return ReadSensorValues(test_axes);
 | 
|  }
 | 
|  
 | 
|  // Extend the sign of an integer of less than 32 bits to a 32-bit integer.
 | 
| -int AccelerometerMac::ExtendSign(int value, size_t size) {
 | 
| +int SuddenMotionSensor::ExtendSign(int value, size_t size) {
 | 
|    switch (size) {
 | 
|    case 1:
 | 
|      if (value & 0x00000080)
 | 
| @@ -454,5 +397,3 @@ int AccelerometerMac::ExtendSign(int value, size_t size) {
 | 
|  
 | 
|    return value;
 | 
|  }
 | 
| -
 | 
| -}  // namespace device_orientation
 | 
| 
 |