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

Side by Side Diff: content/browser/service_worker/service_worker_url_request_job.cc

Issue 320553003: blob bug wip Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "content/browser/service_worker/service_worker_url_request_job.h" 5 #include "content/browser/service_worker/service_worker_url_request_job.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" 9 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h"
10 #include "content/browser/service_worker/service_worker_provider_host.h" 10 #include "content/browser/service_worker/service_worker_provider_host.h"
11 #include "net/http/http_request_headers.h" 11 #include "net/http/http_request_headers.h"
12 #include "net/http/http_response_headers.h" 12 #include "net/http/http_response_headers.h"
13 #include "net/http/http_response_info.h" 13 #include "net/http/http_response_info.h"
14 #include "net/http/http_util.h" 14 #include "net/http/http_util.h"
15 #include "webkit/browser/blob/blob_data_handle.h" 15 #include "webkit/browser/blob/blob_data_handle.h"
16 #include "webkit/browser/blob/blob_storage_context.h" 16 #include "webkit/browser/blob/blob_storage_context.h"
17 #include "webkit/browser/blob/blob_url_request_job_factory.h" 17 #include "webkit/browser/blob/blob_url_request_job_factory.h"
18 18
19 namespace content { 19 namespace content {
20 20
21 namespace {
22
23 ServiceWorkerFetchRequest URLRequestToFetchRequest(
24 net::URLRequest* url_request) {
25 ServiceWorkerFetchRequest fetch_request;
26 fetch_request.url = url_request->url();
27 fetch_request.method = url_request->method();
28 const net::HttpRequestHeaders& headers = url_request->extra_request_headers();
29 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext();)
30 fetch_request.headers[it.name()] = it.value();
31 return fetch_request;
32 }
33
34 } // namespace
35
21 ServiceWorkerURLRequestJob::ServiceWorkerURLRequestJob( 36 ServiceWorkerURLRequestJob::ServiceWorkerURLRequestJob(
22 net::URLRequest* request, 37 net::URLRequest* request,
23 net::NetworkDelegate* network_delegate, 38 net::NetworkDelegate* network_delegate,
24 base::WeakPtr<ServiceWorkerProviderHost> provider_host, 39 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
25 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context) 40 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context)
26 : net::URLRequestJob(request, network_delegate), 41 : net::URLRequestJob(request, network_delegate),
27 provider_host_(provider_host), 42 provider_host_(provider_host),
28 response_type_(NOT_DETERMINED), 43 response_type_(NOT_DETERMINED),
29 is_started_(false), 44 is_started_(false),
30 blob_storage_context_(blob_storage_context), 45 blob_storage_context_(blob_storage_context),
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 NotifyRestartRequired(); 209 NotifyRestartRequired();
195 return; 210 return;
196 211
197 case FORWARD_TO_SERVICE_WORKER: 212 case FORWARD_TO_SERVICE_WORKER:
198 DCHECK(provider_host_ && provider_host_->active_version()); 213 DCHECK(provider_host_ && provider_host_->active_version());
199 DCHECK(!fetch_dispatcher_); 214 DCHECK(!fetch_dispatcher_);
200 215
201 // Send a fetch event to the ServiceWorker associated to the 216 // Send a fetch event to the ServiceWorker associated to the
202 // provider_host. 217 // provider_host.
203 fetch_dispatcher_.reset(new ServiceWorkerFetchDispatcher( 218 fetch_dispatcher_.reset(new ServiceWorkerFetchDispatcher(
204 request(), provider_host_->active_version(), 219 URLRequestToFetchRequest(request()),
220 provider_host_->active_version(),
221 blob_storage_context_,
205 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent, 222 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent,
206 weak_factory_.GetWeakPtr()))); 223 weak_factory_.GetWeakPtr())));
207 fetch_dispatcher_->Run(); 224 fetch_dispatcher_->Run();
208 return; 225 return;
209 } 226 }
210 227
211 NOTREACHED(); 228 NOTREACHED();
212 } 229 }
213 230
214 void ServiceWorkerURLRequestJob::DidDispatchFetchEvent( 231 void ServiceWorkerURLRequestJob::DidDispatchFetchEvent(
215 ServiceWorkerStatusCode status, 232 ServiceWorkerStatusCode status,
216 ServiceWorkerFetchEventResult fetch_result, 233 ServiceWorkerFetchEventResult fetch_result,
217 const ServiceWorkerResponse& response) { 234 const ServiceWorkerResponse& response,
235 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle) {
218 fetch_dispatcher_.reset(); 236 fetch_dispatcher_.reset();
219 237
220 // Check if we're not orphaned. 238 // Check if we're not orphaned.
221 if (!request()) 239 if (!request())
222 return; 240 return;
223 241
224 if (status != SERVICE_WORKER_OK) { 242 if (status != SERVICE_WORKER_OK) {
225 // Dispatching event has been failed, falling back to the network. 243 // Dispatching event has been failed, falling back to the network.
226 // (Tentative behavior described on github) 244 // (Tentative behavior described on github)
227 // TODO(kinuko): consider returning error if we've come here because 245 // TODO(kinuko): consider returning error if we've come here because
(...skipping 10 matching lines...) Expand all
238 response_type_ = FALLBACK_TO_NETWORK; 256 response_type_ = FALLBACK_TO_NETWORK;
239 NotifyRestartRequired(); 257 NotifyRestartRequired();
240 return; 258 return;
241 } 259 }
242 260
243 // We should have a response now. 261 // We should have a response now.
244 DCHECK_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, fetch_result); 262 DCHECK_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, fetch_result);
245 263
246 // Set up a request for reading the blob. 264 // Set up a request for reading the blob.
247 if (!response.blob_uuid.empty() && blob_storage_context_) { 265 if (!response.blob_uuid.empty() && blob_storage_context_) {
248 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle =
249 blob_storage_context_->GetBlobDataFromUUID(response.blob_uuid);
250 if (!blob_data_handle) { 266 if (!blob_data_handle) {
251 // The renderer gave us a bad blob UUID. 267 // The renderer gave us a bad blob UUID.
252 DeliverErrorResponse(); 268 DeliverErrorResponse();
253 return; 269 return;
254 } 270 }
255 blob_request_ = webkit_blob::BlobProtocolHandler::CreateBlobRequest( 271 blob_request_ = webkit_blob::BlobProtocolHandler::CreateBlobRequest(
256 blob_data_handle.Pass(), request()->context(), this); 272 blob_data_handle.Pass(), request()->context(), this);
257 blob_request_->Start(); 273 blob_request_->Start();
258 } 274 }
259 275
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 void ServiceWorkerURLRequestJob::DeliverErrorResponse() { 310 void ServiceWorkerURLRequestJob::DeliverErrorResponse() {
295 // TODO(falken): Print an error to the console of the ServiceWorker and of 311 // TODO(falken): Print an error to the console of the ServiceWorker and of
296 // the requesting page. 312 // the requesting page.
297 CreateResponseHeader(500, 313 CreateResponseHeader(500,
298 "Service Worker Response Error", 314 "Service Worker Response Error",
299 std::map<std::string, std::string>()); 315 std::map<std::string, std::string>());
300 CommitResponseHeader(); 316 CommitResponseHeader();
301 } 317 }
302 318
303 } // namespace content 319 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698