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

Unified Diff: Source/modules/wake_lock/WakeLockController.h

Issue 399313003: Initial implementation of API WakeLock. Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Implementation of WakeLock API on JavaScript side. Created 6 years, 4 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
« no previous file with comments | « Source/modules/wake_lock/WakeLock.idl ('k') | Source/modules/wake_lock/WakeLockController.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/wake_lock/WakeLockController.h
diff --git a/Source/modules/wake_lock/WakeLockController.h b/Source/modules/wake_lock/WakeLockController.h
new file mode 100644
index 0000000000000000000000000000000000000000..ae102c0ef71ca1dfd2e17203c61484264f85ea94
--- /dev/null
+++ b/Source/modules/wake_lock/WakeLockController.h
@@ -0,0 +1,68 @@
+// Copyright 2014 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.
+
+#ifndef WakeLockController_h
+#define WakeLockController_h
+
+#include "bindings/core/v8/ScriptPromise.h"
+#include "core/page/Page.h"
+#include "core/page/PageLifecycleObserver.h"
+#include "public/platform/WebWakeLockRequestCallback.h"
+#include "public/platform/WebWakeLockType.h"
+#include "wtf/OwnPtr.h"
+#include "wtf/Vector.h"
+
+namespace blink {
+
+class ScriptState;
+class WakeLockPromiseResolver;
+class WebWakeLockClient;
+typedef WTF::OwnPtr<WakeLockPromiseResolver> WakeLockPromiseResolverOwnPtr;
+
+class WakeLockController FINAL
+ : public NoBaseWillBeGarbageCollectedFinalized<WakeLockController>
+ , public WillBeHeapSupplement<Page>
+ , public PageLifecycleObserver
+ , public WebWakeLockRequestCallback {
+ WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WakeLockController);
+ WTF_MAKE_NONCOPYABLE(WakeLockController);
+
+public:
+ virtual ~WakeLockController();
+
+ static PassOwnPtrWillBeRawPtr<WakeLockController> create(Page&, WebWakeLockClient*);
+
+ ScriptPromise requestWakeLock(ScriptState*, WebWakeLockType);
+ ScriptPromise requestWakeUnlock(ScriptState*, WebWakeLockType);
+ bool isHeld(WebWakeLockType);
+
+ // Implements WebWakeLockRequestCallback.
+ virtual void onCreatedWakeLockSuccessful(int);
+ virtual void onCreatedWakeLockFailed(int);
+ virtual void onUnlockedWakeLockSuccessful(int);
+ virtual void onUnlockedWakeLockFailed(int);
+
+ WebWakeLockClient* client() { return m_client; }
+ void resetClient();
+
+ static const char* supplementName();
+ static WakeLockController* from(Page*);
+ static void provideWakeLockTo(Page&, WebWakeLockClient*);
+ // Inherited from PageLifecycleObserver.
+ virtual void trace(Visitor*) OVERRIDE;
+ virtual void willBeDestroyed() OVERRIDE;
+
+private:
+ WakeLockController(Page&, WebWakeLockClient*);
+ ScriptPromise requestLockOrUnlock(ScriptState*, WebWakeLockType, bool);
+ WebWakeLockType resolveOrRejectById(int id, bool successful);
+
+ WebWakeLockClient* m_client;
+ Vector<WakeLockPromiseResolverOwnPtr> m_resolvers;
+ Vector<bool> m_isLocked;
+};
+
+} // namespace blink
+
+#endif // WakeLockController
« no previous file with comments | « Source/modules/wake_lock/WakeLock.idl ('k') | Source/modules/wake_lock/WakeLockController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698