Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: base/power_monitor/power_monitor_ios.mm

Issue 10959020: SystemMonitor refactoring: move power state monitor into a separate class called PowerMonitor (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Use PowerMonitor instead of SystemMonitor in XXXMain function Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/system_monitor/system_monitor.h" 5 #include "base/power_monitor/power_monitor.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 namespace base { 9 namespace base {
10 10
11 void SystemMonitor::PlatformInit() { 11 void PowerMonitor::PlatformInit() {
12 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; 12 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
13 id foreground = 13 id foreground =
14 [nc addObserverForName:UIApplicationWillEnterForegroundNotification 14 [nc addObserverForName:UIApplicationWillEnterForegroundNotification
15 object:nil 15 object:nil
16 queue:nil 16 queue:nil
17 usingBlock:^(NSNotification* notification) { 17 usingBlock:^(NSNotification* notification) {
18 ProcessPowerMessage(RESUME_EVENT); 18 ProcessPowerEvent(RESUME_EVENT);
19 }]; 19 }];
20 id background = 20 id background =
21 [nc addObserverForName:UIApplicationDidEnterBackgroundNotification 21 [nc addObserverForName:UIApplicationDidEnterBackgroundNotification
22 object:nil 22 object:nil
23 queue:nil 23 queue:nil
24 usingBlock:^(NSNotification* notification) { 24 usingBlock:^(NSNotification* notification) {
25 ProcessPowerMessage(SUSPEND_EVENT); 25 ProcessPowerEvent(SUSPEND_EVENT);
26 }]; 26 }];
27 notification_observers_.push_back(foreground); 27 notification_observers_.push_back(foreground);
28 notification_observers_.push_back(background); 28 notification_observers_.push_back(background);
29 } 29 }
30 30
31 void SystemMonitor::PlatformDestroy() { 31 void PowerMonitor::PlatformDestroy() {
32 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; 32 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
33 for (std::vector<id>::iterator it = notification_observers_.begin(); 33 for (std::vector<id>::iterator it = notification_observers_.begin();
34 it != notification_observers_.end(); ++it) { 34 it != notification_observers_.end(); ++it) {
35 [nc removeObserver:*it]; 35 [nc removeObserver:*it];
36 } 36 }
37 notification_observers_.clear(); 37 notification_observers_.clear();
38 } 38 }
39 39
40 } // namespace base 40 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698