OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 { "data", URLRequestDataJob::Factory }, | 42 { "data", URLRequestDataJob::Factory }, |
43 }; | 43 }; |
44 | 44 |
45 // static | 45 // static |
46 URLRequestJobManager* URLRequestJobManager::GetInstance() { | 46 URLRequestJobManager* URLRequestJobManager::GetInstance() { |
47 return Singleton<URLRequestJobManager>::get(); | 47 return Singleton<URLRequestJobManager>::get(); |
48 } | 48 } |
49 | 49 |
50 URLRequestJob* URLRequestJobManager::CreateJob( | 50 URLRequestJob* URLRequestJobManager::CreateJob( |
51 URLRequest* request) const { | 51 URLRequest* request) const { |
| 52 #ifndef NDEBUG |
52 DCHECK(IsAllowedThread()); | 53 DCHECK(IsAllowedThread()); |
| 54 #endif |
53 | 55 |
54 // If we are given an invalid URL, then don't even try to inspect the scheme. | 56 // If we are given an invalid URL, then don't even try to inspect the scheme. |
55 if (!request->url().is_valid()) | 57 if (!request->url().is_valid()) |
56 return new URLRequestErrorJob(request, ERR_INVALID_URL); | 58 return new URLRequestErrorJob(request, ERR_INVALID_URL); |
57 | 59 |
58 // We do this here to avoid asking interceptors about unsupported schemes. | 60 // We do this here to avoid asking interceptors about unsupported schemes. |
59 const URLRequestJobFactory* job_factory = NULL; | 61 const URLRequestJobFactory* job_factory = NULL; |
60 if (request->context()) | 62 if (request->context()) |
61 job_factory = request->context()->job_factory(); | 63 job_factory = request->context()->job_factory(); |
62 | 64 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // If we reached here, then it means that a registered protocol factory | 125 // If we reached here, then it means that a registered protocol factory |
124 // wasn't interested in handling the URL. That is fairly unexpected, and we | 126 // wasn't interested in handling the URL. That is fairly unexpected, and we |
125 // don't know have a specific error to report here :-( | 127 // don't know have a specific error to report here :-( |
126 LOG(WARNING) << "Failed to map: " << request->url().spec(); | 128 LOG(WARNING) << "Failed to map: " << request->url().spec(); |
127 return new URLRequestErrorJob(request, ERR_FAILED); | 129 return new URLRequestErrorJob(request, ERR_FAILED); |
128 } | 130 } |
129 | 131 |
130 URLRequestJob* URLRequestJobManager::MaybeInterceptRedirect( | 132 URLRequestJob* URLRequestJobManager::MaybeInterceptRedirect( |
131 URLRequest* request, | 133 URLRequest* request, |
132 const GURL& location) const { | 134 const GURL& location) const { |
| 135 #ifndef NDEBUG |
133 DCHECK(IsAllowedThread()); | 136 DCHECK(IsAllowedThread()); |
134 if (!request->url().is_valid() || | 137 #endif |
135 request->load_flags() & LOAD_DISABLE_INTERCEPT || | 138 if ((request->load_flags() & LOAD_DISABLE_INTERCEPT) || |
136 request->status().status() == URLRequestStatus::CANCELED) { | 139 (request->status().status() == URLRequestStatus::CANCELED) || |
| 140 !request->url().is_valid() || |
| 141 !SupportsScheme(request->url().scheme())) |
137 return NULL; | 142 return NULL; |
138 } | |
139 | |
140 const URLRequestJobFactory* job_factory = NULL; | |
141 if (request->context()) | |
142 job_factory = request->context()->job_factory(); | |
143 | |
144 const std::string& scheme = request->url().scheme(); // already lowercase | |
145 if (job_factory) { | |
146 if (!job_factory->IsHandledProtocol(scheme)) { | |
147 return NULL; | |
148 } | |
149 } else if (!SupportsScheme(scheme)) { | |
150 return NULL; | |
151 } | |
152 | |
153 URLRequestJob* job = NULL; | |
154 if (job_factory) | |
155 job = job_factory->MaybeInterceptRedirect(location, request); | |
156 if (job) | |
157 return job; | |
158 | 143 |
159 InterceptorList::const_iterator i; | 144 InterceptorList::const_iterator i; |
160 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { | 145 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { |
161 job = (*i)->MaybeInterceptRedirect(request, location); | 146 URLRequestJob* job = (*i)->MaybeInterceptRedirect(request, location); |
162 if (job) | 147 if (job) |
163 return job; | 148 return job; |
164 } | 149 } |
165 return NULL; | 150 return NULL; |
166 } | 151 } |
167 | 152 |
168 URLRequestJob* URLRequestJobManager::MaybeInterceptResponse( | 153 URLRequestJob* URLRequestJobManager::MaybeInterceptResponse( |
169 URLRequest* request) const { | 154 URLRequest* request) const { |
| 155 #ifndef NDEBUG |
170 DCHECK(IsAllowedThread()); | 156 DCHECK(IsAllowedThread()); |
171 if (!request->url().is_valid() || | 157 #endif |
172 request->load_flags() & LOAD_DISABLE_INTERCEPT || | 158 if ((request->load_flags() & LOAD_DISABLE_INTERCEPT) || |
173 request->status().status() == URLRequestStatus::CANCELED) { | 159 (request->status().status() == URLRequestStatus::CANCELED) || |
| 160 !request->url().is_valid() || |
| 161 !SupportsScheme(request->url().scheme())) |
174 return NULL; | 162 return NULL; |
175 } | |
176 | |
177 const URLRequestJobFactory* job_factory = NULL; | |
178 if (request->context()) | |
179 job_factory = request->context()->job_factory(); | |
180 | |
181 const std::string& scheme = request->url().scheme(); // already lowercase | |
182 if (job_factory) { | |
183 if (!job_factory->IsHandledProtocol(scheme)) { | |
184 return NULL; | |
185 } | |
186 } else if (!SupportsScheme(scheme)) { | |
187 return NULL; | |
188 } | |
189 | |
190 URLRequestJob* job = NULL; | |
191 if (job_factory) | |
192 job = job_factory->MaybeInterceptResponse(request); | |
193 if (job) | |
194 return job; | |
195 | 163 |
196 InterceptorList::const_iterator i; | 164 InterceptorList::const_iterator i; |
197 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { | 165 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { |
198 job = (*i)->MaybeInterceptResponse(request); | 166 URLRequestJob* job = (*i)->MaybeInterceptResponse(request); |
199 if (job) | 167 if (job) |
200 return job; | 168 return job; |
201 } | 169 } |
202 return NULL; | 170 return NULL; |
203 } | 171 } |
204 | 172 |
205 bool URLRequestJobManager::SupportsScheme(const std::string& scheme) const { | 173 bool URLRequestJobManager::SupportsScheme(const std::string& scheme) const { |
206 // The set of registered factories may change on another thread. | 174 // The set of registered factories may change on another thread. |
207 { | 175 { |
208 base::AutoLock locked(lock_); | 176 base::AutoLock locked(lock_); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 URLRequestJobManager::URLRequestJobManager() : enable_file_access_(false) { | 239 URLRequestJobManager::URLRequestJobManager() : enable_file_access_(false) { |
272 #ifndef NDEBUG | 240 #ifndef NDEBUG |
273 allowed_thread_ = 0; | 241 allowed_thread_ = 0; |
274 allowed_thread_initialized_ = false; | 242 allowed_thread_initialized_ = false; |
275 #endif | 243 #endif |
276 } | 244 } |
277 | 245 |
278 URLRequestJobManager::~URLRequestJobManager() {} | 246 URLRequestJobManager::~URLRequestJobManager() {} |
279 | 247 |
280 } // namespace net | 248 } // namespace net |
OLD | NEW |