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

Side by Side Diff: content/browser/service_worker/service_worker_controllee_url_loader_factory.h

Issue 2843043002: network service: Create URLLoader for service worker navigation case
Patch Set: network fallback in simple cases Created 3 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_URL_LOADER_FACT ORY_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_URL_LOADER_FACT ORY_H_
7
8 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h"
9 #include "content/browser/service_worker/service_worker_url_loader_factory.h"
10 #include "content/browser/service_worker/service_worker_version.h"
11 #include "content/common/service_worker/service_worker_types.h"
12 #include "storage/browser/blob/blob_reader.h"
13
14 namespace content {
15
16 // TODO(scottmg): Bind the other end of this to the acive SWVersion when it's
17 // created in ServiceWorkerControlleeRequestHandler. Currently, this is a simple
18 // passthrough to the network service.
19 class ServiceWorkerControlleeURLLoaderFactory
20 : public ServiceWorkerURLLoaderFactory {
21 public:
22 class CONTENT_EXPORT Delegate {
23 public:
24 virtual ~Delegate() {}
25
26 virtual ServiceWorkerVersion* GetServiceWorkerVersion(
27 ServiceWorkerMetrics::URLRequestJobResult* result) = 0;
28 };
29
30 ServiceWorkerControlleeURLLoaderFactory(
31 std::unique_ptr<ServiceWorkerRequestHandler> handler,
32 const std::string& client_id,
33 base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
34 const ResourceContext* resource_context,
35 FetchRequestMode request_mode,
36 FetchCredentialsMode credentials_mode,
37 FetchRedirectMode redirect_mode,
38 ResourceType resource_type,
39 RequestContextType request_context_type,
40 RequestContextFrameType frame_type,
41 scoped_refptr<ResourceRequestBodyImpl> body,
42 ServiceWorkerFetchType fetch_type,
43 const base::Optional<base::TimeDelta>& timeout,
44 Delegate* delegate)
45 : ServiceWorkerURLLoaderFactory(std::move(handler)),
46 response_type_(ResponseType::kNotDetermined),
47 client_id_(client_id),
48 blob_storage_context_(blob_storage_context),
49 resource_context_(resource_context),
50 request_mode_(request_mode),
51 credentials_mode_(credentials_mode),
52 redirect_mode_(redirect_mode),
53 resource_type_(resource_type),
54 request_context_type_(request_context_type),
55 frame_type_(frame_type),
56 body_(body),
57 fetch_type_(fetch_type),
58 timeout_(timeout),
59 delegate_(delegate),
60 weak_factory_(this) {}
61 ~ServiceWorkerControlleeURLLoaderFactory() override;
62
63 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest request,
64 int32_t routing_id,
65 int32_t request_id,
66 uint32_t options,
67 const ResourceRequest& url_request,
68 mojom::URLLoaderClientPtr client) override;
69 void SyncLoad(int32_t routing_id,
70 int32_t request_id,
71 const ResourceRequest& request,
72 SyncLoadCallback callback) override;
73
74 void FallbackToNetwork();
75 bool ShouldFallbackToNetwork();
76 ui::PageTransition GetPageTransition();
77 size_t GetURLChainSize();
78 void ForwardToServiceWorker();
79 void FallbackToNetworkOrRenderer();
80 void FailToNetworkOrRenderer();
81 void FailDueToLostController();
82 bool WasCanceled() const;
83
84 private:
85 std::unique_ptr<ServiceWorkerFetchRequest> CreateFetchRequest();
86 void StartRequest();
87
88 // For kForwardToServiceWorker case.
89 void DidPrepareFetchEvent(scoped_refptr<ServiceWorkerVersion> version);
90 void DidDispatchFetchEvent(
91 ServiceWorkerStatusCode status,
92 ServiceWorkerFetchEventResult fetch_result,
93 const ServiceWorkerResponse& response,
94 blink::mojom::ServiceWorkerStreamHandlePtr body_as_stream,
95 const scoped_refptr<ServiceWorkerVersion>& version);
96 void AfterRead(scoped_refptr<net::IOBuffer> buffer, int bytes);
97
98 enum class ResponseType {
99 kNotDetermined,
100 kFailDueToLostController,
101 kFallbackToNetwork,
102 kFallbackToRenderer, // Use this when falling back with CORS check
103 kForwardToServiceWorker,
104 };
105 ResponseType response_type_;
106
107 mojom::URLLoaderAssociatedRequest request_;
108 ResourceRequest url_request_;
109 mojom::URLLoaderClientPtr client_;
110
111 std::unique_ptr<ServiceWorkerFetchDispatcher> fetch_dispatcher_;
112 std::string client_id_;
113 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_;
114 const ResourceContext* resource_context_;
115 FetchRequestMode request_mode_;
116 FetchCredentialsMode credentials_mode_;
117 FetchRedirectMode redirect_mode_;
118 const ResourceType resource_type_;
119 RequestContextType request_context_type_;
120 RequestContextFrameType frame_type_;
121 scoped_refptr<ResourceRequestBodyImpl> body_;
122 ServiceWorkerFetchType fetch_type_;
123 base::Optional<base::TimeDelta> timeout_;
124 Delegate* delegate_;
125 std::unique_ptr<storage::BlobReader> blob_reader_;
126 mojo::DataPipe data_pipe_;
127
128 base::WeakPtrFactory<ServiceWorkerControlleeURLLoaderFactory> weak_factory_;
129 };
130
131 } // namespace content
132
133 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_URL_LOADER_F ACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698