Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 private: | |
|
acolwell GONE FROM CHROMIUM
2014/02/18 18:47:43
nit: public declarations should be before private
philipj_slow
2014/02/19 04:10:56
Done.
| |
| 15 HashSet<StableState::Awaiter*> m_awaiters; | |
| 16 StableState::Awaiter* m_currentAwaiter; | |
| 17 | |
| 18 public: | |
| 19 StableStateAwaiters() : m_currentAwaiter(0) { } | |
| 20 | |
| 21 void add(StableState::Awaiter* awaiter) | |
| 22 { | |
| 23 ASSERT(!m_currentAwaiter); | |
| 24 m_awaiters.add(awaiter); | |
| 25 } | |
| 26 | |
| 27 void remove(StableState::Awaiter* awaiter) | |
| 28 { | |
| 29 ASSERT(!m_currentAwaiter || m_currentAwaiter == awaiter); | |
| 30 m_awaiters.remove(awaiter); | |
| 31 } | |
| 32 | |
| 33 void didAwaitStableState() | |
| 34 { | |
| 35 ASSERT(!m_currentAwaiter); | |
| 36 while (!m_awaiters.isEmpty()) { | |
| 37 m_currentAwaiter = *m_awaiters.begin(); | |
| 38 m_currentAwaiter->didAwaitStableState(); | |
| 39 remove(m_currentAwaiter); | |
| 40 m_currentAwaiter = 0; | |
| 41 } | |
| 42 } | |
| 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 | |
| OLD | NEW |