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

Side by Side Diff: chrome/browser/custom_handlers/protocol_handler_registry.cc

Issue 11669012: Convert ProtocolHandlerRegistry::Interceptor to a net::URLRequestJobFactory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/custom_handlers/protocol_handler_registry.h" 5 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 148
149 GURL translated_url(handler.TranslateUrl(request->url())); 149 GURL translated_url(handler.TranslateUrl(request->url()));
150 if (!translated_url.is_valid()) 150 if (!translated_url.is_valid())
151 return NULL; 151 return NULL;
152 152
153 return new net::URLRequestRedirectJob( 153 return new net::URLRequestRedirectJob(
154 request, network_delegate, translated_url, 154 request, network_delegate, translated_url,
155 net::URLRequestRedirectJob::REDIRECT_302_FOUND); 155 net::URLRequestRedirectJob::REDIRECT_302_FOUND);
156 } 156 }
157 157
158 // URLInterceptor ------------------------------------------------------------ 158 // JobFactory -----------------------------------------------------------------
159 159
160 // Instances of this class are produced for ownership by the IO 160 // Instances of JobFactory are produced for ownership by the IO
161 // thread where it handler URL requests. We should never hold 161 // thread where it handler URL requests. We should never hold
162 // any pointers on this class, only produce them in response to 162 // any pointers on this class, only produce them in response to
163 // requests via |ProtocolHandlerRegistry::CreateURLInterceptor|. 163 // requests via |ProtocolHandlerRegistry::CreateURLInterceptor|.
erikwright (departed) 2013/01/02 16:29:36 Update name of CreateURLInterceptor
164 class ProtocolHandlerRegistry::URLInterceptor 164 ProtocolHandlerRegistry::JobFactory::JobFactory(Core* core)
165 : public net::URLRequestJobFactory::Interceptor {
166 public:
167 explicit URLInterceptor(Core* core);
168 virtual ~URLInterceptor();
169
170 virtual net::URLRequestJob* MaybeIntercept(
171 net::URLRequest* request,
172 net::NetworkDelegate* network_delegate) const OVERRIDE;
173
174 virtual bool WillHandleProtocol(const std::string& protocol) const OVERRIDE;
175
176 virtual net::URLRequestJob* MaybeInterceptRedirect(
177 const GURL& url,
178 net::URLRequest* request,
179 net::NetworkDelegate* network_delegate) const OVERRIDE {
180 return NULL;
181 }
182
183 virtual net::URLRequestJob* MaybeInterceptResponse(
184 net::URLRequest* request,
185 net::NetworkDelegate* network_delegate) const OVERRIDE {
186 return NULL;
187 }
188
189 private:
190 scoped_refptr<Core> core_;
191 DISALLOW_COPY_AND_ASSIGN(URLInterceptor);
192 };
193
194 ProtocolHandlerRegistry::URLInterceptor::URLInterceptor(Core* core)
195 : core_(core) { 165 : core_(core) {
196 DCHECK(core_); 166 DCHECK(core_);
167 DetachFromThread();
197 } 168 }
198 169
199 ProtocolHandlerRegistry::URLInterceptor::~URLInterceptor() { 170 ProtocolHandlerRegistry::JobFactory::~JobFactory() {
200 } 171 }
201 172
202 net::URLRequestJob* ProtocolHandlerRegistry::URLInterceptor::MaybeIntercept( 173 void ProtocolHandlerRegistry::JobFactory::Chain(
203 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { 174 scoped_ptr<net::URLRequestJobFactory> job_factory) {
204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 175 job_factory_ = job_factory.Pass();
205
206 return core_->MaybeCreateJob(request, network_delegate);
207 } 176 }
208 177
209 bool ProtocolHandlerRegistry::URLInterceptor::WillHandleProtocol( 178 bool ProtocolHandlerRegistry::JobFactory::SetProtocolHandler(
210 const std::string& protocol) const { 179 const std::string& scheme, ProtocolHandler* protocol_handler) {
180 return job_factory_->SetProtocolHandler(scheme, protocol_handler);
181 }
182
183 void ProtocolHandlerRegistry::JobFactory::AddInterceptor(
184 Interceptor* interceptor) {
185 return job_factory_->AddInterceptor(interceptor);
186 }
187
188 net::URLRequestJob*
189 ProtocolHandlerRegistry::JobFactory::MaybeCreateJobWithInterceptor(
190 net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
191 return job_factory_->MaybeCreateJobWithInterceptor(request, network_delegate);
192 }
193
194 net::URLRequestJob*
195 ProtocolHandlerRegistry::JobFactory::MaybeCreateJobWithProtocolHandler(
196 const std::string& scheme,
197 net::URLRequest* request,
198 net::NetworkDelegate* network_delegate) const {
211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
200 net::URLRequestJob* job = core_->MaybeCreateJob(request, network_delegate);
201 if (job)
202 return job;
203 return job_factory_->MaybeCreateJobWithProtocolHandler(
204 scheme, request, network_delegate);
205 }
212 206
213 return core_->IsHandledProtocol(protocol); 207 net::URLRequestJob* ProtocolHandlerRegistry::JobFactory::MaybeInterceptRedirect(
208 const GURL& location,
209 net::URLRequest* request,
210 net::NetworkDelegate* network_delegate) const {
211 return job_factory_->MaybeInterceptRedirect(
212 location, request, network_delegate);
213 }
214
215 net::URLRequestJob* ProtocolHandlerRegistry::JobFactory::MaybeInterceptResponse(
216 net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
217 return job_factory_->MaybeInterceptResponse(request, network_delegate);
218 }
219
220 bool ProtocolHandlerRegistry::JobFactory::IsHandledProtocol(
221 const std::string& scheme) const {
222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
223 return core_->IsHandledProtocol(scheme) ||
224 job_factory_->IsHandledProtocol(scheme);
225 }
226
227 bool ProtocolHandlerRegistry::JobFactory::IsHandledURL(const GURL& url) const {
228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
229 return (url.is_valid() && core_->IsHandledProtocol(url.scheme())) ||
230 job_factory_->IsHandledURL(url);
214 } 231 }
215 232
216 // DefaultClientObserver ------------------------------------------------------ 233 // DefaultClientObserver ------------------------------------------------------
217 234
218 ProtocolHandlerRegistry::DefaultClientObserver::DefaultClientObserver( 235 ProtocolHandlerRegistry::DefaultClientObserver::DefaultClientObserver(
219 ProtocolHandlerRegistry* registry) 236 ProtocolHandlerRegistry* registry)
220 : worker_(NULL), 237 : worker_(NULL),
221 registry_(registry) { 238 registry_(registry) {
222 DCHECK(registry_); 239 DCHECK(registry_);
223 } 240 }
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 ignored_protocol_handlers_.push_back(handler); 885 ignored_protocol_handlers_.push_back(handler);
869 } 886 }
870 887
871 void ProtocolHandlerRegistry::AddPredefinedHandler( 888 void ProtocolHandlerRegistry::AddPredefinedHandler(
872 const ProtocolHandler& handler) { 889 const ProtocolHandler& handler) {
873 DCHECK(!is_loaded_); // Must be called prior InitProtocolSettings. 890 DCHECK(!is_loaded_); // Must be called prior InitProtocolSettings.
874 RegisterProtocolHandler(handler); 891 RegisterProtocolHandler(handler);
875 SetDefault(handler); 892 SetDefault(handler);
876 } 893 }
877 894
878 net::URLRequestJobFactory::Interceptor* 895 scoped_ptr<ProtocolHandlerRegistry::JobFactory>
879 ProtocolHandlerRegistry::CreateURLInterceptor() { 896 ProtocolHandlerRegistry::CreateURLRequestJobFactory() {
880 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 897 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
881 // this is always created on the UI thread (in profile_io's 898 // this is always created on the UI thread (in profile_io's
882 // InitializeOnUIThread. Any method calls must be done 899 // InitializeOnUIThread. Any method calls must be done
883 // on the IO thread (this is checked). 900 // on the IO thread (this is checked).
884 return new URLInterceptor(core_); 901 return scoped_ptr<JobFactory>(new JobFactory(core_));
885 } 902 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698