OLD | NEW |
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_request_handler.h" | 5 #include "content/browser/service_worker/service_worker_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_context_wrapper.h" | 8 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
9 #include "content/browser/service_worker/service_worker_provider_host.h" | 9 #include "content/browser/service_worker/service_worker_provider_host.h" |
10 #include "content/browser/service_worker/service_worker_registration.h" | 10 #include "content/browser/service_worker/service_worker_registration.h" |
11 #include "content/browser/service_worker/service_worker_url_request_job.h" | 11 #include "content/browser/service_worker/service_worker_url_request_job.h" |
12 #include "content/browser/service_worker/service_worker_utils.h" | 12 #include "content/browser/service_worker/service_worker_utils.h" |
13 #include "content/common/service_worker/service_worker_types.h" | 13 #include "content/common/service_worker/service_worker_types.h" |
14 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
| 15 #include "net/url_request/url_request_interceptor.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 int kUserDataKey; // Key value is not important. | 21 int kUserDataKey; // Key value is not important. |
21 | 22 |
22 class ServiceWorkerRequestInterceptor | 23 class ServiceWorkerRequestInterceptor |
23 : public net::URLRequestJobFactory::ProtocolHandler { | 24 : public net::URLRequestInterceptor { |
24 public: | 25 public: |
25 ServiceWorkerRequestInterceptor() {} | 26 ServiceWorkerRequestInterceptor() {} |
26 virtual ~ServiceWorkerRequestInterceptor() {} | 27 virtual ~ServiceWorkerRequestInterceptor() {} |
27 virtual net::URLRequestJob* MaybeCreateJob( | 28 virtual net::URLRequestJob* MaybeInterceptRequest( |
28 net::URLRequest* request, | 29 net::URLRequest* request, |
29 net::NetworkDelegate* network_delegate) const OVERRIDE { | 30 net::NetworkDelegate* network_delegate) const OVERRIDE { |
30 ServiceWorkerRequestHandler* handler = | 31 ServiceWorkerRequestHandler* handler = |
31 ServiceWorkerRequestHandler::GetHandler(request); | 32 ServiceWorkerRequestHandler::GetHandler(request); |
32 if (!handler) | 33 if (!handler) |
33 return NULL; | 34 return NULL; |
34 return handler->MaybeCreateJob(request, network_delegate); | 35 return handler->MaybeCreateJob(request, network_delegate); |
35 } | 36 } |
36 | 37 |
37 private: | 38 private: |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 78 |
78 request->SetUserData(&kUserDataKey, handler.release()); | 79 request->SetUserData(&kUserDataKey, handler.release()); |
79 } | 80 } |
80 | 81 |
81 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( | 82 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( |
82 net::URLRequest* request) { | 83 net::URLRequest* request) { |
83 return reinterpret_cast<ServiceWorkerRequestHandler*>( | 84 return reinterpret_cast<ServiceWorkerRequestHandler*>( |
84 request->GetUserData(&kUserDataKey)); | 85 request->GetUserData(&kUserDataKey)); |
85 } | 86 } |
86 | 87 |
87 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | 88 scoped_ptr<net::URLRequestInterceptor> |
88 ServiceWorkerRequestHandler::CreateInterceptor() { | 89 ServiceWorkerRequestHandler::CreateInterceptor() { |
89 return make_scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>( | 90 return scoped_ptr<net::URLRequestInterceptor>( |
90 new ServiceWorkerRequestInterceptor); | 91 new ServiceWorkerRequestInterceptor); |
91 } | 92 } |
92 | 93 |
93 ServiceWorkerRequestHandler::~ServiceWorkerRequestHandler() { | 94 ServiceWorkerRequestHandler::~ServiceWorkerRequestHandler() { |
94 } | 95 } |
95 | 96 |
96 ServiceWorkerRequestHandler::ServiceWorkerRequestHandler( | 97 ServiceWorkerRequestHandler::ServiceWorkerRequestHandler( |
97 base::WeakPtr<ServiceWorkerContextCore> context, | 98 base::WeakPtr<ServiceWorkerContextCore> context, |
98 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 99 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
99 ResourceType::Type resource_type) | 100 ResourceType::Type resource_type) |
100 : context_(context), | 101 : context_(context), |
101 provider_host_(provider_host), | 102 provider_host_(provider_host), |
102 resource_type_(resource_type) { | 103 resource_type_(resource_type) { |
103 } | 104 } |
104 | 105 |
105 } // namespace content | 106 } // namespace content |
OLD | NEW |