| 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 "base/debug/crash_logging.h" | 7 #include "base/debug/crash_logging.h" |
| 8 #include "content/browser/appcache/appcache_backend_impl.h" | 8 #include "content/browser/appcache/appcache_backend_impl.h" |
| 9 #include "content/browser/appcache/appcache_host.h" | 9 #include "content/browser/appcache/appcache_host.h" |
| 10 #include "content/browser/appcache/appcache_request_handler.h" | 10 #include "content/browser/appcache/appcache_request_handler.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 AppCacheRequestHandler* handler) { | 24 AppCacheRequestHandler* handler) { |
| 25 request->SetUserData(&kHandlerKey, handler); // request takes ownership | 25 request->SetUserData(&kHandlerKey, handler); // request takes ownership |
| 26 } | 26 } |
| 27 | 27 |
| 28 AppCacheRequestHandler* AppCacheInterceptor::GetHandler( | 28 AppCacheRequestHandler* AppCacheInterceptor::GetHandler( |
| 29 net::URLRequest* request) { | 29 net::URLRequest* request) { |
| 30 return static_cast<AppCacheRequestHandler*>( | 30 return static_cast<AppCacheRequestHandler*>( |
| 31 request->GetUserData(&kHandlerKey)); | 31 request->GetUserData(&kHandlerKey)); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void AppCacheInterceptor::SetExtraRequestInfo( | 34 void AppCacheInterceptor::SetExtraRequestInfo(net::URLRequest* request, |
| 35 net::URLRequest* request, | 35 AppCacheServiceImpl* service, |
| 36 AppCacheServiceImpl* service, | 36 int process_id, |
| 37 int process_id, | 37 int host_id, |
| 38 int host_id, | 38 ResourceType resource_type, |
| 39 ResourceType resource_type, | 39 bool should_reset_appcache) { |
| 40 bool should_reset_appcache) { | |
| 41 if (!service || (host_id == kAppCacheNoHostId)) | 40 if (!service || (host_id == kAppCacheNoHostId)) |
| 42 return; | 41 return; |
| 43 | 42 |
| 44 AppCacheBackendImpl* backend = service->GetBackend(process_id); | 43 AppCacheBackendImpl* backend = service->GetBackend(process_id); |
| 45 if (!backend) | 44 if (!backend) |
| 46 return; | 45 return; |
| 47 | 46 |
| 48 // TODO(michaeln): An invalid host id is indicative of bad data | 47 // TODO(michaeln): An invalid host id is indicative of bad data |
| 49 // from a child process. How should we handle that here? | 48 // from a child process. How should we handle that here? |
| 50 AppCacheHost* host = backend->GetHost(host_id); | 49 AppCacheHost* host = backend->GetHost(host_id); |
| 51 if (!host) | 50 if (!host) |
| 52 return; | 51 return; |
| 53 | 52 |
| 53 SetExtraRequestInfoForHost(request, host, resource_type, |
| 54 should_reset_appcache); |
| 55 } |
| 56 |
| 57 void AppCacheInterceptor::SetExtraRequestInfoForHost( |
| 58 net::URLRequest* request, |
| 59 AppCacheHost* host, |
| 60 ResourceType resource_type, |
| 61 bool should_reset_appcache) { |
| 54 // Create a handler for this request and associate it with the request. | 62 // Create a handler for this request and associate it with the request. |
| 55 AppCacheRequestHandler* handler = | 63 AppCacheRequestHandler* handler = |
| 56 host->CreateRequestHandler(request, resource_type, should_reset_appcache); | 64 host->CreateRequestHandler(request, |
| 65 resource_type, |
| 66 should_reset_appcache); |
| 57 if (handler) | 67 if (handler) |
| 58 SetHandler(request, handler); | 68 SetHandler(request, handler); |
| 59 } | 69 } |
| 60 | 70 |
| 61 void AppCacheInterceptor::GetExtraResponseInfo(net::URLRequest* request, | 71 void AppCacheInterceptor::GetExtraResponseInfo(net::URLRequest* request, |
| 62 int64_t* cache_id, | 72 int64_t* cache_id, |
| 63 GURL* manifest_url) { | 73 GURL* manifest_url) { |
| 64 DCHECK(*cache_id == kAppCacheNoCacheId); | 74 DCHECK(*cache_id == kAppCacheNoCacheId); |
| 65 DCHECK(manifest_url->is_empty()); | 75 DCHECK(manifest_url->is_empty()); |
| 66 AppCacheRequestHandler* handler = GetHandler(request); | 76 AppCacheRequestHandler* handler = GetHandler(request); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 153 |
| 144 net::URLRequestJob* AppCacheInterceptor::MaybeInterceptResponse( | 154 net::URLRequestJob* AppCacheInterceptor::MaybeInterceptResponse( |
| 145 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { | 155 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { |
| 146 AppCacheRequestHandler* handler = GetHandler(request); | 156 AppCacheRequestHandler* handler = GetHandler(request); |
| 147 if (!handler) | 157 if (!handler) |
| 148 return NULL; | 158 return NULL; |
| 149 return handler->MaybeLoadFallbackForResponse(request, network_delegate); | 159 return handler->MaybeLoadFallbackForResponse(request, network_delegate); |
| 150 } | 160 } |
| 151 | 161 |
| 152 } // namespace content | 162 } // namespace content |
| OLD | NEW |