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

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

Issue 10855209: Refactoring: ProtocolHandler::MaybeCreateJob takes NetworkDelegate as argument (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: NetworkDelegate fixed almost everywhere Created 8 years, 4 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // Clears the default for the provided protocol. 83 // Clears the default for the provided protocol.
84 // Should be called only from the IO thread. 84 // Should be called only from the IO thread.
85 void ClearDefault(const std::string& scheme); 85 void ClearDefault(const std::string& scheme);
86 86
87 // Makes this ProtocolHandler the default handler for its protocol. 87 // Makes this ProtocolHandler the default handler for its protocol.
88 // Should be called only from the IO thread. 88 // Should be called only from the IO thread.
89 void SetDefault(const ProtocolHandler& handler); 89 void SetDefault(const ProtocolHandler& handler);
90 90
91 // Creates a URL request job for the given request if there is a matching 91 // Creates a URL request job for the given request if there is a matching
92 // protocol handler, returns NULL otherwise. 92 // protocol handler, returns NULL otherwise.
93 net::URLRequestJob* MaybeCreateJob(net::URLRequest* request) const; 93 net::URLRequestJob* MaybeCreateJob(
94 net::URLRequest* request, net::NetworkDelegate* network_delegate) const;
94 95
95 // Indicate that the registry has been enabled in the IO thread's 96 // Indicate that the registry has been enabled in the IO thread's
96 // copy of the data. 97 // copy of the data.
97 void Enable() { enabled_ = true; } 98 void Enable() { enabled_ = true; }
98 99
99 // Indicate that the registry has been disabled in the IO thread's copy of 100 // Indicate that the registry has been disabled in the IO thread's copy of
100 // the data. 101 // the data.
101 void Disable() { enabled_ = false; } 102 void Disable() { enabled_ = false; }
102 103
103 private: 104 private:
(...skipping 26 matching lines...) Expand all
130 void ProtocolHandlerRegistry::Core::SetDefault(const ProtocolHandler& handler) { 131 void ProtocolHandlerRegistry::Core::SetDefault(const ProtocolHandler& handler) {
131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
132 ClearDefault(handler.protocol()); 133 ClearDefault(handler.protocol());
133 default_handlers_.insert(std::make_pair(handler.protocol(), handler)); 134 default_handlers_.insert(std::make_pair(handler.protocol(), handler));
134 } 135 }
135 136
136 // Create a new job for the supplied |URLRequest| if a default handler 137 // Create a new job for the supplied |URLRequest| if a default handler
137 // is registered and the associated handler is able to interpret 138 // is registered and the associated handler is able to interpret
138 // the url from |request|. 139 // the url from |request|.
139 net::URLRequestJob* ProtocolHandlerRegistry::Core::MaybeCreateJob( 140 net::URLRequestJob* ProtocolHandlerRegistry::Core::MaybeCreateJob(
140 net::URLRequest* request) const { 141 net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
142 143
143 ProtocolHandler handler = LookupHandler(default_handlers_, 144 ProtocolHandler handler = LookupHandler(default_handlers_,
144 request->url().scheme()); 145 request->url().scheme());
145 if (handler.IsEmpty()) 146 if (handler.IsEmpty())
146 return NULL; 147 return NULL;
147 148
148 GURL translated_url(handler.TranslateUrl(request->url())); 149 GURL translated_url(handler.TranslateUrl(request->url()));
149 if (!translated_url.is_valid()) 150 if (!translated_url.is_valid())
150 return NULL; 151 return NULL;
151 152
152 return new net::URLRequestRedirectJob(request, translated_url); 153 return new net::URLRequestRedirectJob(
154 request, network_delegate, translated_url);
153 } 155 }
154 156
155 // URLInterceptor ------------------------------------------------------------ 157 // URLInterceptor ------------------------------------------------------------
156 158
157 // Instances of this class are produced for ownership by the IO 159 // Instances of this class are produced for ownership by the IO
158 // thread where it handler URL requests. We should never hold 160 // thread where it handler URL requests. We should never hold
159 // any pointers on this class, only produce them in response to 161 // any pointers on this class, only produce them in response to
160 // requests via |ProtocolHandlerRegistry::CreateURLInterceptor|. 162 // requests via |ProtocolHandlerRegistry::CreateURLInterceptor|.
161 class ProtocolHandlerRegistry::URLInterceptor 163 class ProtocolHandlerRegistry::URLInterceptor
162 : public net::URLRequestJobFactory::Interceptor { 164 : public net::URLRequestJobFactory::Interceptor {
163 public: 165 public:
164 explicit URLInterceptor(Core* core); 166 explicit URLInterceptor(Core* core);
165 virtual ~URLInterceptor(); 167 virtual ~URLInterceptor();
166 168
167 virtual net::URLRequestJob* MaybeIntercept( 169 virtual net::URLRequestJob* MaybeIntercept(
168 net::URLRequest* request) const OVERRIDE; 170 net::URLRequest* request,
171 net::NetworkDelegate* network_delegate) const OVERRIDE;
169 172
170 virtual bool WillHandleProtocol(const std::string& protocol) const OVERRIDE; 173 virtual bool WillHandleProtocol(const std::string& protocol) const OVERRIDE;
171 174
172 virtual net::URLRequestJob* MaybeInterceptRedirect( 175 virtual net::URLRequestJob* MaybeInterceptRedirect(
173 const GURL& url, net::URLRequest* request) const OVERRIDE { 176 const GURL& url, net::URLRequest* request) const OVERRIDE {
174 return NULL; 177 return NULL;
175 } 178 }
176 179
177 virtual net::URLRequestJob* MaybeInterceptResponse( 180 virtual net::URLRequestJob* MaybeInterceptResponse(
178 net::URLRequest* request) const OVERRIDE { 181 net::URLRequest* request) const OVERRIDE {
179 return NULL; 182 return NULL;
180 } 183 }
181 184
182 private: 185 private:
183 scoped_refptr<Core> core_; 186 scoped_refptr<Core> core_;
184 DISALLOW_COPY_AND_ASSIGN(URLInterceptor); 187 DISALLOW_COPY_AND_ASSIGN(URLInterceptor);
185 }; 188 };
186 189
187 ProtocolHandlerRegistry::URLInterceptor::URLInterceptor(Core* core) 190 ProtocolHandlerRegistry::URLInterceptor::URLInterceptor(Core* core)
188 : core_(core) { 191 : core_(core) {
189 DCHECK(core_); 192 DCHECK(core_);
190 } 193 }
191 194
192 ProtocolHandlerRegistry::URLInterceptor::~URLInterceptor() { 195 ProtocolHandlerRegistry::URLInterceptor::~URLInterceptor() {
193 } 196 }
194 197
195 net::URLRequestJob* ProtocolHandlerRegistry::URLInterceptor::MaybeIntercept( 198 net::URLRequestJob* ProtocolHandlerRegistry::URLInterceptor::MaybeIntercept(
196 net::URLRequest* request) const { 199 net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
198 201
199 return core_->MaybeCreateJob(request); 202 return core_->MaybeCreateJob(request, network_delegate);
200 } 203 }
201 204
202 bool ProtocolHandlerRegistry::URLInterceptor::WillHandleProtocol( 205 bool ProtocolHandlerRegistry::URLInterceptor::WillHandleProtocol(
203 const std::string& protocol) const { 206 const std::string& protocol) const {
204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
205 208
206 return core_->IsHandledProtocol(protocol); 209 return core_->IsHandledProtocol(protocol);
207 } 210 }
208 211
209 // DefaultClientObserver ------------------------------------------------------ 212 // DefaultClientObserver ------------------------------------------------------
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 } 866 }
864 867
865 net::URLRequestJobFactory::Interceptor* 868 net::URLRequestJobFactory::Interceptor*
866 ProtocolHandlerRegistry::CreateURLInterceptor() { 869 ProtocolHandlerRegistry::CreateURLInterceptor() {
867 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 870 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
868 // this is always created on the UI thread (in profile_io's 871 // this is always created on the UI thread (in profile_io's
869 // InitializeOnUIThread. Any method calls must be done 872 // InitializeOnUIThread. Any method calls must be done
870 // on the IO thread (this is checked). 873 // on the IO thread (this is checked).
871 return new URLInterceptor(core_); 874 return new URLInterceptor(core_);
872 } 875 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698