summaryrefslogtreecommitdiffstats
path: root/base/system_monitor
diff options
context:
space:
mode:
authorrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-10 19:18:21 +0000
committerrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-10 19:18:21 +0000
commit250ce03c6ebb8a32eaaab82b63d90a51b1d4f05d (patch)
treed8bafc01ed524f91c174eb71212682c2fde2aeca /base/system_monitor
parent648e0a52e9689060640f9325575439e5914eee1d (diff)
downloadchromium_src-250ce03c6ebb8a32eaaab82b63d90a51b1d4f05d.zip
chromium_src-250ce03c6ebb8a32eaaab82b63d90a51b1d4f05d.tar.gz
chromium_src-250ce03c6ebb8a32eaaab82b63d90a51b1d4f05d.tar.bz2
Adds an iOS implementation of base::SystemMonitor.
BUG=None TEST=None Review URL: https://chromiumcodereview.appspot.com/10703120 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@145929 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/system_monitor')
-rw-r--r--base/system_monitor/system_monitor.h19
-rw-r--r--base/system_monitor/system_monitor_ios.mm40
2 files changed, 56 insertions, 3 deletions
diff --git a/base/system_monitor/system_monitor.h b/base/system_monitor/system_monitor.h
index d960fa2..a070755 100644
--- a/base/system_monitor/system_monitor.h
+++ b/base/system_monitor/system_monitor.h
@@ -27,10 +27,14 @@
#include "base/timer.h"
#endif // defined(ENABLE_BATTERY_MONITORING)
-#if defined(OS_MACOSX)
+#if defined(OS_MACOSX) && !defined(OS_IOS)
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <IOKit/IOMessage.h>
-#endif // OS_MACOSX
+#endif // OS_MACOSX && !OS_IOS
+
+#if defined(OS_IOS)
+#include <objc/runtime.h>
+#endif // OS_IOS
class FilePath;
@@ -65,8 +69,12 @@ class BASE_EXPORT SystemMonitor {
//
// This function must be called before instantiating an instance of the class
// and before the Sandbox is initialized.
+#if !defined(OS_IOS)
static void AllocateSystemIOPorts();
-#endif
+#else
+ static void AllocateSystemIOPorts() {}
+#endif // OS_IOS
+#endif // OS_MACOSX
//
// Power-related APIs
@@ -189,6 +197,11 @@ class BASE_EXPORT SystemMonitor {
base::OneShotTimer<SystemMonitor> delayed_battery_check_;
#endif
+#if defined(OS_IOS)
+ // Holds pointers to system event notification observers.
+ std::vector<id> notification_observers_;
+#endif
+
MediaDeviceMap media_device_map_;
DISALLOW_COPY_AND_ASSIGN(SystemMonitor);
diff --git a/base/system_monitor/system_monitor_ios.mm b/base/system_monitor/system_monitor_ios.mm
new file mode 100644
index 0000000..f3251b6
--- /dev/null
+++ b/base/system_monitor/system_monitor_ios.mm
@@ -0,0 +1,40 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/system_monitor/system_monitor.h"
+
+#import <UIKit/UIKit.h>
+
+namespace base {
+
+void SystemMonitor::PlatformInit() {
+ NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
+ id foreground =
+ [nc addObserverForName:UIApplicationWillEnterForegroundNotification
+ object:nil
+ queue:nil
+ usingBlock:^(NSNotification* notification) {
+ ProcessPowerMessage(RESUME_EVENT);
+ }];
+ id background =
+ [nc addObserverForName:UIApplicationDidEnterBackgroundNotification
+ object:nil
+ queue:nil
+ usingBlock:^(NSNotification* notification) {
+ ProcessPowerMessage(SUSPEND_EVENT);
+ }];
+ notification_observers_.push_back(foreground);
+ notification_observers_.push_back(background);
+}
+
+void SystemMonitor::PlatformDestroy() {
+ NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
+ for (std::vector<id>::iterator it = notification_observers_.begin();
+ it != notification_observers_.end(); ++it) {
+ [nc removeObserver:*it];
+ }
+ notification_observers_.clear();
+}
+
+} // namespace base