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

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

Issue 2038813003: Making ResourceRequestBody part of //content's public API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing... Created 4 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_FOREIGN_FETCH_REQUEST_HANDLER_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_FOREIGN_FETCH_REQUEST_HANDLER_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_FOREIGN_FETCH_REQUEST_HANDLER_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_FOREIGN_FETCH_REQUEST_HANDLER_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 "base/supports_user_data.h" 10 #include "base/supports_user_data.h"
(...skipping 13 matching lines...) Expand all
24 class URLRequestInterceptor; 24 class URLRequestInterceptor;
25 } 25 }
26 26
27 namespace storage { 27 namespace storage {
28 class BlobStorageContext; 28 class BlobStorageContext;
29 } 29 }
30 30
31 namespace content { 31 namespace content {
32 32
33 class ResourceContext; 33 class ResourceContext;
34 class ResourceRequestBody; 34 class ResourceRequestBodyImpl;
35 class ServiceWorkerContextCore; 35 class ServiceWorkerContextCore;
36 class ServiceWorkerContextWrapper; 36 class ServiceWorkerContextWrapper;
37 class ServiceWorkerProviderHost; 37 class ServiceWorkerProviderHost;
38 class ServiceWorkerRegistration; 38 class ServiceWorkerRegistration;
39 struct ResourceResponseInfo; 39 struct ResourceResponseInfo;
40 40
41 // Class for routing network requests to ServiceWorkers for foreign fetch 41 // Class for routing network requests to ServiceWorkers for foreign fetch
42 // events. Created one per URLRequest and attached to each request. 42 // events. Created one per URLRequest and attached to each request.
43 // TODO(mek): Does this need something similar to ServiceWorkerRequestHandler's 43 // TODO(mek): Does this need something similar to ServiceWorkerRequestHandler's
44 // GetExtraResponseInfo method? 44 // GetExtraResponseInfo method?
45 class CONTENT_EXPORT ForeignFetchRequestHandler 45 class CONTENT_EXPORT ForeignFetchRequestHandler
46 : public base::SupportsUserData::Data, 46 : public base::SupportsUserData::Data,
47 public ServiceWorkerURLRequestJob::Delegate { 47 public ServiceWorkerURLRequestJob::Delegate {
48 public: 48 public:
49 // Attaches a newly created handler if the given |request| needs to 49 // Attaches a newly created handler if the given |request| needs to
50 // be handled by a foreign fetch handling ServiceWorker. 50 // be handled by a foreign fetch handling ServiceWorker.
51 static void InitializeHandler( 51 static void InitializeHandler(
52 net::URLRequest* request, 52 net::URLRequest* request,
53 ServiceWorkerContextWrapper* context_wrapper, 53 ServiceWorkerContextWrapper* context_wrapper,
54 storage::BlobStorageContext* blob_storage_context, 54 storage::BlobStorageContext* blob_storage_context,
55 int process_id, 55 int process_id,
56 int provider_id, 56 int provider_id,
57 bool skip_service_worker, 57 bool skip_service_worker,
58 FetchRequestMode request_mode, 58 FetchRequestMode request_mode,
59 FetchCredentialsMode credentials_mode, 59 FetchCredentialsMode credentials_mode,
60 FetchRedirectMode redirect_mode, 60 FetchRedirectMode redirect_mode,
61 ResourceType resource_type, 61 ResourceType resource_type,
62 RequestContextType request_context_type, 62 RequestContextType request_context_type,
63 RequestContextFrameType frame_type, 63 RequestContextFrameType frame_type,
64 scoped_refptr<ResourceRequestBody> body, 64 scoped_refptr<ResourceRequestBodyImpl> body,
65 bool initiated_in_secure_context); 65 bool initiated_in_secure_context);
66 66
67 // Returns the handler attached to |request|. This may return null 67 // Returns the handler attached to |request|. This may return null
68 // if no handler is attached. 68 // if no handler is attached.
69 static ForeignFetchRequestHandler* GetHandler(net::URLRequest* request); 69 static ForeignFetchRequestHandler* GetHandler(net::URLRequest* request);
70 70
71 // Creates a protocol interceptor for foreign fetch. 71 // Creates a protocol interceptor for foreign fetch.
72 static std::unique_ptr<net::URLRequestInterceptor> CreateInterceptor( 72 static std::unique_ptr<net::URLRequestInterceptor> CreateInterceptor(
73 ResourceContext* resource_context); 73 ResourceContext* resource_context);
74 74
75 ~ForeignFetchRequestHandler() override; 75 ~ForeignFetchRequestHandler() override;
76 76
77 // Called via custom URLRequestJobFactory. 77 // Called via custom URLRequestJobFactory.
78 net::URLRequestJob* MaybeCreateJob(net::URLRequest* request, 78 net::URLRequestJob* MaybeCreateJob(net::URLRequest* request,
79 net::NetworkDelegate* network_delegate, 79 net::NetworkDelegate* network_delegate,
80 ResourceContext* resource_context); 80 ResourceContext* resource_context);
81 81
82 private: 82 private:
83 ForeignFetchRequestHandler( 83 ForeignFetchRequestHandler(
84 ServiceWorkerContextWrapper* context, 84 ServiceWorkerContextWrapper* context,
85 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, 85 base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
86 FetchRequestMode request_mode, 86 FetchRequestMode request_mode,
87 FetchCredentialsMode credentials_mode, 87 FetchCredentialsMode credentials_mode,
88 FetchRedirectMode redirect_mode, 88 FetchRedirectMode redirect_mode,
89 ResourceType resource_type, 89 ResourceType resource_type,
90 RequestContextType request_context_type, 90 RequestContextType request_context_type,
91 RequestContextFrameType frame_type, 91 RequestContextFrameType frame_type,
92 scoped_refptr<ResourceRequestBody> body); 92 scoped_refptr<ResourceRequestBodyImpl> body);
93 93
94 // Called when a ServiceWorkerRegistration has (or hasn't) been found for the 94 // Called when a ServiceWorkerRegistration has (or hasn't) been found for the
95 // request being handled. 95 // request being handled.
96 void DidFindRegistration( 96 void DidFindRegistration(
97 const base::WeakPtr<ServiceWorkerURLRequestJob>& job, 97 const base::WeakPtr<ServiceWorkerURLRequestJob>& job,
98 ServiceWorkerStatusCode status, 98 ServiceWorkerStatusCode status,
99 const scoped_refptr<ServiceWorkerRegistration>& registration); 99 const scoped_refptr<ServiceWorkerRegistration>& registration);
100 100
101 // ServiceWorkerURLRequestJob::Delegate implementation: 101 // ServiceWorkerURLRequestJob::Delegate implementation:
102 void OnPrepareToRestart() override; 102 void OnPrepareToRestart() override;
103 ServiceWorkerVersion* GetServiceWorkerVersion( 103 ServiceWorkerVersion* GetServiceWorkerVersion(
104 ServiceWorkerMetrics::URLRequestJobResult* result) override; 104 ServiceWorkerMetrics::URLRequestJobResult* result) override;
105 105
106 // Sets |job_| to nullptr, and clears all extra response info associated with 106 // Sets |job_| to nullptr, and clears all extra response info associated with
107 // that job. 107 // that job.
108 void ClearJob(); 108 void ClearJob();
109 109
110 scoped_refptr<ServiceWorkerContextWrapper> context_; 110 scoped_refptr<ServiceWorkerContextWrapper> context_;
111 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; 111 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_;
112 ResourceType resource_type_; 112 ResourceType resource_type_;
113 FetchRequestMode request_mode_; 113 FetchRequestMode request_mode_;
114 FetchCredentialsMode credentials_mode_; 114 FetchCredentialsMode credentials_mode_;
115 FetchRedirectMode redirect_mode_; 115 FetchRedirectMode redirect_mode_;
116 RequestContextType request_context_type_; 116 RequestContextType request_context_type_;
117 RequestContextFrameType frame_type_; 117 RequestContextFrameType frame_type_;
118 scoped_refptr<ResourceRequestBody> body_; 118 scoped_refptr<ResourceRequestBodyImpl> body_;
119 119
120 base::WeakPtr<ServiceWorkerURLRequestJob> job_; 120 base::WeakPtr<ServiceWorkerURLRequestJob> job_;
121 scoped_refptr<ServiceWorkerVersion> target_worker_; 121 scoped_refptr<ServiceWorkerVersion> target_worker_;
122 122
123 // True if the next time this request is started, the response should be 123 // True if the next time this request is started, the response should be
124 // delivered from the network, bypassing the ServiceWorker. 124 // delivered from the network, bypassing the ServiceWorker.
125 bool use_network_ = false; 125 bool use_network_ = false;
126 126
127 base::WeakPtrFactory<ForeignFetchRequestHandler> weak_factory_; 127 base::WeakPtrFactory<ForeignFetchRequestHandler> weak_factory_;
128 128
129 DISALLOW_COPY_AND_ASSIGN(ForeignFetchRequestHandler); 129 DISALLOW_COPY_AND_ASSIGN(ForeignFetchRequestHandler);
130 }; 130 };
131 131
132 } // namespace content 132 } // namespace content
133 133
134 #endif // CONTENT_BROWSER_SERVICE_WORKER_FOREIGN_FETCH_REQUEST_HANDLER_H_ 134 #endif // CONTENT_BROWSER_SERVICE_WORKER_FOREIGN_FETCH_REQUEST_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698