Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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/memory/scoped_ptr.h" | |
| 8 #include "content/browser/device_orientation/device_data.h" | |
| 9 #include "content/browser/device_orientation/orientation.h" | |
| 10 | |
| 11 namespace device_orientation { | |
| 12 | |
| 13 ObserverDelegate::ObserverDelegate(DeviceData::Type device_data_type, | |
| 14 Provider* provider, int render_view_id, | |
| 15 IPC::Sender* sender) | |
| 16 : Observer(device_data_type), | |
| 17 provider_(provider), | |
| 18 render_view_id_(render_view_id), | |
| 19 sender_(sender) { | |
| 20 provider_->AddObserver(this); | |
| 21 } | |
| 22 | |
| 23 ObserverDelegate::~ObserverDelegate() { | |
| 24 provider_->RemoveObserver(this); | |
| 25 } | |
| 26 | |
| 27 void ObserverDelegate::OnDeviceDataUpdate( | |
| 28 const DeviceData* device_data, DeviceData::Type device_data_type) { | |
| 29 IPC::Message* message = NULL; | |
| 30 | |
| 31 if (device_data) | |
| 32 message = device_data->CreateIPCMessage(render_view_id_); | |
| 33 else { | |
| 34 scoped_ptr<DeviceData> empty_device_data(EmptyDeviceData(device_data_type)); | |
| 35 if (empty_device_data.get()) | |
| 36 message = empty_device_data->CreateIPCMessage(render_view_id_); | |
| 37 } | |
| 38 | |
| 39 if (message) | |
| 40 sender_->Send(message); | |
| 41 } | |
| 42 | |
| 43 DeviceData* ObserverDelegate::EmptyDeviceData(DeviceData::Type type) { | |
|
hans
2012/07/18 17:21:02
maybe we should just DCHECK that type is kTypeOrie
aousterh
2012/07/20 11:18:52
Done.
| |
| 44 if (type == DeviceData::kTypeOrientation) | |
| 45 return new Orientation(); | |
| 46 return NULL; | |
| 47 } | |
| 48 | |
| 49 } // namespace device_orientation | |
| OLD | NEW |