| 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/appcache/appcache_interceptor.h" | 5 #include "content/browser/appcache/appcache_interceptor.h" |
| 6 | 6 |
| 7 #include "content/browser/appcache/appcache_backend_impl.h" | 7 #include "content/browser/appcache/appcache_backend_impl.h" |
| 8 #include "content/browser/appcache/appcache_host.h" | 8 #include "content/browser/appcache/appcache_host.h" |
| 9 #include "content/browser/appcache/appcache_request_handler.h" | 9 #include "content/browser/appcache/appcache_request_handler.h" |
| 10 #include "content/browser/appcache/appcache_service_impl.h" | 10 #include "content/browser/appcache/appcache_service_impl.h" |
| 11 #include "content/browser/appcache/appcache_url_request_job.h" | 11 #include "content/browser/appcache/appcache_url_request_job.h" |
| 12 #include "content/common/appcache_interfaces.h" | 12 #include "content/common/appcache_interfaces.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 // static | 16 // static |
| 17 AppCacheInterceptor* AppCacheInterceptor::GetInstance() { | 17 AppCacheInterceptor* AppCacheInterceptor::GetInstance() { |
| 18 return Singleton<AppCacheInterceptor>::get(); | 18 return Singleton<AppCacheInterceptor>::get(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 void AppCacheInterceptor::SetHandler( | 21 void AppCacheInterceptor::SetHandler(net::URLRequest* request, |
| 22 net::URLRequest* request, AppCacheRequestHandler* handler) { | 22 AppCacheRequestHandler* handler) { |
| 23 request->SetUserData(GetInstance(), handler); // request takes ownership | 23 request->SetUserData(GetInstance(), handler); // request takes ownership |
| 24 } | 24 } |
| 25 | 25 |
| 26 AppCacheRequestHandler* AppCacheInterceptor::GetHandler( | 26 AppCacheRequestHandler* AppCacheInterceptor::GetHandler( |
| 27 net::URLRequest* request) { | 27 net::URLRequest* request) { |
| 28 return reinterpret_cast<AppCacheRequestHandler*>( | 28 return reinterpret_cast<AppCacheRequestHandler*>( |
| 29 request->GetUserData(GetInstance())); | 29 request->GetUserData(GetInstance())); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void AppCacheInterceptor::SetExtraRequestInfo( | 32 void AppCacheInterceptor::SetExtraRequestInfo( |
| 33 net::URLRequest* request, AppCacheServiceImpl* service, int process_id, | 33 net::URLRequest* request, |
| 34 int host_id, ResourceType::Type resource_type) { | 34 AppCacheServiceImpl* service, |
| 35 int process_id, |
| 36 int host_id, |
| 37 ResourceType resource_type) { |
| 35 if (!service || (host_id == kAppCacheNoHostId)) | 38 if (!service || (host_id == kAppCacheNoHostId)) |
| 36 return; | 39 return; |
| 37 | 40 |
| 38 AppCacheBackendImpl* backend = service->GetBackend(process_id); | 41 AppCacheBackendImpl* backend = service->GetBackend(process_id); |
| 39 if (!backend) | 42 if (!backend) |
| 40 return; | 43 return; |
| 41 | 44 |
| 42 // TODO(michaeln): An invalid host id is indicative of bad data | 45 // TODO(michaeln): An invalid host id is indicative of bad data |
| 43 // from a child process. How should we handle that here? | 46 // from a child process. How should we handle that here? |
| 44 AppCacheHost* host = backend->GetHost(host_id); | 47 AppCacheHost* host = backend->GetHost(host_id); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 115 |
| 113 net::URLRequestJob* AppCacheInterceptor::MaybeInterceptResponse( | 116 net::URLRequestJob* AppCacheInterceptor::MaybeInterceptResponse( |
| 114 net::URLRequest* request, net::NetworkDelegate* network_delegate) { | 117 net::URLRequest* request, net::NetworkDelegate* network_delegate) { |
| 115 AppCacheRequestHandler* handler = GetHandler(request); | 118 AppCacheRequestHandler* handler = GetHandler(request); |
| 116 if (!handler) | 119 if (!handler) |
| 117 return NULL; | 120 return NULL; |
| 118 return handler->MaybeLoadFallbackForResponse(request, network_delegate); | 121 return handler->MaybeLoadFallbackForResponse(request, network_delegate); |
| 119 } | 122 } |
| 120 | 123 |
| 121 } // namespace content | 124 } // namespace content |
| OLD | NEW |