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

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: Fix build failures 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
michaeln 2017/07/17 21:04:55 maybe comment on how these methods apply to the ne
ananta 2017/07/18 00:19:03 Done.
78 void OnReceiveResponse(const ResourceResponseHead& response_head,
79 const base::Optional<net::SSLInfo>& ssl_info,
80 mojom::DownloadedTempFilePtr downloaded_file) override;
81 void OnReceiveRedirect(const net::RedirectInfo& redirect_info,
82 const ResourceResponseHead& response_head) override;
83 void OnDataDownloaded(int64_t data_len, int64_t encoded_data_len) override;
84 void OnUploadProgress(int64_t current_position,
85 int64_t total_size,
86 OnUploadProgressCallback ack_callback) override;
87 void OnReceiveCachedMetadata(const std::vector<uint8_t>& data) override;
88 void OnTransferSizeUpdated(int32_t transfer_size_diff) override;
89 void OnStartLoadingResponseBody(
90 mojo::ScopedDataPipeConsumerHandle body) override;
91 void OnComplete(const ResourceRequestCompletionStatus& status) override;
92
76 void set_main_resource_loader_callback(LoaderCallback callback) { 93 void set_main_resource_loader_callback(LoaderCallback callback) {
77 main_resource_loader_callback_ = std::move(callback); 94 main_resource_loader_callback_ = std::move(callback);
78 } 95 }
79 96
80 // Subresource request load information is passed in the 97 // Subresource request load information is passed in the
81 // |subresource_load_info| parameter. This includes the request id, the 98 // |subresource_load_info| parameter. This includes the request id, the
82 // client pointer, etc. 99 // client pointer, etc.
83 // |default_url_loader| is used to retrieve the network loader for requests 100 // |default_url_loader| is used to retrieve the network loader for requests
84 // intended to be sent to the network. 101 // intended to be sent to the network.
85 void SetSubresourceLoadInfo( 102 void SetSubresourceLoadInfo(
86 std::unique_ptr<SubresourceLoadInfo> subresource_load_info, 103 std::unique_ptr<SubresourceLoadInfo> subresource_load_info,
87 URLLoaderFactoryGetter* default_url_loader); 104 URLLoaderFactoryGetter* default_url_loader);
88 105
89 // Ownership of the |handler| is transferred to us via this call. This is 106 // Ownership of the |handler| is transferred to us via this call. This is
90 // only for subresource requests. 107 // only for subresource requests.
91 void set_request_handler(std::unique_ptr<AppCacheRequestHandler> handler) { 108 void set_request_handler(std::unique_ptr<AppCacheRequestHandler> handler) {
92 sub_resource_handler_ = std::move(handler); 109 sub_resource_handler_ = std::move(handler);
93 } 110 }
94 111
95 protected: 112 protected:
96 // AppCacheJob::Create() creates this instance. 113 // AppCacheJob::Create() creates this instance.
97 friend class AppCacheJob; 114 friend class AppCacheJob;
98 115
99 AppCacheURLLoaderJob(const ResourceRequest& request, 116 AppCacheURLLoaderJob(const ResourceRequest& request,
117 AppCacheURLLoaderRequest* url_loader_request,
100 AppCacheStorage* storage); 118 AppCacheStorage* storage);
101 119
102 // AppCacheStorage::Delegate methods 120 // AppCacheStorage::Delegate methods
103 void OnResponseInfoLoaded(AppCacheResponseInfo* response_info, 121 void OnResponseInfoLoaded(AppCacheResponseInfo* response_info,
104 int64_t response_id) override; 122 int64_t response_id) override;
105 123
106 // AppCacheResponseReader completion callback 124 // AppCacheResponseReader completion callback
107 void OnReadComplete(int result); 125 void OnReadComplete(int result);
108 126
109 void OnConnectionError(); 127 void OnConnectionError();
110 128
111 // Helper to send the AppCacheResponseInfo to the URLLoaderClient. 129 // Helper to send the AppCacheResponseInfo to the URLLoaderClient.
112 void SendResponseInfo(); 130 void SendResponseInfo();
113 131
114 // Helper function to read the data from the AppCache. 132 // Helper function to read the data from the AppCache.
115 void ReadMore(); 133 void ReadMore();
116 134
117 // Callback invoked when the data pipe can be written to. 135 // Callback invoked when the data pipe can be written to.
118 void OnResponseBodyStreamReady(MojoResult result); 136 void OnResponseBodyStreamReady(MojoResult result);
119 137
120 // Notifies the client about request completion. 138 // Notifies the client about request completion.
121 void NotifyCompleted(int error_code); 139 void NotifyCompleted(int error_code);
122 140
141 // Creates the URLLoaderClient proxy. Used to setup the proxy URLLoaderClient
142 // which enables us to inspect responses coming back from the network service
143 // for AppCache fallback.
144 mojom::URLLoaderClientPtr CreateLoaderClientProxy();
145
123 // The current request. 146 // The current request.
124 ResourceRequest request_; 147 ResourceRequest request_;
125 148
126 base::WeakPtr<AppCacheStorage> storage_; 149 base::WeakPtr<AppCacheStorage> storage_;
127 150
128 // Time when the request started. 151 // Time when the request started.
129 base::TimeTicks start_time_tick_; 152 base::TimeTicks start_time_tick_;
130 153
131 // The AppCache manifest URL. 154 // The AppCache manifest URL.
132 GURL manifest_url_; 155 GURL manifest_url_;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 197
175 // Used for subresource requests which go to the network. 198 // Used for subresource requests which go to the network.
176 mojom::URLLoaderAssociatedPtr network_loader_request_; 199 mojom::URLLoaderAssociatedPtr network_loader_request_;
177 200
178 // Binds the subresource URLLoaderClient with us. We can use the regular 201 // Binds the subresource URLLoaderClient with us. We can use the regular
179 // binding_ member above when we remove the need for the associated requests 202 // binding_ member above when we remove the need for the associated requests
180 // issue with URLLoaderFactory. 203 // issue with URLLoaderFactory.
181 std::unique_ptr<mojo::AssociatedBinding<mojom::URLLoader>> 204 std::unique_ptr<mojo::AssociatedBinding<mojom::URLLoader>>
182 associated_binding_; 205 associated_binding_;
183 206
207 // Proxy URLLoaderClient binding for subresource requests.
208 mojo::Binding<mojom::URLLoaderClient> loader_client_proxy_binding_;
209
210 // The AppCacheURLLoaderRequest instance. We use this to set the response
211 // info when we receive it.
212 AppCacheURLLoaderRequest* url_loader_request_instance_;
213
184 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoaderJob); 214 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoaderJob);
185 }; 215 };
186 216
187 } // namespace content 217 } // namespace content
188 218
189 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_JOB_H_ 219 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698