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

Side by Side Diff: content/browser/appcache/appcache_url_loader_job.h

Issue 2974733002: Add support for subresource request fallback in AppCache for the network service.. (Closed)
Patch Set: Close the network service binding handle when we are delivering a fallback Created 3 years, 5 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 (c) 2017 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_APPCACHE_APPCACHE_URL_LOADER_JOB_H_ 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_JOB_H_
6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_JOB_H_ 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_JOB_H_
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "content/browser/appcache/appcache_entry.h" 13 #include "content/browser/appcache/appcache_entry.h"
14 #include "content/browser/appcache/appcache_job.h" 14 #include "content/browser/appcache/appcache_job.h"
15 #include "content/browser/appcache/appcache_request_handler.h" 15 #include "content/browser/appcache/appcache_request_handler.h"
16 #include "content/browser/appcache/appcache_response.h" 16 #include "content/browser/appcache/appcache_response.h"
17 #include "content/browser/appcache/appcache_storage.h" 17 #include "content/browser/appcache/appcache_storage.h"
18 #include "content/browser/loader/url_loader_request_handler.h" 18 #include "content/browser/loader/url_loader_request_handler.h"
19 #include "content/common/content_export.h" 19 #include "content/common/content_export.h"
20 #include "content/public/common/resource_request.h" 20 #include "content/public/common/resource_request.h"
21 #include "content/public/common/url_loader.mojom.h" 21 #include "content/public/common/url_loader.mojom.h"
22 #include "mojo/public/cpp/bindings/associated_binding.h" 22 #include "mojo/public/cpp/bindings/associated_binding.h"
23 #include "mojo/public/cpp/bindings/binding.h" 23 #include "mojo/public/cpp/bindings/binding.h"
24 #include "mojo/public/cpp/system/data_pipe.h" 24 #include "mojo/public/cpp/system/data_pipe.h"
25 25
26 namespace content { 26 namespace content {
27 27
28 class AppCacheRequest; 28 class AppCacheRequest;
29 class AppCacheURLLoaderRequest;
29 class NetToMojoPendingBuffer; 30 class NetToMojoPendingBuffer;
30 class URLLoaderFactoryGetter; 31 class URLLoaderFactoryGetter;
31 struct SubresourceLoadInfo;
32 32
33 // Holds information about the subresource load request like the routing id, 33 // Holds information about the subresource load request like the routing id,
34 // request id, the client pointer, etc. 34 // request id, the client pointer, etc.
35 struct SubresourceLoadInfo { 35 struct SubresourceLoadInfo {
36 SubresourceLoadInfo(); 36 SubresourceLoadInfo();
37 ~SubresourceLoadInfo(); 37 ~SubresourceLoadInfo();
38 38
39 mojom::URLLoaderAssociatedRequest url_loader_request; 39 mojom::URLLoaderAssociatedRequest url_loader_request;
40 int32_t routing_id; 40 int32_t routing_id;
41 int32_t request_id; 41 int32_t request_id;
42 uint32_t options; 42 uint32_t options;
43 ResourceRequest request; 43 ResourceRequest request;
44 mojom::URLLoaderClientPtr client; 44 mojom::URLLoaderClientPtr client;
45 net::MutableNetworkTrafficAnnotationTag traffic_annotation; 45 net::MutableNetworkTrafficAnnotationTag traffic_annotation;
46 }; 46 };
47 47
48 // AppCacheJob wrapper for a mojom::URLLoader implementation which returns 48 // AppCacheJob wrapper for a mojom::URLLoader implementation which returns
49 // responses stored in the AppCache. 49 // responses stored in the AppCache.
50 class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob, 50 class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob,
51 public AppCacheStorage::Delegate, 51 public AppCacheStorage::Delegate,
52 public mojom::URLLoader { 52 public mojom::URLLoader,
53 public mojom::URLLoaderClient {
53 public: 54 public:
54 ~AppCacheURLLoaderJob() override; 55 ~AppCacheURLLoaderJob() override;
55 56
56 // Sets up the bindings. 57 // Sets up the bindings.
57 void Start(mojom::URLLoaderRequest request, mojom::URLLoaderClientPtr client); 58 void Start(mojom::URLLoaderRequest request, mojom::URLLoaderClientPtr client);
58 59
59 // AppCacheJob overrides. 60 // AppCacheJob overrides.
60 void Kill() override; 61 void Kill() override;
61 bool IsStarted() const override; 62 bool IsStarted() const override;
62 void DeliverAppCachedResponse(const GURL& manifest_url, 63 void DeliverAppCachedResponse(const GURL& manifest_url,
63 int64_t cache_id, 64 int64_t cache_id,
64 const AppCacheEntry& entry, 65 const AppCacheEntry& entry,
65 bool is_fallback) override; 66 bool is_fallback) override;
66 void DeliverNetworkResponse() override; 67 void DeliverNetworkResponse() override;
67 void DeliverErrorResponse() override; 68 void DeliverErrorResponse() override;
68 const GURL& GetURL() const override; 69 const GURL& GetURL() const override;
69 AppCacheURLLoaderJob* AsURLLoaderJob() override; 70 AppCacheURLLoaderJob* AsURLLoaderJob() override;
70 71
71 // mojom::URLLoader implementation: 72 // mojom::URLLoader implementation:
72 void FollowRedirect() override; 73 void FollowRedirect() override;
73 void SetPriority(net::RequestPriority priority, 74 void SetPriority(net::RequestPriority priority,
74 int32_t intra_priority_value) override; 75 int32_t intra_priority_value) override;
75 76
77 // mojom::URLLoaderClient implementation.
78 // These methods are called by the network loader for subresource requests
79 // which go to the network. We serve fallback content in these methods
80 // if applicable.
81 void OnReceiveResponse(const ResourceResponseHead& response_head,
82 const base::Optional<net::SSLInfo>& ssl_info,
83 mojom::DownloadedTempFilePtr downloaded_file) override;
84 void OnReceiveRedirect(const net::RedirectInfo& redirect_info,
85 const ResourceResponseHead& response_head) override;
86 void OnDataDownloaded(int64_t data_len, int64_t encoded_data_len) override;
87 void OnUploadProgress(int64_t current_position,
88 int64_t total_size,
89 OnUploadProgressCallback ack_callback) override;
90 void OnReceiveCachedMetadata(const std::vector<uint8_t>& data) override;
91 void OnTransferSizeUpdated(int32_t transfer_size_diff) override;
92 void OnStartLoadingResponseBody(
93 mojo::ScopedDataPipeConsumerHandle body) override;
94 void OnComplete(const ResourceRequestCompletionStatus& status) override;
95
76 void set_main_resource_loader_callback(LoaderCallback callback) { 96 void set_main_resource_loader_callback(LoaderCallback callback) {
77 main_resource_loader_callback_ = std::move(callback); 97 main_resource_loader_callback_ = std::move(callback);
78 } 98 }
79 99
80 // Subresource request load information is passed in the 100 // Subresource request load information is passed in the
81 // |subresource_load_info| parameter. This includes the request id, the 101 // |subresource_load_info| parameter. This includes the request id, the
82 // client pointer, etc. 102 // client pointer, etc.
83 // |default_url_loader| is used to retrieve the network loader for requests 103 // |default_url_loader| is used to retrieve the network loader for requests
84 // intended to be sent to the network. 104 // intended to be sent to the network.
85 void SetSubresourceLoadInfo( 105 void SetSubresourceLoadInfo(
86 std::unique_ptr<SubresourceLoadInfo> subresource_load_info, 106 std::unique_ptr<SubresourceLoadInfo> subresource_load_info,
87 URLLoaderFactoryGetter* default_url_loader); 107 URLLoaderFactoryGetter* default_url_loader);
88 108
89 // Ownership of the |handler| is transferred to us via this call. This is 109 // Ownership of the |handler| is transferred to us via this call. This is
90 // only for subresource requests. 110 // only for subresource requests.
91 void set_request_handler(std::unique_ptr<AppCacheRequestHandler> handler) { 111 void set_request_handler(std::unique_ptr<AppCacheRequestHandler> handler) {
92 sub_resource_handler_ = std::move(handler); 112 sub_resource_handler_ = std::move(handler);
93 } 113 }
94 114
95 protected: 115 protected:
96 // AppCacheJob::Create() creates this instance. 116 // AppCacheJob::Create() creates this instance.
97 friend class AppCacheJob; 117 friend class AppCacheJob;
98 118
99 AppCacheURLLoaderJob(const ResourceRequest& request, 119 AppCacheURLLoaderJob(const ResourceRequest& request,
120 AppCacheURLLoaderRequest* url_loader_request,
100 AppCacheStorage* storage); 121 AppCacheStorage* storage);
101 122
102 // AppCacheStorage::Delegate methods 123 // AppCacheStorage::Delegate methods
103 void OnResponseInfoLoaded(AppCacheResponseInfo* response_info, 124 void OnResponseInfoLoaded(AppCacheResponseInfo* response_info,
104 int64_t response_id) override; 125 int64_t response_id) override;
105 126
106 // AppCacheResponseReader completion callback 127 // AppCacheResponseReader completion callback
107 void OnReadComplete(int result); 128 void OnReadComplete(int result);
108 129
109 void OnConnectionError(); 130 void OnConnectionError();
110 131
111 // Helper to send the AppCacheResponseInfo to the URLLoaderClient. 132 // Helper to send the AppCacheResponseInfo to the URLLoaderClient.
112 void SendResponseInfo(); 133 void SendResponseInfo();
113 134
114 // Helper function to read the data from the AppCache. 135 // Helper function to read the data from the AppCache.
115 void ReadMore(); 136 void ReadMore();
116 137
117 // Callback invoked when the data pipe can be written to. 138 // Callback invoked when the data pipe can be written to.
118 void OnResponseBodyStreamReady(MojoResult result); 139 void OnResponseBodyStreamReady(MojoResult result);
119 140
120 // Notifies the client about request completion. 141 // Notifies the client about request completion.
121 void NotifyCompleted(int error_code); 142 void NotifyCompleted(int error_code);
122 143
144 // Creates the URLLoaderClient proxy. Used to setup the proxy URLLoaderClient
145 // which enables us to inspect responses coming back from the network service
146 // for AppCache fallback.
147 mojom::URLLoaderClientPtr CreateLoaderClientProxy();
148
123 // The current request. 149 // The current request.
124 ResourceRequest request_; 150 ResourceRequest request_;
125 151
126 base::WeakPtr<AppCacheStorage> storage_; 152 base::WeakPtr<AppCacheStorage> storage_;
127 153
128 // Time when the request started. 154 // Time when the request started.
129 base::TimeTicks start_time_tick_; 155 base::TimeTicks start_time_tick_;
130 156
131 // The AppCache manifest URL. 157 // The AppCache manifest URL.
132 GURL manifest_url_; 158 GURL manifest_url_;
133 159
134 // The AppCache id. 160 // The AppCache id.
135 int64_t cache_id_; 161 int64_t cache_id_;
136 162
137 AppCacheEntry entry_; 163 AppCacheEntry entry_;
138 164
139 // Set to true if we are loading fallback content. 165 // Set to true if we are loading fallback content.
140 bool is_fallback_; 166 bool is_fallback_;
141 167
142 // The data pipe used to transfer AppCache data to the client. 168 // The data pipe used to transfer AppCache data to the client.
143 mojo::DataPipe data_pipe_; 169 mojo::DataPipe data_pipe_;
144 170
145 // Binds the URLLoaderClient with us. 171 // Binds the URLLoaderClient with us.
146 mojo::Binding<mojom::URLLoader> binding_; 172 mojo::Binding<mojom::URLLoader> binding_;
147 173
148 // The URLLoaderClient pointer. We call this interface with notifications 174 // The URLLoaderClient pointer. We call this interface with notifications
149 // about the URL load 175 // about the URL load
150 mojom::URLLoaderClientPtr client_info_; 176 mojom::URLLoaderClientPtr client_info_;
michaeln 2017/07/18 19:19:22 naming: client_ (_info sounds more like a data str
ananta 2017/07/18 19:52:40 Done.
151 177
152 // mojo data pipe entities. 178 // mojo data pipe entities.
153 mojo::ScopedDataPipeProducerHandle response_body_stream_; 179 mojo::ScopedDataPipeProducerHandle response_body_stream_;
154 180
155 scoped_refptr<NetToMojoPendingBuffer> pending_write_; 181 scoped_refptr<NetToMojoPendingBuffer> pending_write_;
156 182
157 mojo::SimpleWatcher writable_handle_watcher_; 183 mojo::SimpleWatcher writable_handle_watcher_;
158 184
159 // The Callback to be invoked in the network service land to indicate if 185 // The Callback to be invoked in the network service land to indicate if
160 // the main resource request can be serviced via the AppCache. 186 // the main resource request can be serviced via the AppCache.
161 LoaderCallback main_resource_loader_callback_; 187 LoaderCallback main_resource_loader_callback_;
162 188
163 // We own the AppCacheRequestHandler instance for subresource requests. 189 // We own the AppCacheRequestHandler instance for subresource requests.
164 std::unique_ptr<AppCacheRequestHandler> sub_resource_handler_; 190 std::unique_ptr<AppCacheRequestHandler> sub_resource_handler_;
165 191
166 scoped_refptr<URLLoaderFactoryGetter> default_url_loader_factory_getter_; 192 scoped_refptr<URLLoaderFactoryGetter> default_url_loader_factory_getter_;
167 193
168 // Holds subresource url loader information. 194 // Holds subresource url loader information.
169 std::unique_ptr<SubresourceLoadInfo> subresource_load_info_; 195 std::unique_ptr<SubresourceLoadInfo> subresource_load_info_;
170 196
171 // Timing information for the most recent request. Its start times are 197 // Timing information for the most recent request. Its start times are
172 // populated in DeliverAppCachedResponse(). 198 // populated in DeliverAppCachedResponse().
173 net::LoadTimingInfo load_timing_info_; 199 net::LoadTimingInfo load_timing_info_;
174 200
175 // Used for subresource requests which go to the network. 201 // Used for subresource requests which go to the network.
176 mojom::URLLoaderAssociatedPtr network_loader_request_; 202 mojom::URLLoaderAssociatedPtr network_loader_request_;
michaeln 2017/07/18 19:19:22 naming: network_loader_
ananta 2017/07/18 19:52:40 Done.
177 203
178 // Binds the subresource URLLoaderClient with us. We can use the regular 204 // Binds the subresource URLLoaderClient with us. We can use the regular
179 // binding_ member above when we remove the need for the associated requests 205 // binding_ member above when we remove the need for the associated requests
180 // issue with URLLoaderFactory. 206 // issue with URLLoaderFactory.
181 std::unique_ptr<mojo::AssociatedBinding<mojom::URLLoader>> 207 std::unique_ptr<mojo::AssociatedBinding<mojom::URLLoader>>
182 associated_binding_; 208 associated_binding_;
183 209
210 // Proxy URLLoaderClient binding for subresource requests.
211 mojo::Binding<mojom::URLLoaderClient> loader_client_proxy_binding_;
michaeln 2017/07/18 19:19:22 naming: network_loader_client_binding_
ananta 2017/07/18 19:52:40 Done.
212
213 // The AppCacheURLLoaderRequest instance. We use this to set the response
214 // info when we receive it.
215 AppCacheURLLoaderRequest* url_loader_request_instance_;
michaeln 2017/07/18 19:19:22 naming: appcache_request_
ananta 2017/07/18 19:52:40 Done.
216
184 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoaderJob); 217 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoaderJob);
185 }; 218 };
186 219
187 } // namespace content 220 } // namespace content
188 221
189 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_JOB_H_ 222 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698