| 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 <utility> |
| 8 |
| 7 #include "base/debug/crash_logging.h" | 9 #include "base/debug/crash_logging.h" |
| 8 #include "content/browser/appcache/appcache_backend_impl.h" | 10 #include "content/browser/appcache/appcache_backend_impl.h" |
| 9 #include "content/browser/appcache/appcache_host.h" | 11 #include "content/browser/appcache/appcache_host.h" |
| 10 #include "content/browser/appcache/appcache_request_handler.h" | 12 #include "content/browser/appcache/appcache_request_handler.h" |
| 11 #include "content/browser/appcache/appcache_service_impl.h" | 13 #include "content/browser/appcache/appcache_service_impl.h" |
| 12 #include "content/browser/appcache/appcache_url_request_job.h" | 14 #include "content/browser/appcache/appcache_url_request_job.h" |
| 13 #include "content/browser/appcache/chrome_appcache_service.h" | 15 #include "content/browser/appcache/chrome_appcache_service.h" |
| 14 #include "content/browser/bad_message.h" | 16 #include "content/browser/bad_message.h" |
| 15 #include "content/browser/loader/resource_message_filter.h" | 17 #include "content/browser/loader/resource_message_filter.h" |
| 16 #include "content/browser/loader/resource_requester_info.h" | 18 #include "content/browser/loader/resource_requester_info.h" |
| 17 #include "content/common/appcache_interfaces.h" | 19 #include "content/common/appcache_interfaces.h" |
| 18 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
| 19 | 21 |
| 20 static int kHandlerKey; // Value is not used. | 22 static int kHandlerKey; // Value is not used. |
| 21 | 23 |
| 22 namespace content { | 24 namespace content { |
| 23 | 25 |
| 24 void AppCacheInterceptor::SetHandler(net::URLRequest* request, | 26 void AppCacheInterceptor::SetHandler( |
| 25 AppCacheRequestHandler* handler) { | 27 net::URLRequest* request, |
| 26 request->SetUserData(&kHandlerKey, handler); // request takes ownership | 28 std::unique_ptr<AppCacheRequestHandler> handler) { |
| 29 request->SetUserData(&kHandlerKey, std::move(handler)); |
| 27 } | 30 } |
| 28 | 31 |
| 29 AppCacheRequestHandler* AppCacheInterceptor::GetHandler( | 32 AppCacheRequestHandler* AppCacheInterceptor::GetHandler( |
| 30 net::URLRequest* request) { | 33 net::URLRequest* request) { |
| 31 return static_cast<AppCacheRequestHandler*>( | 34 return static_cast<AppCacheRequestHandler*>( |
| 32 request->GetUserData(&kHandlerKey)); | 35 request->GetUserData(&kHandlerKey)); |
| 33 } | 36 } |
| 34 | 37 |
| 35 void AppCacheInterceptor::SetExtraRequestInfo(net::URLRequest* request, | 38 void AppCacheInterceptor::SetExtraRequestInfo(net::URLRequest* request, |
| 36 AppCacheServiceImpl* service, | 39 AppCacheServiceImpl* service, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 54 SetExtraRequestInfoForHost(request, host, resource_type, | 57 SetExtraRequestInfoForHost(request, host, resource_type, |
| 55 should_reset_appcache); | 58 should_reset_appcache); |
| 56 } | 59 } |
| 57 | 60 |
| 58 void AppCacheInterceptor::SetExtraRequestInfoForHost( | 61 void AppCacheInterceptor::SetExtraRequestInfoForHost( |
| 59 net::URLRequest* request, | 62 net::URLRequest* request, |
| 60 AppCacheHost* host, | 63 AppCacheHost* host, |
| 61 ResourceType resource_type, | 64 ResourceType resource_type, |
| 62 bool should_reset_appcache) { | 65 bool should_reset_appcache) { |
| 63 // Create a handler for this request and associate it with the request. | 66 // Create a handler for this request and associate it with the request. |
| 64 AppCacheRequestHandler* handler = | 67 std::unique_ptr<AppCacheRequestHandler> handler = |
| 65 host->CreateRequestHandler(request, resource_type, should_reset_appcache); | 68 host->CreateRequestHandler(request, resource_type, should_reset_appcache); |
| 66 if (handler) | 69 if (handler) |
| 67 SetHandler(request, handler); | 70 SetHandler(request, std::move(handler)); |
| 68 } | 71 } |
| 69 | 72 |
| 70 void AppCacheInterceptor::GetExtraResponseInfo(net::URLRequest* request, | 73 void AppCacheInterceptor::GetExtraResponseInfo(net::URLRequest* request, |
| 71 int64_t* cache_id, | 74 int64_t* cache_id, |
| 72 GURL* manifest_url) { | 75 GURL* manifest_url) { |
| 73 DCHECK(*cache_id == kAppCacheNoCacheId); | 76 DCHECK(*cache_id == kAppCacheNoCacheId); |
| 74 DCHECK(manifest_url->is_empty()); | 77 DCHECK(manifest_url->is_empty()); |
| 75 AppCacheRequestHandler* handler = GetHandler(request); | 78 AppCacheRequestHandler* handler = GetHandler(request); |
| 76 if (handler) | 79 if (handler) |
| 77 handler->GetExtraResponseInfo(cache_id, manifest_url); | 80 handler->GetExtraResponseInfo(cache_id, manifest_url); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 157 |
| 155 net::URLRequestJob* AppCacheInterceptor::MaybeInterceptResponse( | 158 net::URLRequestJob* AppCacheInterceptor::MaybeInterceptResponse( |
| 156 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { | 159 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { |
| 157 AppCacheRequestHandler* handler = GetHandler(request); | 160 AppCacheRequestHandler* handler = GetHandler(request); |
| 158 if (!handler) | 161 if (!handler) |
| 159 return NULL; | 162 return NULL; |
| 160 return handler->MaybeLoadFallbackForResponse(request, network_delegate); | 163 return handler->MaybeLoadFallbackForResponse(request, network_delegate); |
| 161 } | 164 } |
| 162 | 165 |
| 163 } // namespace content | 166 } // namespace content |
| OLD | NEW |