| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/url_request/url_request_job_manager.h" | 5 #include "net/url_request/url_request_job_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 // If we are given an invalid URL, then don't even try to inspect the scheme. | 51 // If we are given an invalid URL, then don't even try to inspect the scheme. |
| 52 if (!request->url().is_valid()) | 52 if (!request->url().is_valid()) |
| 53 return new URLRequestErrorJob(request, network_delegate, ERR_INVALID_URL); | 53 return new URLRequestErrorJob(request, network_delegate, ERR_INVALID_URL); |
| 54 | 54 |
| 55 // We do this here to avoid asking interceptors about unsupported schemes. | 55 // We do this here to avoid asking interceptors about unsupported schemes. |
| 56 const URLRequestJobFactory* job_factory = NULL; | 56 const URLRequestJobFactory* job_factory = NULL; |
| 57 job_factory = request->context()->job_factory(); | 57 job_factory = request->context()->job_factory(); |
| 58 | 58 |
| 59 const std::string& scheme = request->url().scheme(); // already lowercase | 59 const std::string& scheme = request->url().scheme(); // already lowercase |
| 60 if (job_factory) { | 60 if (!job_factory->IsHandledProtocol(scheme)) { |
| 61 if (!job_factory->IsHandledProtocol(scheme)) { | |
| 62 return new URLRequestErrorJob( | |
| 63 request, network_delegate, ERR_UNKNOWN_URL_SCHEME); | |
| 64 } | |
| 65 } else if (!SupportsScheme(scheme)) { | |
| 66 return new URLRequestErrorJob( | 61 return new URLRequestErrorJob( |
| 67 request, network_delegate, ERR_UNKNOWN_URL_SCHEME); | 62 request, network_delegate, ERR_UNKNOWN_URL_SCHEME); |
| 68 } | 63 } |
| 69 | 64 |
| 70 // THREAD-SAFETY NOTICE: | 65 // THREAD-SAFETY NOTICE: |
| 71 // We do not need to acquire the lock here since we are only reading our | 66 // We do not need to acquire the lock here since we are only reading our |
| 72 // data structures. They should only be modified on the current thread. | 67 // data structures. They should only be modified on the current thread. |
| 73 | 68 |
| 74 // See if the request should be intercepted. | 69 // See if the request should be intercepted. |
| 75 // | 70 // |
| 76 | 71 |
| 77 // TODO(pauljensen): Remove this when AppCacheInterceptor is a | 72 // TODO(pauljensen): Remove this when AppCacheInterceptor is a |
| 78 // ProtocolHandler, see crbug.com/161547. | 73 // ProtocolHandler, see crbug.com/161547. |
| 79 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { | 74 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { |
| 80 InterceptorList::const_iterator i; | 75 InterceptorList::const_iterator i; |
| 81 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { | 76 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { |
| 82 URLRequestJob* job = (*i)->MaybeIntercept(request, network_delegate); | 77 URLRequestJob* job = (*i)->MaybeIntercept(request, network_delegate); |
| 83 if (job) | 78 if (job) |
| 84 return job; | 79 return job; |
| 85 } | 80 } |
| 86 } | 81 } |
| 87 | 82 |
| 88 if (job_factory) { | 83 URLRequestJob* job = job_factory->MaybeCreateJobWithProtocolHandler( |
| 89 URLRequestJob* job = job_factory->MaybeCreateJobWithProtocolHandler( | 84 scheme, request, network_delegate); |
| 90 scheme, request, network_delegate); | 85 if (job) |
| 91 if (job) | 86 return job; |
| 92 return job; | |
| 93 } | |
| 94 | 87 |
| 95 // See if the request should be handled by a built-in protocol factory. | 88 // See if the request should be handled by a built-in protocol factory. |
| 96 for (size_t i = 0; i < arraysize(kBuiltinFactories); ++i) { | 89 for (size_t i = 0; i < arraysize(kBuiltinFactories); ++i) { |
| 97 if (scheme == kBuiltinFactories[i].scheme) { | 90 if (scheme == kBuiltinFactories[i].scheme) { |
| 98 URLRequestJob* job = (kBuiltinFactories[i].factory)( | 91 URLRequestJob* job = (kBuiltinFactories[i].factory)( |
| 99 request, network_delegate, scheme); | 92 request, network_delegate, scheme); |
| 100 DCHECK(job); // The built-in factories are not expected to fail! | 93 DCHECK(job); // The built-in factories are not expected to fail! |
| 101 return job; | 94 return job; |
| 102 } | 95 } |
| 103 } | 96 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 117 if (!request->url().is_valid() || | 110 if (!request->url().is_valid() || |
| 118 request->load_flags() & LOAD_DISABLE_INTERCEPT || | 111 request->load_flags() & LOAD_DISABLE_INTERCEPT || |
| 119 request->status().status() == URLRequestStatus::CANCELED) { | 112 request->status().status() == URLRequestStatus::CANCELED) { |
| 120 return NULL; | 113 return NULL; |
| 121 } | 114 } |
| 122 | 115 |
| 123 const URLRequestJobFactory* job_factory = NULL; | 116 const URLRequestJobFactory* job_factory = NULL; |
| 124 job_factory = request->context()->job_factory(); | 117 job_factory = request->context()->job_factory(); |
| 125 | 118 |
| 126 const std::string& scheme = request->url().scheme(); // already lowercase | 119 const std::string& scheme = request->url().scheme(); // already lowercase |
| 127 if (job_factory) { | 120 if (!job_factory->IsHandledProtocol(scheme)) |
| 128 if (!job_factory->IsHandledProtocol(scheme)) { | |
| 129 return NULL; | |
| 130 } | |
| 131 } else if (!SupportsScheme(scheme)) { | |
| 132 return NULL; | 121 return NULL; |
| 133 } | |
| 134 | 122 |
| 135 InterceptorList::const_iterator i; | 123 InterceptorList::const_iterator i; |
| 136 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { | 124 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { |
| 137 URLRequestJob* job = (*i)->MaybeInterceptRedirect(request, | 125 URLRequestJob* job = (*i)->MaybeInterceptRedirect(request, |
| 138 network_delegate, | 126 network_delegate, |
| 139 location); | 127 location); |
| 140 if (job) | 128 if (job) |
| 141 return job; | 129 return job; |
| 142 } | 130 } |
| 143 return NULL; | 131 return NULL; |
| 144 } | 132 } |
| 145 | 133 |
| 146 URLRequestJob* URLRequestJobManager::MaybeInterceptResponse( | 134 URLRequestJob* URLRequestJobManager::MaybeInterceptResponse( |
| 147 URLRequest* request, NetworkDelegate* network_delegate) const { | 135 URLRequest* request, NetworkDelegate* network_delegate) const { |
| 148 DCHECK(IsAllowedThread()); | 136 DCHECK(IsAllowedThread()); |
| 149 if (!request->url().is_valid() || | 137 if (!request->url().is_valid() || |
| 150 request->load_flags() & LOAD_DISABLE_INTERCEPT || | 138 request->load_flags() & LOAD_DISABLE_INTERCEPT || |
| 151 request->status().status() == URLRequestStatus::CANCELED) { | 139 request->status().status() == URLRequestStatus::CANCELED) { |
| 152 return NULL; | 140 return NULL; |
| 153 } | 141 } |
| 154 | 142 |
| 155 const URLRequestJobFactory* job_factory = NULL; | 143 const URLRequestJobFactory* job_factory = NULL; |
| 156 job_factory = request->context()->job_factory(); | 144 job_factory = request->context()->job_factory(); |
| 157 | 145 |
| 158 const std::string& scheme = request->url().scheme(); // already lowercase | 146 const std::string& scheme = request->url().scheme(); // already lowercase |
| 159 if (job_factory) { | 147 if (!job_factory->IsHandledProtocol(scheme)) |
| 160 if (!job_factory->IsHandledProtocol(scheme)) { | |
| 161 return NULL; | |
| 162 } | |
| 163 } else if (!SupportsScheme(scheme)) { | |
| 164 return NULL; | 148 return NULL; |
| 165 } | |
| 166 | 149 |
| 167 InterceptorList::const_iterator i; | 150 InterceptorList::const_iterator i; |
| 168 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { | 151 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { |
| 169 URLRequestJob* job = (*i)->MaybeInterceptResponse(request, | 152 URLRequestJob* job = (*i)->MaybeInterceptResponse(request, |
| 170 network_delegate); | 153 network_delegate); |
| 171 if (job) | 154 if (job) |
| 172 return job; | 155 return job; |
| 173 } | 156 } |
| 174 return NULL; | 157 return NULL; |
| 175 } | 158 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 } | 191 } |
| 209 | 192 |
| 210 URLRequestJobManager::URLRequestJobManager() | 193 URLRequestJobManager::URLRequestJobManager() |
| 211 : allowed_thread_(0), | 194 : allowed_thread_(0), |
| 212 allowed_thread_initialized_(false) { | 195 allowed_thread_initialized_(false) { |
| 213 } | 196 } |
| 214 | 197 |
| 215 URLRequestJobManager::~URLRequestJobManager() {} | 198 URLRequestJobManager::~URLRequestJobManager() {} |
| 216 | 199 |
| 217 } // namespace net | 200 } // namespace net |
| OLD | NEW |