OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2013 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2013 Google Inc. All Rights Reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 continue; | 55 continue; |
56 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observer); | 56 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observer); |
57 #if DCHECK_IS_ON() | 57 #if DCHECK_IS_ON() |
58 DCHECK_EQ(activeDOMObject->getExecutionContext(), context()); | 58 DCHECK_EQ(activeDOMObject->getExecutionContext(), context()); |
59 DCHECK(activeDOMObject->suspendIfNeededCalled()); | 59 DCHECK(activeDOMObject->suspendIfNeededCalled()); |
60 #endif | 60 #endif |
61 activeDOMObject->suspend(); | 61 activeDOMObject->suspend(); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() { | |
66 // Observers may be removed, but handled after iteration has completed. | |
67 AutoReset<IterationState> scope(&m_iterationState, AllowPendingRemoval); | |
68 ObserverSet observers; | |
69 m_observers.swap(observers); | |
70 for (ContextLifecycleObserver* observer : observers) { | |
71 if (observer->observerType() != | |
72 ContextLifecycleObserver::ActiveDOMObjectType) | |
73 continue; | |
74 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observer); | |
75 #if DCHECK_IS_ON() | |
76 DCHECK_EQ(activeDOMObject->getExecutionContext(), context()); | |
77 DCHECK(activeDOMObject->suspendIfNeededCalled()); | |
78 #endif | |
79 activeDOMObject->stop(); | |
80 } | |
81 removePending(observers); | |
82 } | |
83 | |
84 unsigned ContextLifecycleNotifier::activeDOMObjectCount() const { | 65 unsigned ContextLifecycleNotifier::activeDOMObjectCount() const { |
85 DCHECK(!isIteratingOverObservers()); | 66 DCHECK(!isIteratingOverObservers()); |
86 unsigned activeDOMObjects = 0; | 67 unsigned activeDOMObjects = 0; |
87 for (ContextLifecycleObserver* observer : m_observers) { | 68 for (ContextLifecycleObserver* observer : m_observers) { |
88 if (observer->observerType() != | 69 if (observer->observerType() != |
89 ContextLifecycleObserver::ActiveDOMObjectType) | 70 ContextLifecycleObserver::ActiveDOMObjectType) |
90 continue; | 71 continue; |
91 activeDOMObjects++; | 72 activeDOMObjects++; |
92 } | 73 } |
93 return activeDOMObjects; | 74 return activeDOMObjects; |
94 } | 75 } |
95 | 76 |
96 #if DCHECK_IS_ON() | 77 #if DCHECK_IS_ON() |
97 bool ContextLifecycleNotifier::contains(ActiveDOMObject* object) const { | 78 bool ContextLifecycleNotifier::contains(ActiveDOMObject* object) const { |
98 DCHECK(!isIteratingOverObservers()); | 79 DCHECK(!isIteratingOverObservers()); |
99 for (ContextLifecycleObserver* observer : m_observers) { | 80 for (ContextLifecycleObserver* observer : m_observers) { |
100 if (observer->observerType() != | 81 if (observer->observerType() != |
101 ContextLifecycleObserver::ActiveDOMObjectType) | 82 ContextLifecycleObserver::ActiveDOMObjectType) |
102 continue; | 83 continue; |
103 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observer); | 84 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observer); |
104 if (activeDOMObject == object) | 85 if (activeDOMObject == object) |
105 return true; | 86 return true; |
106 } | 87 } |
107 return false; | 88 return false; |
108 } | 89 } |
109 #endif | 90 #endif |
110 | 91 |
111 } // namespace blink | 92 } // namespace blink |
OLD | NEW |