Home | History | Annotate | Download | only in device_orientation
      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
      3 // found in the LICENSE file.
      4 
      5 #include "content/browser/device_orientation/observer_delegate.h"
      6 
      7 #include "base/logging.h"
      8 #include "content/browser/device_orientation/device_data.h"
      9 #include "content/browser/device_orientation/orientation.h"
     10 #include "ipc/ipc_sender.h"
     11 
     12 namespace content {
     13 
     14 ObserverDelegate::ObserverDelegate(DeviceData::Type device_data_type,
     15                                    Provider* provider, int render_view_id,
     16                                    IPC::Sender* sender)
     17     : Observer(device_data_type),
     18       provider_(provider),
     19       render_view_id_(render_view_id),
     20       sender_(sender) {
     21   provider_->AddObserver(this);
     22 }
     23 
     24 ObserverDelegate::~ObserverDelegate() {
     25   provider_->RemoveObserver(this);
     26 }
     27 
     28 void ObserverDelegate::OnDeviceDataUpdate(
     29     const DeviceData* device_data, DeviceData::Type device_data_type) {
     30   scoped_refptr<const DeviceData> new_device_data(device_data);
     31   if (!new_device_data.get())
     32     new_device_data = EmptyDeviceData(device_data_type);
     33 
     34   sender_->Send(new_device_data->CreateIPCMessage(render_view_id_));
     35 }
     36 
     37 DeviceData* ObserverDelegate::EmptyDeviceData(DeviceData::Type type) {
     38   switch (type) {
     39     case DeviceData::kTypeOrientation:
     40       return new Orientation();
     41     case DeviceData::kTypeMotion:
     42     case DeviceData::kTypeTest:
     43       NOTREACHED();
     44   }
     45   NOTREACHED();
     46   return NULL;
     47 }
     48 
     49 }  // namespace content
     50