1 // Copyright 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 "base/power_monitor/power_monitor_device_source.h"
7 #import <UIKit/UIKit.h>
11 void PowerMonitorDeviceSource::PlatformInit() {
12 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
14 [nc addObserverForName:UIApplicationWillEnterForegroundNotification
17 usingBlock:^(NSNotification* notification) {
18 ProcessPowerEvent(RESUME_EVENT);
21 [nc addObserverForName:UIApplicationDidEnterBackgroundNotification
24 usingBlock:^(NSNotification* notification) {
25 ProcessPowerEvent(SUSPEND_EVENT);
27 notification_observers_.push_back(foreground);
28 notification_observers_.push_back(background);
31 void PowerMonitorDeviceSource::PlatformDestroy() {
32 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
33 for (std::vector<id>::iterator it = notification_observers_.begin();
34 it != notification_observers_.end(); ++it) {
35 [nc removeObserver:*it];
37 notification_observers_.clear();