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

Unified Diff: third_party/WebKit/Source/modules/wake_lock/ScreenWakeLock.cpp

Issue 1883493003: [OnionSoup] Moving WakeLock Service to Blink (2/2): removing WebWakeLockClient and WakeLockDispatch… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: esprehn@ comments Created 4 years, 8 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: third_party/WebKit/Source/modules/wake_lock/ScreenWakeLock.cpp
diff --git a/third_party/WebKit/Source/modules/wake_lock/ScreenWakeLock.cpp b/third_party/WebKit/Source/modules/wake_lock/ScreenWakeLock.cpp
index 331e672b50e8610b5a72b99e986333bd2ca7b1de..2c42f900b6998fe51e44063f46bd28528e8e44ab 100644
--- a/third_party/WebKit/Source/modules/wake_lock/ScreenWakeLock.cpp
+++ b/third_party/WebKit/Source/modules/wake_lock/ScreenWakeLock.cpp
@@ -8,7 +8,7 @@
#include "core/frame/Screen.h"
#include "core/page/PageVisibilityState.h"
#include "platform/RuntimeEnabledFeatures.h"
-#include "public/platform/modules/wake_lock/WebWakeLockClient.h"
+#include "public/platform/ServiceRegistry.h"
namespace blink {
@@ -26,16 +26,8 @@ bool ScreenWakeLock::keepAwake(Screen& screen)
void ScreenWakeLock::setKeepAwake(Screen& screen, bool keepAwake)
{
ScreenWakeLock* screenWakeLock = fromScreen(screen);
- if (!screenWakeLock)
- return;
-
- screenWakeLock->setKeepAwake(keepAwake);
-}
-
-void ScreenWakeLock::setKeepAwake(bool keepAwake)
-{
- m_keepAwake = keepAwake;
- notifyClient();
+ if (screenWakeLock)
+ screenWakeLock->setKeepAwake(keepAwake);
}
// static
@@ -51,31 +43,30 @@ ScreenWakeLock* ScreenWakeLock::from(LocalFrame* frame)
}
// static
-void ScreenWakeLock::provideTo(LocalFrame& frame, WebWakeLockClient* client)
+void ScreenWakeLock::provideTo(LocalFrame& frame, ServiceRegistry* registry)
{
- ASSERT(RuntimeEnabledFeatures::wakeLockEnabled());
+ DCHECK(RuntimeEnabledFeatures::wakeLockEnabled());
Supplement<LocalFrame>::provideTo(
frame,
ScreenWakeLock::supplementName(),
- new ScreenWakeLock(frame, client));
+ registry ? new ScreenWakeLock(frame, registry) : nullptr);
}
void ScreenWakeLock::pageVisibilityChanged()
{
- notifyClient();
+ notifyService();
}
void ScreenWakeLock::didCommitLoad(LocalFrame* committedFrame)
{
// Reset wake lock flag for this frame if it is the one being navigated.
- if (committedFrame == frame()) {
+ if (committedFrame == frame())
setKeepAwake(false);
- }
}
void ScreenWakeLock::willDetachFrameHost()
{
- m_client = nullptr;
+ setKeepAwake(false);
}
DEFINE_TRACE(ScreenWakeLock)
@@ -85,12 +76,25 @@ DEFINE_TRACE(ScreenWakeLock)
LocalFrameLifecycleObserver::trace(visitor);
}
-ScreenWakeLock::ScreenWakeLock(LocalFrame& frame, WebWakeLockClient* client)
+ScreenWakeLock::ScreenWakeLock(LocalFrame& frame, ServiceRegistry* registry)
: PageLifecycleObserver(frame.page())
, LocalFrameLifecycleObserver(&frame)
- , m_client(client)
, m_keepAwake(false)
{
+ DCHECK(!m_service.is_bound());
+ DCHECK(registry);
+ registry->connectToRemoteService(mojo::GetProxy(&m_service));
+}
+
+bool ScreenWakeLock::keepAwake() const
+{
+ return m_keepAwake;
+}
+
+void ScreenWakeLock::setKeepAwake(bool keepAwake)
+{
+ m_keepAwake = keepAwake;
+ notifyService();
}
// static
@@ -99,12 +103,15 @@ ScreenWakeLock* ScreenWakeLock::fromScreen(Screen& screen)
return screen.frame() ? ScreenWakeLock::from(screen.frame()) : nullptr;
}
-void ScreenWakeLock::notifyClient()
+void ScreenWakeLock::notifyService()
{
- if (!m_client)
+ if (!m_service)
return;
- m_client->requestKeepScreenAwake(m_keepAwake && page() && page()->isPageVisible());
+ if (m_keepAwake && frame()->page() && frame()->page()->isPageVisible())
+ m_service->RequestWakeLock();
+ else
+ m_service->CancelWakeLock();
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/wake_lock/ScreenWakeLock.h ('k') | third_party/WebKit/Source/platform/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698