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

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

Issue 5634005: Add a new GetInstance() method for singleton classes under chrome/service and /net. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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
« no previous file with comments | « net/url_request/https_prober.cc ('k') | net/url_request/url_request_http_job.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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.h" 5 #include "net/url_request/url_request.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/metrics/stats_counters.h" 9 #include "base/metrics/stats_counters.h"
10 #include "base/singleton.h" 10 #include "base/singleton.h"
(...skipping 11 matching lines...) Expand all
22 22
23 using base::Time; 23 using base::Time;
24 using net::UploadData; 24 using net::UploadData;
25 using std::string; 25 using std::string;
26 26
27 namespace { 27 namespace {
28 28
29 // Max number of http redirects to follow. Same number as gecko. 29 // Max number of http redirects to follow. Same number as gecko.
30 const int kMaxRedirects = 20; 30 const int kMaxRedirects = 20;
31 31
32 URLRequestJobManager* GetJobManager() {
33 return Singleton<URLRequestJobManager>::get();
34 }
35
36 // Discard headers which have meaning in POST (Content-Length, Content-Type, 32 // Discard headers which have meaning in POST (Content-Length, Content-Type,
37 // Origin). 33 // Origin).
38 void StripPostSpecificHeaders(net::HttpRequestHeaders* headers) { 34 void StripPostSpecificHeaders(net::HttpRequestHeaders* headers) {
39 // These are headers that may be attached to a POST. 35 // These are headers that may be attached to a POST.
40 headers->RemoveHeader(net::HttpRequestHeaders::kContentLength); 36 headers->RemoveHeader(net::HttpRequestHeaders::kContentLength);
41 headers->RemoveHeader(net::HttpRequestHeaders::kContentType); 37 headers->RemoveHeader(net::HttpRequestHeaders::kContentType);
42 headers->RemoveHeader(net::HttpRequestHeaders::kOrigin); 38 headers->RemoveHeader(net::HttpRequestHeaders::kOrigin);
43 } 39 }
44 40
45 } // namespace 41 } // namespace
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 119
124 if (job_) 120 if (job_)
125 OrphanJob(); 121 OrphanJob();
126 122
127 set_context(NULL); 123 set_context(NULL);
128 } 124 }
129 125
130 // static 126 // static
131 URLRequest::ProtocolFactory* URLRequest::RegisterProtocolFactory( 127 URLRequest::ProtocolFactory* URLRequest::RegisterProtocolFactory(
132 const string& scheme, ProtocolFactory* factory) { 128 const string& scheme, ProtocolFactory* factory) {
133 return GetJobManager()->RegisterProtocolFactory(scheme, factory); 129 return URLRequestJobManager::GetInstance()->RegisterProtocolFactory(scheme,
130 factory);
134 } 131 }
135 132
136 // static 133 // static
137 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) { 134 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) {
138 GetJobManager()->RegisterRequestInterceptor(interceptor); 135 URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor);
139 } 136 }
140 137
141 // static 138 // static
142 void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) { 139 void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) {
143 GetJobManager()->UnregisterRequestInterceptor(interceptor); 140 URLRequestJobManager::GetInstance()->UnregisterRequestInterceptor(
141 interceptor);
144 } 142 }
145 143
146 void URLRequest::AppendBytesToUpload(const char* bytes, int bytes_len) { 144 void URLRequest::AppendBytesToUpload(const char* bytes, int bytes_len) {
147 DCHECK(bytes_len > 0 && bytes); 145 DCHECK(bytes_len > 0 && bytes);
148 if (!upload_) 146 if (!upload_)
149 upload_ = new UploadData(); 147 upload_ = new UploadData();
150 upload_->AppendBytes(bytes, bytes_len); 148 upload_->AppendBytes(bytes, bytes_len);
151 } 149 }
152 150
153 void URLRequest::AppendFileRangeToUpload( 151 void URLRequest::AppendFileRangeToUpload(
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 job_->GetCharset(charset); 255 job_->GetCharset(charset);
258 } 256 }
259 257
260 int URLRequest::GetResponseCode() { 258 int URLRequest::GetResponseCode() {
261 DCHECK(job_); 259 DCHECK(job_);
262 return job_->GetResponseCode(); 260 return job_->GetResponseCode();
263 } 261 }
264 262
265 // static 263 // static
266 bool URLRequest::IsHandledProtocol(const std::string& scheme) { 264 bool URLRequest::IsHandledProtocol(const std::string& scheme) {
267 return GetJobManager()->SupportsScheme(scheme); 265 return URLRequestJobManager::GetInstance()->SupportsScheme(scheme);
268 } 266 }
269 267
270 // static 268 // static
271 bool URLRequest::IsHandledURL(const GURL& url) { 269 bool URLRequest::IsHandledURL(const GURL& url) {
272 if (!url.is_valid()) { 270 if (!url.is_valid()) {
273 // We handle error cases. 271 // We handle error cases.
274 return true; 272 return true;
275 } 273 }
276 274
277 return IsHandledProtocol(url.scheme()); 275 return IsHandledProtocol(url.scheme());
278 } 276 }
279 277
280 // static 278 // static
281 void URLRequest::AllowFileAccess() { 279 void URLRequest::AllowFileAccess() {
282 GetJobManager()->set_enable_file_access(true); 280 URLRequestJobManager::GetInstance()->set_enable_file_access(true);
283 } 281 }
284 282
285 // static 283 // static
286 bool URLRequest::IsFileAccessAllowed() { 284 bool URLRequest::IsFileAccessAllowed() {
287 return GetJobManager()->enable_file_access(); 285 return URLRequestJobManager::GetInstance()->enable_file_access();
288 } 286 }
289 287
290 288
291 void URLRequest::set_first_party_for_cookies( 289 void URLRequest::set_first_party_for_cookies(
292 const GURL& first_party_for_cookies) { 290 const GURL& first_party_for_cookies) {
293 first_party_for_cookies_ = first_party_for_cookies; 291 first_party_for_cookies_ = first_party_for_cookies;
294 } 292 }
295 293
296 void URLRequest::set_method(const std::string& method) { 294 void URLRequest::set_method(const std::string& method) {
297 DCHECK(!is_pending_); 295 DCHECK(!is_pending_);
(...skipping 13 matching lines...) Expand all
311 GURL::Replacements referrer_mods; 309 GURL::Replacements referrer_mods;
312 referrer_mods.ClearUsername(); 310 referrer_mods.ClearUsername();
313 referrer_mods.ClearPassword(); 311 referrer_mods.ClearPassword();
314 ret = ret.ReplaceComponents(referrer_mods); 312 ret = ret.ReplaceComponents(referrer_mods);
315 } 313 }
316 314
317 return ret; 315 return ret;
318 } 316 }
319 317
320 void URLRequest::Start() { 318 void URLRequest::Start() {
321 StartJob(GetJobManager()->CreateJob(this)); 319 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this));
322 } 320 }
323 321
324 /////////////////////////////////////////////////////////////////////////////// 322 ///////////////////////////////////////////////////////////////////////////////
325 323
326 void URLRequest::StartJob(URLRequestJob* job) { 324 void URLRequest::StartJob(URLRequestJob* job) {
327 DCHECK(!is_pending_); 325 DCHECK(!is_pending_);
328 DCHECK(!job_); 326 DCHECK(!job_);
329 327
330 net_log_.BeginEvent( 328 net_log_.BeginEvent(
331 net::NetLog::TYPE_URL_REQUEST_START_JOB, 329 net::NetLog::TYPE_URL_REQUEST_START_JOB,
(...skipping 14 matching lines...) Expand all
346 // Don't allow errors to be sent from within Start(). 344 // Don't allow errors to be sent from within Start().
347 // TODO(brettw) this may cause NotifyDone to be sent synchronously, 345 // TODO(brettw) this may cause NotifyDone to be sent synchronously,
348 // we probably don't want this: they should be sent asynchronously so 346 // we probably don't want this: they should be sent asynchronously so
349 // the caller does not get reentered. 347 // the caller does not get reentered.
350 job_->Start(); 348 job_->Start();
351 } 349 }
352 350
353 void URLRequest::Restart() { 351 void URLRequest::Restart() {
354 // Should only be called if the original job didn't make any progress. 352 // Should only be called if the original job didn't make any progress.
355 DCHECK(job_ && !job_->has_response_started()); 353 DCHECK(job_ && !job_->has_response_started());
356 RestartWithJob(GetJobManager()->CreateJob(this)); 354 RestartWithJob(URLRequestJobManager::GetInstance()->CreateJob(this));
357 } 355 }
358 356
359 void URLRequest::RestartWithJob(URLRequestJob *job) { 357 void URLRequest::RestartWithJob(URLRequestJob *job) {
360 DCHECK(job->request() == this); 358 DCHECK(job->request() == this);
361 PrepareToRestart(); 359 PrepareToRestart();
362 StartJob(job); 360 StartJob(job);
363 } 361 }
364 362
365 void URLRequest::Cancel() { 363 void URLRequest::Cancel() {
366 DoCancel(net::ERR_ABORTED, net::SSLInfo()); 364 DoCancel(net::ERR_ABORTED, net::SSLInfo());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 418
421 return job_->Read(dest, dest_size, bytes_read); 419 return job_->Read(dest, dest_size, bytes_read);
422 } 420 }
423 421
424 void URLRequest::StopCaching() { 422 void URLRequest::StopCaching() {
425 DCHECK(job_); 423 DCHECK(job_);
426 job_->StopCaching(); 424 job_->StopCaching();
427 } 425 }
428 426
429 void URLRequest::ReceivedRedirect(const GURL& location, bool* defer_redirect) { 427 void URLRequest::ReceivedRedirect(const GURL& location, bool* defer_redirect) {
430 URLRequestJob* job = GetJobManager()->MaybeInterceptRedirect(this, location); 428 URLRequestJob* job =
429 URLRequestJobManager::GetInstance()->MaybeInterceptRedirect(this,
430 location);
431 if (job) { 431 if (job) {
432 RestartWithJob(job); 432 RestartWithJob(job);
433 } else if (delegate_) { 433 } else if (delegate_) {
434 delegate_->OnReceivedRedirect(this, location, defer_redirect); 434 delegate_->OnReceivedRedirect(this, location, defer_redirect);
435 } 435 }
436 } 436 }
437 437
438 void URLRequest::ResponseStarted() { 438 void URLRequest::ResponseStarted() {
439 scoped_refptr<net::NetLog::EventParameters> params; 439 scoped_refptr<net::NetLog::EventParameters> params;
440 if (!status_.is_success()) 440 if (!status_.is_success())
441 params = new net::NetLogIntegerParameter("net_error", status_.os_error()); 441 params = new net::NetLogIntegerParameter("net_error", status_.os_error());
442 net_log_.EndEvent(net::NetLog::TYPE_URL_REQUEST_START_JOB, params); 442 net_log_.EndEvent(net::NetLog::TYPE_URL_REQUEST_START_JOB, params);
443 443
444 URLRequestJob* job = GetJobManager()->MaybeInterceptResponse(this); 444 URLRequestJob* job =
445 URLRequestJobManager::GetInstance()->MaybeInterceptResponse(this);
445 if (job) { 446 if (job) {
446 RestartWithJob(job); 447 RestartWithJob(job);
447 } else if (delegate_) { 448 } else if (delegate_) {
448 delegate_->OnResponseStarted(this); 449 delegate_->OnResponseStarted(this);
449 } 450 }
450 } 451 }
451 452
452 void URLRequest::FollowDeferredRedirect() { 453 void URLRequest::FollowDeferredRedirect() {
453 CHECK(job_); 454 CHECK(job_);
454 CHECK(status_.is_success()); 455 CHECK(status_.is_success());
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 if (found != user_data_.end()) 596 if (found != user_data_.end())
596 return found->second.get(); 597 return found->second.get();
597 return NULL; 598 return NULL;
598 } 599 }
599 600
600 void URLRequest::SetUserData(const void* key, UserData* data) { 601 void URLRequest::SetUserData(const void* key, UserData* data) {
601 user_data_[key] = linked_ptr<UserData>(data); 602 user_data_[key] = linked_ptr<UserData>(data);
602 } 603 }
603 604
604 } // namespace net 605 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/https_prober.cc ('k') | net/url_request/url_request_http_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698