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

Unified Diff: Source/modules/battery/BatteryManager.cpp

Issue 182613002: Add support to Battery Status API in blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: Source/modules/battery/BatteryManager.cpp
diff --git a/Source/modules/battery/BatteryManager.cpp b/Source/modules/battery/BatteryManager.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9515a8f99a53e0ce8f7bd41d6ce399c5d22f6c0f
--- /dev/null
+++ b/Source/modules/battery/BatteryManager.cpp
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics
+ * Copyright (C) 2014 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "modules/battery/BatteryManager.h"
+
+#include "core/dom/Document.h"
+#include "core/events/Event.h"
+#include "core/frame/Frame.h"
+#include "core/frame/Navigator.h"
+#include "modules/battery/BatteryStatus.h"
+#include <limits>
+
+namespace WebCore {
+
+PassRefPtr<BatteryManager> BatteryManager::create(Navigator* navigator)
+{
+ RefPtr<BatteryManager> batteryManager(adoptRef(new BatteryManager(navigator)));
+ batteryManager->suspendIfNeeded();
+ return batteryManager.release();
+}
+
+PassRefPtr<BatteryManager> BatteryManager::create(Frame* frame)
+{
+ RefPtr<BatteryManager> batteryManager(adoptRef(new BatteryManager(frame)));
+ batteryManager->suspendIfNeeded();
+ return batteryManager.release();
+}
+
+BatteryManager::~BatteryManager()
+{
+}
+
+BatteryManager::BatteryManager(Navigator* navigator)
+ : ActiveDOMObject(navigator->frame()->document())
+ , m_batteryStatus(nullptr)
+{
+}
+
+BatteryManager::BatteryManager(Frame* frame)
+ : ActiveDOMObject(frame->document())
+ , m_batteryStatus(nullptr)
+{
+}
+
+bool BatteryManager::charging()
+{
+ return m_batteryStatus ? m_batteryStatus->charging() : true;
+}
+
+double BatteryManager::chargingTime()
+{
+ if (!m_batteryStatus || !m_batteryStatus->charging())
+ return std::numeric_limits<double>::infinity();
+
+ return m_batteryStatus->chargingTime();
+}
+
+double BatteryManager::dischargingTime()
+{
+ if (!m_batteryStatus || m_batteryStatus->charging())
+ return std::numeric_limits<double>::infinity();
+
+ return m_batteryStatus->dischargingTime();
+}
+
+double BatteryManager::level()
+{
+ return m_batteryStatus ? m_batteryStatus->level() : 1;
+}
+
+void BatteryManager::didChangeBatteryStatus(PassRefPtr<Event> event, PassRefPtr<BatteryStatus> batteryStatus)
+{
+ m_batteryStatus = batteryStatus;
+ dispatchEvent(event);
+}
+
+void BatteryManager::suspend()
+{
+}
+
+void BatteryManager::resume()
+{
+}
+
+void BatteryManager::stop()
+{
+}
abarth-chromium 2014/02/27 05:42:09 Given that you don't implement these functions, th
+
+} // namespace WebCore
+

Powered by Google App Engine
This is Rietveld 408576698