| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 URLRequestJob* URLRequestJobManager::CreateJob(URLRequest* request) const { | 53 URLRequestJob* URLRequestJobManager::CreateJob(URLRequest* request) const { |
| 54 #ifndef NDEBUG | 54 #ifndef NDEBUG |
| 55 DCHECK(IsAllowedThread()); | 55 DCHECK(IsAllowedThread()); |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 // If we are given an invalid URL, then don't even try to inspect the scheme. | 58 // If we are given an invalid URL, then don't even try to inspect the scheme. |
| 59 if (!request->url().is_valid()) | 59 if (!request->url().is_valid()) |
| 60 return new URLRequestErrorJob(request, net::ERR_INVALID_URL); | 60 return new URLRequestErrorJob(request, net::ERR_INVALID_URL); |
| 61 | 61 |
| 62 // We do this here to avoid asking interceptors about unsupported schemes. |
| 62 const std::string& scheme = request->url().scheme(); // already lowercase | 63 const std::string& scheme = request->url().scheme(); // already lowercase |
| 63 | |
| 64 // We do this here to avoid asking interceptors about unsupported schemes. | |
| 65 if (!SupportsScheme(scheme)) | 64 if (!SupportsScheme(scheme)) |
| 66 return new URLRequestErrorJob(request, net::ERR_UNKNOWN_URL_SCHEME); | 65 return new URLRequestErrorJob(request, net::ERR_UNKNOWN_URL_SCHEME); |
| 67 | 66 |
| 68 // THREAD-SAFETY NOTICE: | 67 // THREAD-SAFETY NOTICE: |
| 69 // We do not need to acquire the lock here since we are only reading our | 68 // We do not need to acquire the lock here since we are only reading our |
| 70 // data structures. They should only be modified on the current thread. | 69 // data structures. They should only be modified on the current thread. |
| 71 | 70 |
| 72 // See if the request should be intercepted. | 71 // See if the request should be intercepted. |
| 73 if (!(request->load_flags() & net::LOAD_DISABLE_INTERCEPT)) { | 72 if (!(request->load_flags() & net::LOAD_DISABLE_INTERCEPT)) { |
| 74 InterceptorList::const_iterator i; | 73 InterceptorList::const_iterator i; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 97 return job; | 96 return job; |
| 98 } | 97 } |
| 99 } | 98 } |
| 100 | 99 |
| 101 // If we reached here, then it means that a registered protocol factory | 100 // If we reached here, then it means that a registered protocol factory |
| 102 // wasn't interested in handling the URL. That is fairly unexpected, and we | 101 // wasn't interested in handling the URL. That is fairly unexpected, and we |
| 103 // don't know have a specific error to report here :-( | 102 // don't know have a specific error to report here :-( |
| 104 return new URLRequestErrorJob(request, net::ERR_FAILED); | 103 return new URLRequestErrorJob(request, net::ERR_FAILED); |
| 105 } | 104 } |
| 106 | 105 |
| 106 URLRequestJob* URLRequestJobManager::MaybeInterceptRedirect( |
| 107 URLRequest* request, |
| 108 const GURL& location) const { |
| 109 #ifndef NDEBUG |
| 110 DCHECK(IsAllowedThread()); |
| 111 #endif |
| 112 if ((request->load_flags() & net::LOAD_DISABLE_INTERCEPT) || |
| 113 (request->status().status() == URLRequestStatus::CANCELED) || |
| 114 !request->url().is_valid() || |
| 115 !SupportsScheme(request->url().scheme())) |
| 116 return NULL; |
| 117 |
| 118 InterceptorList::const_iterator i; |
| 119 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { |
| 120 URLRequestJob* job = (*i)->MaybeInterceptRedirect(request, location); |
| 121 if (job) |
| 122 return job; |
| 123 } |
| 124 return NULL; |
| 125 } |
| 126 |
| 127 URLRequestJob* URLRequestJobManager::MaybeInterceptResponse( |
| 128 URLRequest* request) const { |
| 129 #ifndef NDEBUG |
| 130 DCHECK(IsAllowedThread()); |
| 131 #endif |
| 132 if ((request->load_flags() & net::LOAD_DISABLE_INTERCEPT) || |
| 133 (request->status().status() == URLRequestStatus::CANCELED) || |
| 134 !request->url().is_valid() || |
| 135 !SupportsScheme(request->url().scheme())) |
| 136 return NULL; |
| 137 |
| 138 InterceptorList::const_iterator i; |
| 139 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { |
| 140 URLRequestJob* job = (*i)->MaybeInterceptResponse(request); |
| 141 if (job) |
| 142 return job; |
| 143 } |
| 144 return NULL; |
| 145 } |
| 146 |
| 107 bool URLRequestJobManager::SupportsScheme(const std::string& scheme) const { | 147 bool URLRequestJobManager::SupportsScheme(const std::string& scheme) const { |
| 108 // The set of registered factories may change on another thread. | 148 // The set of registered factories may change on another thread. |
| 109 { | 149 { |
| 110 AutoLock locked(lock_); | 150 AutoLock locked(lock_); |
| 111 if (factories_.find(scheme) != factories_.end()) | 151 if (factories_.find(scheme) != factories_.end()) |
| 112 return true; | 152 return true; |
| 113 } | 153 } |
| 114 | 154 |
| 115 for (size_t i = 0; i < arraysize(kBuiltinFactories); ++i) | 155 for (size_t i = 0; i < arraysize(kBuiltinFactories); ++i) |
| 116 if (LowerCaseEqualsASCII(scheme, kBuiltinFactories[i].scheme)) | 156 if (LowerCaseEqualsASCII(scheme, kBuiltinFactories[i].scheme)) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 DCHECK(IsAllowedThread()); | 202 DCHECK(IsAllowedThread()); |
| 163 #endif | 203 #endif |
| 164 | 204 |
| 165 AutoLock locked(lock_); | 205 AutoLock locked(lock_); |
| 166 | 206 |
| 167 InterceptorList::iterator i = | 207 InterceptorList::iterator i = |
| 168 std::find(interceptors_.begin(), interceptors_.end(), interceptor); | 208 std::find(interceptors_.begin(), interceptors_.end(), interceptor); |
| 169 DCHECK(i != interceptors_.end()); | 209 DCHECK(i != interceptors_.end()); |
| 170 interceptors_.erase(i); | 210 interceptors_.erase(i); |
| 171 } | 211 } |
| OLD | NEW |