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

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

Issue 2923413003: Split ServiceWorkerURLLoaderJob from URLJobWrapper (Closed)
Patch Set: rebase Created 3 years, 6 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_URL_LOADER_JOB_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_LOADER_JOB_H_
7
8 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h"
10 #include "content/browser/loader/url_loader_request_handler.h"
11 #include "content/browser/service_worker/service_worker_metrics.h"
12 #include "content/browser/service_worker/service_worker_response_type.h"
13 #include "content/common/service_worker/service_worker_status_code.h"
14 #include "content/common/service_worker/service_worker_types.h"
15 #include "content/common/url_loader.mojom.h"
16 #include "mojo/public/cpp/bindings/strong_binding.h"
17 #include "third_party/WebKit/public/platform/modules/serviceworker/service_worke r_stream_handle.mojom.h"
18
19 namespace net {
20 class IOBuffer;
21 }
22
23 namespace storage {
24 class BlobReader;
25 class BlobStorageContext;
26 }
27
28 namespace content {
29
30 class ServiceWorkerFetchDispatcher;
31 class ServiceWorkerVersion;
32 struct ServiceWorkerResponse;
33
34 // ServiceWorkerURLLoaderJob works similar to ServiceWorkerURLRequestJob
35 // but with mojom::URLLoader instead of URLRequest, and used only when
36 // --enable-network-service and PlzNavigate is enabled.
37 class ServiceWorkerURLLoaderJob : public mojom::URLLoader {
38 public:
39 class Delegate {
40 public:
41 virtual ~Delegate() {}
42
43 virtual ServiceWorkerVersion* GetServiceWorkerVersion(
44 ServiceWorkerMetrics::URLRequestJobResult* result) = 0;
45 };
46
47 ServiceWorkerURLLoaderJob(
48 LoaderCallback loader_callback,
49 Delegate* delegate,
50 const ResourceRequest& resource_request,
51 base::WeakPtr<storage::BlobStorageContext> blob_storage_context);
52
53 ~ServiceWorkerURLLoaderJob() override;
54
55 // Called via URLJobWrapper.
56 void FallbackToNetwork();
57 void FallbackToNetworkOrRenderer();
58 void ForwardToServiceWorker();
59 bool ShouldFallbackToNetwork();
60 void FailDueToLostController();
61 ui::PageTransition GetPageTransition();
62 size_t GetURLChainSize() const;
63 void Cancel();
64 bool WasCanceled() const;
65
66 private:
67 // For FORWARD_TO_SERVICE_WORKER case.
68 void StartRequest();
69 void DidPrepareFetchEvent(scoped_refptr<ServiceWorkerVersion> version);
70 void DidDispatchFetchEvent(
71 ServiceWorkerStatusCode status,
72 ServiceWorkerFetchEventResult fetch_result,
73 const ServiceWorkerResponse& response,
74 blink::mojom::ServiceWorkerStreamHandlePtr body_as_stream,
75 const scoped_refptr<ServiceWorkerVersion>& version);
76
77 void StartResponse(const ServiceWorkerResponse& response,
78 blink::mojom::ServiceWorkerStreamHandlePtr body_as_stream,
79 mojom::URLLoaderRequest request,
80 mojom::URLLoaderClientPtr client);
81 void AfterRead(scoped_refptr<net::IOBuffer> buffer, int bytes);
82
83 std::unique_ptr<ServiceWorkerFetchRequest> CreateFetchRequest(
84 const ResourceRequest& request);
85
86 // mojom::URLLoader:
87 void FollowRedirect() override;
88 void SetPriority(net::RequestPriority priority,
89 int32_t intra_priority_value) override;
90
91 ServiceWorkerResponseType response_type_ = NOT_DETERMINED;
92 LoaderCallback loader_callback_;
93
94 Delegate* delegate_;
95 ResourceRequest resource_request_;
96 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_;
97 std::unique_ptr<ServiceWorkerFetchDispatcher> fetch_dispatcher_;
98
99 std::unique_ptr<storage::BlobReader> blob_reader_;
100 mojo::DataPipe data_pipe_;
101
102 mojom::URLLoaderClientPtr url_loader_client_;
103 mojo::Binding<mojom::URLLoader> binding_;
104
105 bool canceled_ = false;
106
107 base::WeakPtrFactory<ServiceWorkerURLLoaderJob> weak_factory_;
108
109 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLLoaderJob);
110 };
111
112 } // namespace content
113
114 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_LOADER_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698