Respond with QuotaExceededError when IndexedDB has no disk space on open.
[chromium-blink-merge.git] / content / child / power_monitor_broadcast_source.cc
blobb3f72ed485b6e3a1cc7fe486b35db4e626cb118c
1 // Copyright (c) 2013 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.
5 #include "content/child/power_monitor_broadcast_source.h"
7 #include "base/message_loop/message_loop.h"
8 #include "content/common/power_monitor_messages.h"
10 namespace content {
12 class PowerMessageFilter : public IPC::ChannelProxy::MessageFilter {
13 public:
14 PowerMessageFilter(
15 PowerMonitorBroadcastSource* source,
16 scoped_refptr<base::MessageLoopProxy> message_loop)
17 : source_(source),
18 message_loop_(message_loop) {
21 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
22 bool handled = true;
23 IPC_BEGIN_MESSAGE_MAP(PowerMessageFilter, message)
24 IPC_MESSAGE_HANDLER(PowerMonitorMsg_PowerStateChange, OnPowerStateChange)
25 IPC_MESSAGE_HANDLER(PowerMonitorMsg_Suspend, OnSuspend)
26 IPC_MESSAGE_HANDLER(PowerMonitorMsg_Resume, OnResume)
27 IPC_MESSAGE_UNHANDLED(handled = false)
28 IPC_END_MESSAGE_MAP()
29 return handled;
32 void RemoveSource() {
33 source_ = NULL;
36 private:
37 friend class base::RefCounted<PowerMessageFilter>;
39 virtual ~PowerMessageFilter() {};
41 void OnPowerStateChange(bool on_battery_power) {
42 message_loop_->PostTask(FROM_HERE,
43 base::Bind(&PowerMessageFilter::NotifySourcePowerStateChange, this,
44 on_battery_power));
46 void OnSuspend() {
47 message_loop_->PostTask(FROM_HERE,
48 base::Bind(&PowerMessageFilter::NotifySourceSuspend, this));
50 void OnResume() {
51 message_loop_->PostTask(FROM_HERE,
52 base::Bind(&PowerMessageFilter::NotifySourceResume, this));
55 void NotifySourcePowerStateChange(bool on_battery_power) {
56 if (source_)
57 source_->OnPowerStateChange(on_battery_power);
59 void NotifySourceSuspend() {
60 if (source_)
61 source_->OnSuspend();
63 void NotifySourceResume() {
64 if (source_)
65 source_->OnResume();
68 // source_ should only be accessed on the thread associated with
69 // message_loop_.
70 PowerMonitorBroadcastSource* source_;
71 scoped_refptr<base::MessageLoopProxy> message_loop_;
73 DISALLOW_COPY_AND_ASSIGN(PowerMessageFilter);
76 PowerMonitorBroadcastSource::PowerMonitorBroadcastSource()
77 : last_reported_battery_power_state_(false) {
78 message_filter_ = new PowerMessageFilter(this,
79 base::MessageLoopProxy::current());
82 PowerMonitorBroadcastSource::~PowerMonitorBroadcastSource() {
83 message_filter_->RemoveSource();
86 IPC::ChannelProxy::MessageFilter*
87 PowerMonitorBroadcastSource::GetMessageFilter() {
88 return message_filter_.get();
91 bool PowerMonitorBroadcastSource::IsOnBatteryPowerImpl() {
92 return last_reported_battery_power_state_;
95 void PowerMonitorBroadcastSource::OnPowerStateChange(bool on_battery_power) {
96 last_reported_battery_power_state_ = on_battery_power;
97 ProcessPowerEvent(PowerMonitorSource::POWER_STATE_EVENT);
100 void PowerMonitorBroadcastSource::OnSuspend() {
101 ProcessPowerEvent(PowerMonitorSource::SUSPEND_EVENT);
104 void PowerMonitorBroadcastSource::OnResume() {
105 ProcessPowerEvent(PowerMonitorSource::RESUME_EVENT);
108 } // namespace content