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 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 |
OLD | NEW |