root/content/renderer/device_orientation/device_motion_event_pump.cc

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. listener_
  2. listener_
  3. SetListener
  4. OnControlMessageReceived
  5. FireEvent
  6. InitializeReader
  7. SendStartMessage
  8. SendStopMessage

// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "device_motion_event_pump.h"

#include "content/common/device_orientation/device_motion_messages.h"
#include "content/public/renderer/render_thread.h"
#include "third_party/WebKit/public/platform/WebDeviceMotionListener.h"

namespace content {

DeviceMotionEventPump::DeviceMotionEventPump()
    : DeviceSensorEventPump(), listener_(0) {
}

DeviceMotionEventPump::DeviceMotionEventPump(int pump_delay_millis)
    : DeviceSensorEventPump(pump_delay_millis), listener_(0) {
}

DeviceMotionEventPump::~DeviceMotionEventPump() {
}

bool DeviceMotionEventPump::SetListener(
    blink::WebDeviceMotionListener* listener) {
  listener_ = listener;
  return listener_ ? RequestStart() : Stop();
}

bool DeviceMotionEventPump::OnControlMessageReceived(
    const IPC::Message& message) {
  bool handled = true;
  IPC_BEGIN_MESSAGE_MAP(DeviceMotionEventPump, message)
    IPC_MESSAGE_HANDLER(DeviceMotionMsg_DidStartPolling, OnDidStart)
    IPC_MESSAGE_UNHANDLED(handled = false)
  IPC_END_MESSAGE_MAP()
  return handled;
}

void DeviceMotionEventPump::FireEvent() {
  DCHECK(listener_);
  blink::WebDeviceMotionData data;
  if (reader_->GetLatestData(&data) && data.allAvailableSensorsAreActive)
    listener_->didChangeDeviceMotion(data);
}

bool DeviceMotionEventPump::InitializeReader(base::SharedMemoryHandle handle) {
  if (!reader_)
    reader_.reset(new DeviceMotionSharedMemoryReader());
  return reader_->Initialize(handle);
}

bool DeviceMotionEventPump::SendStartMessage() {
  return RenderThread::Get()->Send(new DeviceMotionHostMsg_StartPolling());
}


bool DeviceMotionEventPump::SendStopMessage() {
  return RenderThread::Get()->Send(new DeviceMotionHostMsg_StopPolling());
}

}  // namespace content

/* [<][>][^][v][top][bottom][index][help] */