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

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
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..a772cb40be17d038f45e809616e747b08e8ce237
--- /dev/null
+++ b/Source/modules/wake_lock/WakeLockController.h
@@ -0,0 +1,67 @@
+// 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);
+
+ virtual void onCreatedWakeLockSuccessful(int);
mlamouri (slow - plz ping) 2014/08/18 12:15:53 nit: specify the interface you are implementing, l
redchenko 2014/08/19 16:42:20 Done.
+ 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<int> m_lockCounter;
+};
+
+} // namespace WebCore
+
+#endif // WakeLockController

Powered by Google App Engine
This is Rietveld 408576698