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

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

Issue 425653002: content: ResourceType cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: REBASE Created 6 years, 4 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_context_request_handler. h" 5 #include "content/browser/service_worker/service_worker_context_request_handler. h"
6 6
7 #include "content/browser/service_worker/service_worker_context_core.h" 7 #include "content/browser/service_worker/service_worker_context_core.h"
8 #include "content/browser/service_worker/service_worker_provider_host.h" 8 #include "content/browser/service_worker/service_worker_provider_host.h"
9 #include "content/browser/service_worker/service_worker_read_from_cache_job.h" 9 #include "content/browser/service_worker/service_worker_read_from_cache_job.h"
10 #include "content/browser/service_worker/service_worker_storage.h" 10 #include "content/browser/service_worker/service_worker_storage.h"
11 #include "content/browser/service_worker/service_worker_version.h" 11 #include "content/browser/service_worker/service_worker_version.h"
12 #include "content/browser/service_worker/service_worker_write_to_cache_job.h" 12 #include "content/browser/service_worker/service_worker_write_to_cache_job.h"
13 #include "net/url_request/url_request.h" 13 #include "net/url_request/url_request.h"
14 14
15 namespace content { 15 namespace content {
16 16
17 ServiceWorkerContextRequestHandler::ServiceWorkerContextRequestHandler( 17 ServiceWorkerContextRequestHandler::ServiceWorkerContextRequestHandler(
18 base::WeakPtr<ServiceWorkerContextCore> context, 18 base::WeakPtr<ServiceWorkerContextCore> context,
19 base::WeakPtr<ServiceWorkerProviderHost> provider_host, 19 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
20 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context, 20 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context,
21 ResourceType::Type resource_type) 21 ResourceType resource_type)
22 : ServiceWorkerRequestHandler(context, 22 : ServiceWorkerRequestHandler(context,
23 provider_host, 23 provider_host,
24 blob_storage_context, 24 blob_storage_context,
25 resource_type), 25 resource_type),
26 version_(provider_host_->running_hosted_version()) { 26 version_(provider_host_->running_hosted_version()) {
27 DCHECK(provider_host_->IsHostToRunningServiceWorker()); 27 DCHECK(provider_host_->IsHostToRunningServiceWorker());
28 } 28 }
29 29
30 ServiceWorkerContextRequestHandler::~ServiceWorkerContextRequestHandler() { 30 ServiceWorkerContextRequestHandler::~ServiceWorkerContextRequestHandler() {
31 } 31 }
32 32
33 net::URLRequestJob* ServiceWorkerContextRequestHandler::MaybeCreateJob( 33 net::URLRequestJob* ServiceWorkerContextRequestHandler::MaybeCreateJob(
34 net::URLRequest* request, 34 net::URLRequest* request,
35 net::NetworkDelegate* network_delegate) { 35 net::NetworkDelegate* network_delegate) {
36 if (!provider_host_ || !version_ || !context_) 36 if (!provider_host_ || !version_ || !context_)
37 return NULL; 37 return NULL;
38 38
39 // We currently have no use case for hijacking a redirected request. 39 // We currently have no use case for hijacking a redirected request.
40 if (request->url_chain().size() > 1) 40 if (request->url_chain().size() > 1)
41 return NULL; 41 return NULL;
42 42
43 // We only use the script cache for main script loading and 43 // We only use the script cache for main script loading and
44 // importScripts(), even if a cached script is xhr'd, we don't 44 // importScripts(), even if a cached script is xhr'd, we don't
45 // retrieve it from the script cache. 45 // retrieve it from the script cache.
46 // TODO(michaeln): Get the desired behavior clarified in the spec, 46 // TODO(michaeln): Get the desired behavior clarified in the spec,
47 // and make tweak the behavior here to match. 47 // and make tweak the behavior here to match.
48 if (resource_type_ != ResourceType::SERVICE_WORKER && 48 if (resource_type_ != RESOURCE_TYPE_SERVICE_WORKER &&
49 resource_type_ != ResourceType::SCRIPT) { 49 resource_type_ != RESOURCE_TYPE_SCRIPT) {
50 return NULL; 50 return NULL;
51 } 51 }
52 52
53 if (ShouldAddToScriptCache(request->url())) { 53 if (ShouldAddToScriptCache(request->url())) {
54 int64 response_id = context_->storage()->NewResourceId(); 54 int64 response_id = context_->storage()->NewResourceId();
55 if (response_id == kInvalidServiceWorkerResponseId) 55 if (response_id == kInvalidServiceWorkerResponseId)
56 return NULL; 56 return NULL;
57 return new ServiceWorkerWriteToCacheJob(request, 57 return new ServiceWorkerWriteToCacheJob(request,
58 network_delegate, 58 network_delegate,
59 resource_type_, 59 resource_type_,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 const GURL& url, int64* response_id_out) { 94 const GURL& url, int64* response_id_out) {
95 // We don't read from the script cache until the version is INSTALLED. 95 // We don't read from the script cache until the version is INSTALLED.
96 if (version_->status() == ServiceWorkerVersion::NEW || 96 if (version_->status() == ServiceWorkerVersion::NEW ||
97 version_->status() == ServiceWorkerVersion::INSTALLING) 97 version_->status() == ServiceWorkerVersion::INSTALLING)
98 return false; 98 return false;
99 *response_id_out = version_->script_cache_map()->Lookup(url); 99 *response_id_out = version_->script_cache_map()->Lookup(url);
100 return *response_id_out != kInvalidServiceWorkerResponseId; 100 return *response_id_out != kInvalidServiceWorkerResponseId;
101 } 101 }
102 102
103 } // namespace content 103 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698