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

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

Issue 2906163002: [network service][SW] Rework browser-side SW on top of URL loader chaining (Closed)
Patch Set: 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "content/browser/loader/url_loader_request_handler.h" 10 #include "content/browser/loader/url_loader_request_handler.h"
11 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h"
11 #include "content/browser/service_worker/service_worker_response_type.h" 12 #include "content/browser/service_worker/service_worker_response_type.h"
12 #include "content/browser/service_worker/service_worker_url_request_job.h" 13 #include "content/browser/service_worker/service_worker_url_request_job.h"
14 #include "storage/browser/blob/blob_reader.h"
13 15
14 namespace content { 16 namespace content {
15 17
16 // This class is a helper to support having 18 // This class is a helper to support having
17 // ServiceWorkerControlleeRequestHandler work with both URLRequestJobs and 19 // ServiceWorkerControlleeRequestHandler work with both URLRequestJobs and
18 // mojom::URLLoaderFactorys (that is, both with and without 20 // mojom::URLLoaderFactorys (that is, both with and without
19 // --enable-network-service). It wraps either a ServiceWorkerURLRequestJob or a 21 // --enable-network-service). It wraps either a ServiceWorkerURLRequestJob or a
20 // callback for URLLoaderFactory and forwards to the underlying implementation. 22 // callback for URLLoaderFactory and forwards to the underlying implementation.
21 class ServiceWorkerURLJobWrapper { 23 class ServiceWorkerURLJobWrapper {
22 public: 24 public:
25 class Delegate {
26 public:
27 virtual ~Delegate() {}
28
29 virtual ServiceWorkerVersion* GetServiceWorkerVersion(
30 ServiceWorkerMetrics::URLRequestJobResult* result) = 0;
31 };
32
23 // Non-network service case. 33 // Non-network service case.
24 explicit ServiceWorkerURLJobWrapper( 34 explicit ServiceWorkerURLJobWrapper(
25 base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job); 35 base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job);
26 36
27 // With --enable-network-service. 37 // With --enable-network-service.
28 // TODO(kinuko): Implement this as a separate job class rather 38 // TODO(kinuko): Implement this as a separate job class rather
29 // than in a wrapper. 39 // than in a wrapper.
30 ServiceWorkerURLJobWrapper(LoaderFactoryCallback loader_factory_callback); 40 ServiceWorkerURLJobWrapper(
41 LoaderFactoryCallback loader_factory_callback,
42 Delegate* delegate,
43 base::WeakPtr<storage::BlobStorageContext> blob_storage_context);
31 44
32 ~ServiceWorkerURLJobWrapper(); 45 ~ServiceWorkerURLJobWrapper();
33 46
34 // Sets the response type. 47 // Sets the response type.
35 void FallbackToNetwork(); 48 void FallbackToNetwork();
36 void FallbackToNetworkOrRenderer(); 49 void FallbackToNetworkOrRenderer();
37 void ForwardToServiceWorker(); 50 void ForwardToServiceWorker();
38 51
39 // Returns true if this job should not be handled by a service worker, but 52 // Returns true if this job should not be handled by a service worker, but
40 // instead should fallback to the network. 53 // instead should fallback to the network.
(...skipping 12 matching lines...) Expand all
53 // purposes). 66 // purposes).
54 size_t GetURLChainSize() const; 67 size_t GetURLChainSize() const;
55 68
56 // Returns true if the underlying job has been canceled or destroyed. 69 // Returns true if the underlying job has been canceled or destroyed.
57 bool WasCanceled() const; 70 bool WasCanceled() const;
58 71
59 private: 72 private:
60 enum class JobType { kURLRequest, kURLLoader }; 73 enum class JobType { kURLRequest, kURLLoader };
61 74
62 // Used only for URLLoader case. 75 // Used only for URLLoader case.
63 // TODO(kinuko): Implement this in a separate job class rather 76 // For FORWARD_TO_SERVICE_WORKER case.
64 // than in a wrapper. 77 class Factory;
65 void StartRequest(); 78 void StartRequest();
66 79
67 JobType job_type_; 80 JobType job_type_;
68 81
69 ServiceWorkerResponseType response_type_ = NOT_DETERMINED; 82 ServiceWorkerResponseType response_type_ = NOT_DETERMINED;
70 LoaderFactoryCallback loader_factory_callback_; 83 LoaderFactoryCallback loader_factory_callback_;
71 84
72 base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job_; 85 base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job_;
73 86
87 Delegate* delegate_;
88 std::unique_ptr<Factory> factory_;
89 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_;
90
74 base::WeakPtrFactory<ServiceWorkerURLJobWrapper> weak_factory_; 91 base::WeakPtrFactory<ServiceWorkerURLJobWrapper> weak_factory_;
75 92
76 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLJobWrapper); 93 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLJobWrapper);
77 }; 94 };
78 95
79 } // namespace content 96 } // namespace content
80 97
81 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_ 98 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698