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

Side by Side Diff: Source/core/html/StableState.cpp

Issue 153813002: Support "await a stable state" and "provide a stable state" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: nits 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/StableState.h ('k') | Source/core/html/StableStateTest.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 #include "config.h"
6 #include "core/html/StableState.h"
7
8 #include "wtf/HashSet.h"
9 #include "wtf/MainThread.h"
10
11 namespace WebCore {
12
13 class StableStateAwaiters {
14 public:
15 StableStateAwaiters() : m_currentAwaiter(0) { }
16
17 void add(StableState::Awaiter* awaiter)
18 {
19 ASSERT(!m_currentAwaiter);
20 m_awaiters.add(awaiter);
21 }
22
23 void remove(StableState::Awaiter* awaiter)
24 {
25 ASSERT(!m_currentAwaiter || m_currentAwaiter == awaiter);
26 m_awaiters.remove(awaiter);
27 }
28
29 void didAwaitStableState()
30 {
31 ASSERT(!m_currentAwaiter);
32 while (!m_awaiters.isEmpty()) {
33 m_currentAwaiter = *m_awaiters.begin();
34 m_currentAwaiter->didAwaitStableState();
35 remove(m_currentAwaiter);
36 m_currentAwaiter = 0;
37 }
38 }
39
40 private:
41 HashSet<StableState::Awaiter*> m_awaiters;
42 StableState::Awaiter* m_currentAwaiter;
43 };
44
45 static StableStateAwaiters& stableStateAwaiters()
46 {
47 ASSERT(isMainThread());
48 DEFINE_STATIC_LOCAL(StableStateAwaiters, stableStateAwaiters, ());
49 return stableStateAwaiters;
50 }
51
52 StableState::Awaiter::~Awaiter()
53 {
54 stableStateAwaiters().remove(this);
55 }
56
57 void StableState::await(Awaiter& awaiter)
58 {
59 stableStateAwaiters().add(&awaiter);
60 }
61
62 void StableState::provide()
63 {
64 stableStateAwaiters().didAwaitStableState();
65 }
66
67 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/StableState.h ('k') | Source/core/html/StableStateTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698