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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef WakeLockController_h
6 #define WakeLockController_h
7
8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "core/page/Page.h"
10 #include "core/page/PageLifecycleObserver.h"
11 #include "public/platform/WebWakeLockRequestCallback.h"
12 #include "public/platform/WebWakeLockType.h"
13 #include "wtf/OwnPtr.h"
14 #include "wtf/Vector.h"
15
16 namespace blink {
17
18 class ScriptState;
19 class WakeLockPromiseResolver;
20 class WebWakeLockClient;
21 typedef WTF::OwnPtr<WakeLockPromiseResolver> WakeLockPromiseResolverOwnPtr;
22
23 class WakeLockController FINAL
24 : public NoBaseWillBeGarbageCollectedFinalized<WakeLockController>
25 , public WillBeHeapSupplement<Page>
26 , public PageLifecycleObserver
27 , public WebWakeLockRequestCallback {
28 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WakeLockController);
29 WTF_MAKE_NONCOPYABLE(WakeLockController);
30
31 public:
32 virtual ~WakeLockController();
33
34 static PassOwnPtrWillBeRawPtr<WakeLockController> create(Page&, WebWakeLockC lient*);
35
36 ScriptPromise requestWakeLock(ScriptState*, WebWakeLockType);
37 ScriptPromise requestWakeUnlock(ScriptState*, WebWakeLockType);
38 bool isHeld(WebWakeLockType);
39
40 // Implements WebWakeLockRequestCallback.
41 virtual void onCreatedWakeLockSuccessful(int);
42 virtual void onCreatedWakeLockFailed(int);
43 virtual void onUnlockedWakeLockSuccessful(int);
44 virtual void onUnlockedWakeLockFailed(int);
45
46 WebWakeLockClient* client() { return m_client; }
47 void resetClient();
48
49 static const char* supplementName();
50 static WakeLockController* from(Page*);
51 static void provideWakeLockTo(Page&, WebWakeLockClient*);
52 // Inherited from PageLifecycleObserver.
53 virtual void trace(Visitor*) OVERRIDE;
54 virtual void willBeDestroyed() OVERRIDE;
55
56 private:
57 WakeLockController(Page&, WebWakeLockClient*);
58 ScriptPromise requestLockOrUnlock(ScriptState*, WebWakeLockType, bool);
59 WebWakeLockType resolveOrRejectById(int id, bool successful);
60
61 WebWakeLockClient* m_client;
62 Vector<WakeLockPromiseResolverOwnPtr> m_resolvers;
63 Vector<bool> m_isLocked;
64 };
65
66 } // namespace blink
67
68 #endif // WakeLockController
OLDNEW
« 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