diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-26 10:18:52 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-26 10:18:52 +0000 |
commit | a1f7bba412d50a3939f495011bdd3bdf30fb3bf5 (patch) | |
tree | a1f2d6e68df4ee5ed39a7a1c67797c0dbeff85db /net | |
parent | abc2056e55ea99b6065acea7582127f8ed46f220 (diff) | |
download | chromium_src-a1f7bba412d50a3939f495011bdd3bdf30fb3bf5.zip chromium_src-a1f7bba412d50a3939f495011bdd3bdf30fb3bf5.tar.gz chromium_src-a1f7bba412d50a3939f495011bdd3bdf30fb3bf5.tar.bz2 |
Remove ProtocolFactory/Interceptor uses in GViewRequestInterceptor.
Gets rid of more use of net/ globals, replacing with URLRequestJobFactory uses. Helps make net/ more thread-compatible.
BUG=81979
TEST=none
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=86802
Review URL: http://codereview.chromium.org/7019030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86804 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/url_request/url_request_job_factory.cc | 33 | ||||
-rw-r--r-- | net/url_request/url_request_job_factory.h | 5 | ||||
-rw-r--r-- | net/url_request/url_request_job_manager.cc | 70 | ||||
-rw-r--r-- | net/url_request/url_request_job_manager.h | 2 |
4 files changed, 86 insertions, 24 deletions
diff --git a/net/url_request/url_request_job_factory.cc b/net/url_request/url_request_job_factory.cc index e802f60..8ef5876 100644 --- a/net/url_request/url_request_job_factory.cc +++ b/net/url_request/url_request_job_factory.cc @@ -76,6 +76,39 @@ URLRequestJob* URLRequestJobFactory::MaybeCreateJobWithProtocolHandler( return it->second->MaybeCreateJob(request); } +URLRequestJob* URLRequestJobFactory::MaybeInterceptRedirect( + const GURL& location, + URLRequest* request) const { + DCHECK(CalledOnValidThread()); + URLRequestJob* job = NULL; + + if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { + InterceptorList::const_iterator i; + for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { + job = (*i)->MaybeInterceptRedirect(location, request); + if (job) + return job; + } + } + return NULL; +} + +URLRequestJob* URLRequestJobFactory::MaybeInterceptResponse( + URLRequest* request) const { + DCHECK(CalledOnValidThread()); + URLRequestJob* job = NULL; + + if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { + InterceptorList::const_iterator i; + for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { + job = (*i)->MaybeInterceptResponse(request); + if (job) + return job; + } + } + return NULL; +} + bool URLRequestJobFactory::IsHandledProtocol(const std::string& scheme) const { DCHECK(CalledOnValidThread()); InterceptorList::const_iterator i; diff --git a/net/url_request/url_request_job_factory.h b/net/url_request/url_request_job_factory.h index ee1ea64..5c87e00 100644 --- a/net/url_request/url_request_job_factory.h +++ b/net/url_request/url_request_job_factory.h @@ -86,6 +86,11 @@ class NET_TEST URLRequestJobFactory URLRequestJob* MaybeCreateJobWithProtocolHandler(const std::string& scheme, URLRequest* request) const; + URLRequestJob* MaybeInterceptRedirect(const GURL& location, + URLRequest* request) const; + + URLRequestJob* MaybeInterceptResponse(URLRequest* request) const; + bool IsHandledProtocol(const std::string& scheme) const; bool IsHandledURL(const GURL& url) const; diff --git a/net/url_request/url_request_job_manager.cc b/net/url_request/url_request_job_manager.cc index dc6af79..71e9e55 100644 --- a/net/url_request/url_request_job_manager.cc +++ b/net/url_request/url_request_job_manager.cc @@ -49,9 +49,7 @@ URLRequestJobManager* URLRequestJobManager::GetInstance() { URLRequestJob* URLRequestJobManager::CreateJob( URLRequest* request) const { -#ifndef NDEBUG DCHECK(IsAllowedThread()); -#endif // If we are given an invalid URL, then don't even try to inspect the scheme. if (!request->url().is_valid()) @@ -132,18 +130,35 @@ URLRequestJob* URLRequestJobManager::CreateJob( URLRequestJob* URLRequestJobManager::MaybeInterceptRedirect( URLRequest* request, const GURL& location) const { -#ifndef NDEBUG DCHECK(IsAllowedThread()); -#endif - if ((request->load_flags() & LOAD_DISABLE_INTERCEPT) || - (request->status().status() == URLRequestStatus::CANCELED) || - !request->url().is_valid() || - !SupportsScheme(request->url().scheme())) + if (!request->url().is_valid() || + request->load_flags() & LOAD_DISABLE_INTERCEPT || + request->status().status() == URLRequestStatus::CANCELED) { + return NULL; + } + + const URLRequestJobFactory* job_factory = NULL; + if (request->context()) + job_factory = request->context()->job_factory(); + + const std::string& scheme = request->url().scheme(); // already lowercase + if (job_factory) { + if (!job_factory->IsHandledProtocol(scheme)) { + return NULL; + } + } else if (!SupportsScheme(scheme)) { return NULL; + } + + URLRequestJob* job = NULL; + if (job_factory) + job = job_factory->MaybeInterceptRedirect(location, request); + if (job) + return job; InterceptorList::const_iterator i; for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { - URLRequestJob* job = (*i)->MaybeInterceptRedirect(request, location); + job = (*i)->MaybeInterceptRedirect(request, location); if (job) return job; } @@ -152,18 +167,35 @@ URLRequestJob* URLRequestJobManager::MaybeInterceptRedirect( URLRequestJob* URLRequestJobManager::MaybeInterceptResponse( URLRequest* request) const { -#ifndef NDEBUG DCHECK(IsAllowedThread()); -#endif - if ((request->load_flags() & LOAD_DISABLE_INTERCEPT) || - (request->status().status() == URLRequestStatus::CANCELED) || - !request->url().is_valid() || - !SupportsScheme(request->url().scheme())) + if (!request->url().is_valid() || + request->load_flags() & LOAD_DISABLE_INTERCEPT || + request->status().status() == URLRequestStatus::CANCELED) { return NULL; + } + + const URLRequestJobFactory* job_factory = NULL; + if (request->context()) + job_factory = request->context()->job_factory(); + + const std::string& scheme = request->url().scheme(); // already lowercase + if (job_factory) { + if (!job_factory->IsHandledProtocol(scheme)) { + return NULL; + } + } else if (!SupportsScheme(scheme)) { + return NULL; + } + + URLRequestJob* job = NULL; + if (job_factory) + job = job_factory->MaybeInterceptResponse(request); + if (job) + return job; InterceptorList::const_iterator i; for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { - URLRequestJob* job = (*i)->MaybeInterceptResponse(request); + job = (*i)->MaybeInterceptResponse(request); if (job) return job; } @@ -188,9 +220,7 @@ bool URLRequestJobManager::SupportsScheme(const std::string& scheme) const { URLRequest::ProtocolFactory* URLRequestJobManager::RegisterProtocolFactory( const std::string& scheme, URLRequest::ProtocolFactory* factory) { -#ifndef NDEBUG DCHECK(IsAllowedThread()); -#endif base::AutoLock locked(lock_); @@ -211,9 +241,7 @@ URLRequest::ProtocolFactory* URLRequestJobManager::RegisterProtocolFactory( void URLRequestJobManager::RegisterRequestInterceptor( URLRequest::Interceptor* interceptor) { -#ifndef NDEBUG DCHECK(IsAllowedThread()); -#endif base::AutoLock locked(lock_); @@ -224,9 +252,7 @@ void URLRequestJobManager::RegisterRequestInterceptor( void URLRequestJobManager::UnregisterRequestInterceptor( URLRequest::Interceptor* interceptor) { -#ifndef NDEBUG DCHECK(IsAllowedThread()); -#endif base::AutoLock locked(lock_); diff --git a/net/url_request/url_request_job_manager.h b/net/url_request/url_request_job_manager.h index 747f923..469cc66 100644 --- a/net/url_request/url_request_job_manager.h +++ b/net/url_request/url_request_job_manager.h @@ -76,7 +76,6 @@ class URLRequestJobManager { URLRequestJobManager(); ~URLRequestJobManager(); -#ifndef NDEBUG // The first guy to call this function sets the allowed thread. This way we // avoid needing to define that thread externally. Since we expect all // callers to be on the same thread, we don't worry about threads racing to @@ -98,7 +97,6 @@ class URLRequestJobManager { // bug http://b/issue?id=1338969 has been filed to fix things and turn the // check back on. return true; -#endif } // We use this to assert that CreateJob and the registration functions all |