[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / base / system_monitor / system_monitor_ios.mm
blobf3251b60f143c0b119fdcce7323dedab2e60be5f
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.
5 #include "base/system_monitor/system_monitor.h"
7 #import <UIKit/UIKit.h>
9 namespace base {
11 void SystemMonitor::PlatformInit() {
12   NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
13   id foreground =
14       [nc addObserverForName:UIApplicationWillEnterForegroundNotification
15                       object:nil
16                        queue:nil
17                   usingBlock:^(NSNotification* notification) {
18                       ProcessPowerMessage(RESUME_EVENT);
19                   }];
20   id background =
21       [nc addObserverForName:UIApplicationDidEnterBackgroundNotification
22                       object:nil
23                        queue:nil
24                   usingBlock:^(NSNotification* notification) {
25                       ProcessPowerMessage(SUSPEND_EVENT);
26                   }];
27   notification_observers_.push_back(foreground);
28   notification_observers_.push_back(background);
31 void SystemMonitor::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];
36   }
37   notification_observers_.clear();
40 }  // namespace base