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

Unified Diff: Source/modules/serviceworkers/RespondWithObserver.h

Issue 180843003: Start to implement FetchEvent for ServiceWorker (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: patch for landing 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/serviceworkers/FetchEvent.idl ('k') | Source/modules/serviceworkers/RespondWithObserver.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/serviceworkers/RespondWithObserver.h
diff --git a/Source/modules/serviceworkers/RespondWithObserver.h b/Source/modules/serviceworkers/RespondWithObserver.h
new file mode 100644
index 0000000000000000000000000000000000000000..7a3d22cd1b0c4bc1d1e40a49c13972662c17b375
--- /dev/null
+++ b/Source/modules/serviceworkers/RespondWithObserver.h
@@ -0,0 +1,53 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef RespondWithObserver_h
+#define RespondWithObserver_h
+
+#include "core/dom/ContextLifecycleObserver.h"
+#include "wtf/Forward.h"
+#include "wtf/RefCounted.h"
+
+namespace WebCore {
+
+class ExecutionContext;
+class Response;
+class ScriptValue;
+
+// This class observes the service worker's handling of a FetchEvent and
+// notifies the client.
+class RespondWithObserver FINAL : public ContextLifecycleObserver, public RefCounted<RespondWithObserver> {
+public:
+ static PassRefPtr<RespondWithObserver> create(ExecutionContext*, int eventID);
+ ~RespondWithObserver();
+
+ virtual void contextDestroyed() OVERRIDE;
+
+ void didDispatchEvent();
+
+ // Observes the promise and delays calling didHandleFetchEvent() until the
+ // given promise is resolved or rejected.
+ void respondWith(const ScriptValue&);
+
+ void responseWasRejected();
+ void responseWasFulfilled(const ScriptValue&);
+
+private:
+ class ThenFunction;
+
+ RespondWithObserver(ExecutionContext*, int eventID);
+
+ // Sends a response back to the client. The null response means to fallback
+ // to native.
+ void sendResponse(PassRefPtr<Response>);
+
+ int m_eventID;
+
+ enum State { Initial, Pending, Done };
+ State m_state;
+};
+
+} // namespace WebCore
+
+#endif // RespondWithObserver_h
« no previous file with comments | « Source/modules/serviceworkers/FetchEvent.idl ('k') | Source/modules/serviceworkers/RespondWithObserver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698