OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "modules/serviceworkers/WaitUntilObserver.h" | 6 #include "modules/serviceworkers/WaitUntilObserver.h" |
7 | 7 |
8 #include "bindings/core/v8/ScriptFunction.h" | 8 #include "bindings/core/v8/ScriptFunction.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptValue.h" | 10 #include "bindings/core/v8/ScriptValue.h" |
11 #include "bindings/core/v8/V8Binding.h" | 11 #include "bindings/core/v8/V8Binding.h" |
12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
13 #include "core/dom/ExecutionContext.h" | 13 #include "core/dom/ExecutionContext.h" |
14 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" | 14 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" |
15 #include "platform/NotImplemented.h" | 15 #include "platform/NotImplemented.h" |
16 #include "public/platform/WebServiceWorkerEventResult.h" | 16 #include "public/platform/WebServiceWorkerEventResult.h" |
17 #include "wtf/Assertions.h" | 17 #include "wtf/Assertions.h" |
18 #include "wtf/RefCounted.h" | 18 #include "wtf/RefCounted.h" |
19 #include "wtf/RefPtr.h" | 19 #include "wtf/RefPtr.h" |
20 #include <v8.h> | 20 #include <v8.h> |
21 | 21 |
22 namespace blink { | 22 namespace blink { |
23 | 23 |
24 namespace { | |
25 | |
26 unsigned& windowInteractionTimeout() | |
27 { | |
28 DEFINE_STATIC_LOCAL(unsigned, windowInteractionTimeout, (ServiceWorkerGlobal Scope::kWindowInteractionTimeout)); | |
29 fprintf(stderr, "%s%d\n", "windowInteractionTimeout = ", windowInteractionTi meout); | |
dominicc (has gone to gerrit)
2015/02/05 18:58:13
Hmm, what happens if unit tests run in parallel?
mlamouri (slow - plz ping)
2015/02/05 20:23:12
Yeah... So I moved to another model. There is now
| |
30 return windowInteractionTimeout; | |
31 } | |
32 | |
33 } // anonymous namespace | |
34 | |
24 class WaitUntilObserver::ThenFunction final : public ScriptFunction { | 35 class WaitUntilObserver::ThenFunction final : public ScriptFunction { |
25 public: | 36 public: |
26 enum ResolveType { | 37 enum ResolveType { |
27 Fulfilled, | 38 Fulfilled, |
28 Rejected, | 39 Rejected, |
29 }; | 40 }; |
30 | 41 |
31 static v8::Handle<v8::Function> createFunction(ScriptState* scriptState, Wai tUntilObserver* observer, ResolveType type) | 42 static v8::Handle<v8::Function> createFunction(ScriptState* scriptState, Wai tUntilObserver* observer, ResolveType type) |
32 { | 43 { |
33 ThenFunction* self = new ThenFunction(scriptState, observer, type); | 44 ThenFunction* self = new ThenFunction(scriptState, observer, type); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 | 101 |
91 if (!executionContext()) | 102 if (!executionContext()) |
92 return; | 103 return; |
93 | 104 |
94 // When handling a notificationclick event, we want to allow one window to | 105 // When handling a notificationclick event, we want to allow one window to |
95 // be focused or opened. Regardless of whether such action happened, | 106 // be focused or opened. Regardless of whether such action happened, |
96 // |consumeWindowInteraction| will be called when all the pending activities | 107 // |consumeWindowInteraction| will be called when all the pending activities |
97 // will be resolved or after a | 108 // will be resolved or after a |
98 if (m_type == NotificationClick) { | 109 if (m_type == NotificationClick) { |
99 executionContext()->allowWindowInteraction(); | 110 executionContext()->allowWindowInteraction(); |
100 m_consumeWindowInteractionTimer.startOneShot(ServiceWorkerGlobalScope::k WindowInteractionTimeout, FROM_HERE); | 111 m_consumeWindowInteractionTimer.startOneShot(windowInteractionTimeout(), FROM_HERE); |
101 } | 112 } |
102 | 113 |
103 incrementPendingActivity(); | 114 incrementPendingActivity(); |
104 ScriptPromise::cast(scriptState, value).then( | 115 ScriptPromise::cast(scriptState, value).then( |
105 ThenFunction::createFunction(scriptState, this, ThenFunction::Fulfilled) , | 116 ThenFunction::createFunction(scriptState, this, ThenFunction::Fulfilled) , |
106 ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected)) ; | 117 ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected)) ; |
107 } | 118 } |
108 | 119 |
109 WaitUntilObserver::WaitUntilObserver(ExecutionContext* context, EventType type, int eventID) | 120 WaitUntilObserver::WaitUntilObserver(ExecutionContext* context, EventType type, int eventID) |
110 : ContextLifecycleObserver(context) | 121 : ContextLifecycleObserver(context) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 break; | 163 break; |
153 case Push: | 164 case Push: |
154 client->didHandlePushEvent(m_eventID, result); | 165 client->didHandlePushEvent(m_eventID, result); |
155 break; | 166 break; |
156 } | 167 } |
157 observeContext(0); | 168 observeContext(0); |
158 } | 169 } |
159 | 170 |
160 void WaitUntilObserver::consumeWindowInteraction(Timer<WaitUntilObserver>*) | 171 void WaitUntilObserver::consumeWindowInteraction(Timer<WaitUntilObserver>*) |
161 { | 172 { |
173 fprintf(stderr, "%s\n", "consumeWindowInteraction"); | |
dominicc (has gone to gerrit)
2015/02/05 18:58:13
Remove the logging.
mlamouri (slow - plz ping)
2015/02/05 20:23:12
Removed in patch #2.
| |
162 if (!executionContext()) | 174 if (!executionContext()) |
163 return; | 175 return; |
164 executionContext()->consumeWindowInteraction(); | 176 executionContext()->consumeWindowInteraction(); |
165 } | 177 } |
166 | 178 |
179 // static | |
180 void WaitUntilObserver::overrideWindowInteractionTimeoutForTest(unsigned timeout ) | |
181 { | |
182 windowInteractionTimeout() = timeout; | |
183 } | |
184 | |
167 void WaitUntilObserver::trace(Visitor* visitor) | 185 void WaitUntilObserver::trace(Visitor* visitor) |
168 { | 186 { |
169 ContextLifecycleObserver::trace(visitor); | 187 ContextLifecycleObserver::trace(visitor); |
170 } | 188 } |
171 | 189 |
172 } // namespace blink | 190 } // namespace blink |
OLD | NEW |