| 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 class AppCacheInterceptor::StartInterceptor |
| 17 : public net::URLRequestInterceptor { |
| 18 public: |
| 19 StartInterceptor() {} |
| 20 virtual ~StartInterceptor() {} |
| 21 virtual net::URLRequestJob* MaybeInterceptRequest( |
| 22 net::URLRequest* request, |
| 23 net::NetworkDelegate* network_delegate) const override { |
| 24 AppCacheRequestHandler* handler = GetHandler(request); |
| 25 if (!handler) |
| 26 return NULL; |
| 27 return handler->MaybeLoadResource(request, network_delegate); |
| 28 } |
| 29 |
| 30 private: |
| 31 DISALLOW_COPY_AND_ASSIGN(StartInterceptor); |
| 32 }; |
| 33 |
| 34 |
| 16 // static | 35 // static |
| 17 AppCacheInterceptor* AppCacheInterceptor::GetInstance() { | 36 AppCacheInterceptor* AppCacheInterceptor::GetInstance() { |
| 18 return Singleton<AppCacheInterceptor>::get(); | 37 return Singleton<AppCacheInterceptor>::get(); |
| 19 } | 38 } |
| 20 | 39 |
| 40 // static |
| 41 scoped_ptr<net::URLRequestInterceptor> |
| 42 AppCacheInterceptor::CreateStartInterceptor() { |
| 43 return scoped_ptr<net::URLRequestInterceptor>( |
| 44 new StartInterceptor); |
| 45 } |
| 46 |
| 21 void AppCacheInterceptor::SetHandler(net::URLRequest* request, | 47 void AppCacheInterceptor::SetHandler(net::URLRequest* request, |
| 22 AppCacheRequestHandler* handler) { | 48 AppCacheRequestHandler* handler) { |
| 23 request->SetUserData(GetInstance(), handler); // request takes ownership | 49 request->SetUserData(GetInstance(), handler); // request takes ownership |
| 24 } | 50 } |
| 25 | 51 |
| 26 AppCacheRequestHandler* AppCacheInterceptor::GetHandler( | 52 AppCacheRequestHandler* AppCacheInterceptor::GetHandler( |
| 27 net::URLRequest* request) { | 53 net::URLRequest* request) { |
| 28 return static_cast<AppCacheRequestHandler*>( | 54 return static_cast<AppCacheRequestHandler*>( |
| 29 request->GetUserData(GetInstance())); | 55 request->GetUserData(GetInstance())); |
| 30 } | 56 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 AppCacheInterceptor::AppCacheInterceptor() { | 115 AppCacheInterceptor::AppCacheInterceptor() { |
| 90 net::URLRequest::Deprecated::RegisterRequestInterceptor(this); | 116 net::URLRequest::Deprecated::RegisterRequestInterceptor(this); |
| 91 } | 117 } |
| 92 | 118 |
| 93 AppCacheInterceptor::~AppCacheInterceptor() { | 119 AppCacheInterceptor::~AppCacheInterceptor() { |
| 94 net::URLRequest::Deprecated::UnregisterRequestInterceptor(this); | 120 net::URLRequest::Deprecated::UnregisterRequestInterceptor(this); |
| 95 } | 121 } |
| 96 | 122 |
| 97 net::URLRequestJob* AppCacheInterceptor::MaybeIntercept( | 123 net::URLRequestJob* AppCacheInterceptor::MaybeIntercept( |
| 98 net::URLRequest* request, net::NetworkDelegate* network_delegate) { | 124 net::URLRequest* request, net::NetworkDelegate* network_delegate) { |
| 99 AppCacheRequestHandler* handler = GetHandler(request); | 125 // Intentionally empty, handled by class StartInterceptor. |
| 100 if (!handler) | 126 return NULL; |
| 101 return NULL; | |
| 102 return handler->MaybeLoadResource(request, network_delegate); | |
| 103 } | 127 } |
| 104 | 128 |
| 105 net::URLRequestJob* AppCacheInterceptor::MaybeInterceptRedirect( | 129 net::URLRequestJob* AppCacheInterceptor::MaybeInterceptRedirect( |
| 106 net::URLRequest* request, | 130 net::URLRequest* request, |
| 107 net::NetworkDelegate* network_delegate, | 131 net::NetworkDelegate* network_delegate, |
| 108 const GURL& location) { | 132 const GURL& location) { |
| 109 AppCacheRequestHandler* handler = GetHandler(request); | 133 AppCacheRequestHandler* handler = GetHandler(request); |
| 110 if (!handler) | 134 if (!handler) |
| 111 return NULL; | 135 return NULL; |
| 112 return handler->MaybeLoadFallbackForRedirect( | 136 return handler->MaybeLoadFallbackForRedirect( |
| 113 request, network_delegate, location); | 137 request, network_delegate, location); |
| 114 } | 138 } |
| 115 | 139 |
| 116 net::URLRequestJob* AppCacheInterceptor::MaybeInterceptResponse( | 140 net::URLRequestJob* AppCacheInterceptor::MaybeInterceptResponse( |
| 117 net::URLRequest* request, net::NetworkDelegate* network_delegate) { | 141 net::URLRequest* request, net::NetworkDelegate* network_delegate) { |
| 118 AppCacheRequestHandler* handler = GetHandler(request); | 142 AppCacheRequestHandler* handler = GetHandler(request); |
| 119 if (!handler) | 143 if (!handler) |
| 120 return NULL; | 144 return NULL; |
| 121 return handler->MaybeLoadFallbackForResponse(request, network_delegate); | 145 return handler->MaybeLoadFallbackForResponse(request, network_delegate); |
| 122 } | 146 } |
| 123 | 147 |
| 124 } // namespace content | 148 } // namespace content |
| OLD | NEW |