Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: net/url_request/url_request_job_manager.cc

Issue 5384002: net: Remove typedef net::URLRequest URLRequest; (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "net/base/load_flags.h" 11 #include "net/base/load_flags.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/url_request/url_request_about_job.h" 13 #include "net/url_request/url_request_about_job.h"
14 #include "net/url_request/url_request_data_job.h" 14 #include "net/url_request/url_request_data_job.h"
15 #include "net/url_request/url_request_error_job.h" 15 #include "net/url_request/url_request_error_job.h"
16 #include "net/url_request/url_request_file_job.h" 16 #include "net/url_request/url_request_file_job.h"
17 #include "net/url_request/url_request_ftp_job.h" 17 #include "net/url_request/url_request_ftp_job.h"
18 #include "net/url_request/url_request_http_job.h" 18 #include "net/url_request/url_request_http_job.h"
19 19
20 // The built-in set of protocol factories 20 // The built-in set of protocol factories
21 namespace { 21 namespace {
22 22
23 struct SchemeToFactory { 23 struct SchemeToFactory {
24 const char* scheme; 24 const char* scheme;
25 URLRequest::ProtocolFactory* factory; 25 net::URLRequest::ProtocolFactory* factory;
26 }; 26 };
27 27
28 } // namespace 28 } // namespace
29 29
30 static const SchemeToFactory kBuiltinFactories[] = { 30 static const SchemeToFactory kBuiltinFactories[] = {
31 { "http", URLRequestHttpJob::Factory }, 31 { "http", URLRequestHttpJob::Factory },
32 { "https", URLRequestHttpJob::Factory }, 32 { "https", URLRequestHttpJob::Factory },
33 { "file", URLRequestFileJob::Factory }, 33 { "file", URLRequestFileJob::Factory },
34 { "ftp", URLRequestFtpJob::Factory }, 34 { "ftp", URLRequestFtpJob::Factory },
35 { "about", URLRequestAboutJob::Factory }, 35 { "about", URLRequestAboutJob::Factory },
36 { "data", URLRequestDataJob::Factory }, 36 { "data", URLRequestDataJob::Factory },
37 }; 37 };
38 38
39 URLRequestJobManager::URLRequestJobManager() : enable_file_access_(false) { 39 URLRequestJobManager::URLRequestJobManager() : enable_file_access_(false) {
40 #ifndef NDEBUG 40 #ifndef NDEBUG
41 allowed_thread_ = 0; 41 allowed_thread_ = 0;
42 allowed_thread_initialized_ = false; 42 allowed_thread_initialized_ = false;
43 #endif 43 #endif
44 } 44 }
45 45
46 URLRequestJobManager::~URLRequestJobManager() {} 46 URLRequestJobManager::~URLRequestJobManager() {}
47 47
48 URLRequestJob* URLRequestJobManager::CreateJob(URLRequest* request) const { 48 URLRequestJob* URLRequestJobManager::CreateJob(net::URLRequest* request) const {
49 #ifndef NDEBUG 49 #ifndef NDEBUG
50 DCHECK(IsAllowedThread()); 50 DCHECK(IsAllowedThread());
51 #endif 51 #endif
52 52
53 // If we are given an invalid URL, then don't even try to inspect the scheme. 53 // If we are given an invalid URL, then don't even try to inspect the scheme.
54 if (!request->url().is_valid()) 54 if (!request->url().is_valid())
55 return new URLRequestErrorJob(request, net::ERR_INVALID_URL); 55 return new URLRequestErrorJob(request, net::ERR_INVALID_URL);
56 56
57 // We do this here to avoid asking interceptors about unsupported schemes. 57 // We do this here to avoid asking interceptors about unsupported schemes.
58 const std::string& scheme = request->url().scheme(); // already lowercase 58 const std::string& scheme = request->url().scheme(); // already lowercase
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 93 }
94 94
95 // If we reached here, then it means that a registered protocol factory 95 // If we reached here, then it means that a registered protocol factory
96 // wasn't interested in handling the URL. That is fairly unexpected, and we 96 // wasn't interested in handling the URL. That is fairly unexpected, and we
97 // don't know have a specific error to report here :-( 97 // don't know have a specific error to report here :-(
98 LOG(WARNING) << "Failed to map: " << request->url().spec(); 98 LOG(WARNING) << "Failed to map: " << request->url().spec();
99 return new URLRequestErrorJob(request, net::ERR_FAILED); 99 return new URLRequestErrorJob(request, net::ERR_FAILED);
100 } 100 }
101 101
102 URLRequestJob* URLRequestJobManager::MaybeInterceptRedirect( 102 URLRequestJob* URLRequestJobManager::MaybeInterceptRedirect(
103 URLRequest* request, 103 net::URLRequest* request,
104 const GURL& location) const { 104 const GURL& location) const {
105 #ifndef NDEBUG 105 #ifndef NDEBUG
106 DCHECK(IsAllowedThread()); 106 DCHECK(IsAllowedThread());
107 #endif 107 #endif
108 if ((request->load_flags() & net::LOAD_DISABLE_INTERCEPT) || 108 if ((request->load_flags() & net::LOAD_DISABLE_INTERCEPT) ||
109 (request->status().status() == URLRequestStatus::CANCELED) || 109 (request->status().status() == URLRequestStatus::CANCELED) ||
110 !request->url().is_valid() || 110 !request->url().is_valid() ||
111 !SupportsScheme(request->url().scheme())) 111 !SupportsScheme(request->url().scheme()))
112 return NULL; 112 return NULL;
113 113
114 InterceptorList::const_iterator i; 114 InterceptorList::const_iterator i;
115 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { 115 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
116 URLRequestJob* job = (*i)->MaybeInterceptRedirect(request, location); 116 URLRequestJob* job = (*i)->MaybeInterceptRedirect(request, location);
117 if (job) 117 if (job)
118 return job; 118 return job;
119 } 119 }
120 return NULL; 120 return NULL;
121 } 121 }
122 122
123 URLRequestJob* URLRequestJobManager::MaybeInterceptResponse( 123 URLRequestJob* URLRequestJobManager::MaybeInterceptResponse(
124 URLRequest* request) const { 124 net::URLRequest* request) const {
125 #ifndef NDEBUG 125 #ifndef NDEBUG
126 DCHECK(IsAllowedThread()); 126 DCHECK(IsAllowedThread());
127 #endif 127 #endif
128 if ((request->load_flags() & net::LOAD_DISABLE_INTERCEPT) || 128 if ((request->load_flags() & net::LOAD_DISABLE_INTERCEPT) ||
129 (request->status().status() == URLRequestStatus::CANCELED) || 129 (request->status().status() == URLRequestStatus::CANCELED) ||
130 !request->url().is_valid() || 130 !request->url().is_valid() ||
131 !SupportsScheme(request->url().scheme())) 131 !SupportsScheme(request->url().scheme()))
132 return NULL; 132 return NULL;
133 133
134 InterceptorList::const_iterator i; 134 InterceptorList::const_iterator i;
(...skipping 13 matching lines...) Expand all
148 return true; 148 return true;
149 } 149 }
150 150
151 for (size_t i = 0; i < arraysize(kBuiltinFactories); ++i) 151 for (size_t i = 0; i < arraysize(kBuiltinFactories); ++i)
152 if (LowerCaseEqualsASCII(scheme, kBuiltinFactories[i].scheme)) 152 if (LowerCaseEqualsASCII(scheme, kBuiltinFactories[i].scheme))
153 return true; 153 return true;
154 154
155 return false; 155 return false;
156 } 156 }
157 157
158 URLRequest::ProtocolFactory* URLRequestJobManager::RegisterProtocolFactory( 158 net::URLRequest::ProtocolFactory* URLRequestJobManager::RegisterProtocolFactory(
159 const std::string& scheme, 159 const std::string& scheme,
160 URLRequest::ProtocolFactory* factory) { 160 net::URLRequest::ProtocolFactory* factory) {
161 #ifndef NDEBUG 161 #ifndef NDEBUG
162 DCHECK(IsAllowedThread()); 162 DCHECK(IsAllowedThread());
163 #endif 163 #endif
164 164
165 AutoLock locked(lock_); 165 AutoLock locked(lock_);
166 166
167 URLRequest::ProtocolFactory* old_factory; 167 net::URLRequest::ProtocolFactory* old_factory;
168 FactoryMap::iterator i = factories_.find(scheme); 168 FactoryMap::iterator i = factories_.find(scheme);
169 if (i != factories_.end()) { 169 if (i != factories_.end()) {
170 old_factory = i->second; 170 old_factory = i->second;
171 } else { 171 } else {
172 old_factory = NULL; 172 old_factory = NULL;
173 } 173 }
174 if (factory) { 174 if (factory) {
175 factories_[scheme] = factory; 175 factories_[scheme] = factory;
176 } else if (i != factories_.end()) { // uninstall any old one 176 } else if (i != factories_.end()) { // uninstall any old one
177 factories_.erase(i); 177 factories_.erase(i);
178 } 178 }
179 return old_factory; 179 return old_factory;
180 } 180 }
181 181
182 void URLRequestJobManager::RegisterRequestInterceptor( 182 void URLRequestJobManager::RegisterRequestInterceptor(
183 URLRequest::Interceptor* interceptor) { 183 net::URLRequest::Interceptor* interceptor) {
184 #ifndef NDEBUG 184 #ifndef NDEBUG
185 DCHECK(IsAllowedThread()); 185 DCHECK(IsAllowedThread());
186 #endif 186 #endif
187 187
188 AutoLock locked(lock_); 188 AutoLock locked(lock_);
189 189
190 DCHECK(std::find(interceptors_.begin(), interceptors_.end(), interceptor) == 190 DCHECK(std::find(interceptors_.begin(), interceptors_.end(), interceptor) ==
191 interceptors_.end()); 191 interceptors_.end());
192 interceptors_.push_back(interceptor); 192 interceptors_.push_back(interceptor);
193 } 193 }
194 194
195 void URLRequestJobManager::UnregisterRequestInterceptor( 195 void URLRequestJobManager::UnregisterRequestInterceptor(
196 URLRequest::Interceptor* interceptor) { 196 net::URLRequest::Interceptor* interceptor) {
197 #ifndef NDEBUG 197 #ifndef NDEBUG
198 DCHECK(IsAllowedThread()); 198 DCHECK(IsAllowedThread());
199 #endif 199 #endif
200 200
201 AutoLock locked(lock_); 201 AutoLock locked(lock_);
202 202
203 InterceptorList::iterator i = 203 InterceptorList::iterator i =
204 std::find(interceptors_.begin(), interceptors_.end(), interceptor); 204 std::find(interceptors_.begin(), interceptors_.end(), interceptor);
205 DCHECK(i != interceptors_.end()); 205 DCHECK(i != interceptors_.end());
206 interceptors_.erase(i); 206 interceptors_.erase(i);
207 } 207 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698