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

Side by Side Diff: chrome/browser/profiles/profile_io_data.cc

Issue 10546083: Convert ProtocolHandlerRegistry to be a ProfileKeyedService. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Update content_setting_bubble_model tests to use injected ProtocolHandlerRegistry (integrating Greg… Created 8 years, 5 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
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/profiles/profile_io_data.h" 5 #include "chrome/browser/profiles/profile_io_data.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 #include "base/stringprintf.h" 18 #include "base/stringprintf.h"
19 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/content_settings/cookie_settings.h" 20 #include "chrome/browser/content_settings/cookie_settings.h"
21 #include "chrome/browser/content_settings/host_content_settings_map.h" 21 #include "chrome/browser/content_settings/host_content_settings_map.h"
22 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 22 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
23 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
23 #include "chrome/browser/download/download_service.h" 24 #include "chrome/browser/download/download_service.h"
24 #include "chrome/browser/download/download_service_factory.h" 25 #include "chrome/browser/download/download_service_factory.h"
25 #include "chrome/browser/extensions/extension_info_map.h" 26 #include "chrome/browser/extensions/extension_info_map.h"
26 #include "chrome/browser/extensions/extension_protocols.h" 27 #include "chrome/browser/extensions/extension_protocols.h"
27 #include "chrome/browser/extensions/extension_resource_protocols.h" 28 #include "chrome/browser/extensions/extension_resource_protocols.h"
28 #include "chrome/browser/extensions/extension_system.h" 29 #include "chrome/browser/extensions/extension_system.h"
29 #include "chrome/browser/io_thread.h" 30 #include "chrome/browser/io_thread.h"
30 #include "chrome/browser/net/chrome_cookie_notification_details.h" 31 #include "chrome/browser/net/chrome_cookie_notification_details.h"
31 #include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h" 32 #include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h"
32 #include "chrome/browser/net/chrome_net_log.h" 33 #include "chrome/browser/net/chrome_net_log.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 content::NotificationService::current()->Notify( 109 content::NotificationService::current()->Notify(
109 chrome::NOTIFICATION_COOKIE_CHANGED, 110 chrome::NOTIFICATION_COOKIE_CHANGED,
110 content::Source<Profile>(profile), 111 content::Source<Profile>(profile),
111 content::Details<ChromeCookieDetails>(&cookie_details)); 112 content::Details<ChromeCookieDetails>(&cookie_details));
112 } 113 }
113 } 114 }
114 115
115 const base::Callback<Profile*(void)> profile_getter_; 116 const base::Callback<Profile*(void)> profile_getter_;
116 }; 117 };
117 118
118 class ProtocolHandlerRegistryInterceptor
119 : public net::URLRequestJobFactory::Interceptor {
120 public:
121 explicit ProtocolHandlerRegistryInterceptor(
122 ProtocolHandlerRegistry* protocol_handler_registry)
123 : protocol_handler_registry_(protocol_handler_registry) {
124 DCHECK(protocol_handler_registry_);
125 }
126
127 virtual ~ProtocolHandlerRegistryInterceptor() {}
128
129 virtual net::URLRequestJob* MaybeIntercept(
130 net::URLRequest* request) const OVERRIDE {
131 return protocol_handler_registry_->MaybeCreateJob(request);
132 }
133
134 virtual bool WillHandleProtocol(const std::string& protocol) const {
135 return protocol_handler_registry_->IsHandledProtocolIO(protocol);
136 }
137
138 virtual net::URLRequestJob* MaybeInterceptRedirect(
139 const GURL& url, net::URLRequest* request) const OVERRIDE {
140 return NULL;
141 }
142
143 virtual net::URLRequestJob* MaybeInterceptResponse(
144 net::URLRequest* request) const OVERRIDE {
145 return NULL;
146 }
147
148 private:
149 const scoped_refptr<ProtocolHandlerRegistry> protocol_handler_registry_;
150
151 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistryInterceptor);
152 };
153
154 Profile* GetProfileOnUI(ProfileManager* profile_manager, Profile* profile) { 119 Profile* GetProfileOnUI(ProfileManager* profile_manager, Profile* profile) {
155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
156 DCHECK(profile); 121 DCHECK(profile);
157 if (profile_manager->IsValidProfile(profile)) 122 if (profile_manager->IsValidProfile(profile))
158 return profile; 123 return profile;
159 return NULL; 124 return NULL;
160 } 125 }
161 126
162 } // namespace 127 } // namespace
163 128
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 profile)) { 171 profile)) {
207 resource_prefetch_predictor_observer_.reset( 172 resource_prefetch_predictor_observer_.reset(
208 new chrome_browser_net::ResourcePrefetchPredictorObserver(predictor)); 173 new chrome_browser_net::ResourcePrefetchPredictorObserver(predictor));
209 } 174 }
210 175
211 #if defined(ENABLE_NOTIFICATIONS) 176 #if defined(ENABLE_NOTIFICATIONS)
212 params->notification_service = 177 params->notification_service =
213 DesktopNotificationServiceFactory::GetForProfile(profile); 178 DesktopNotificationServiceFactory::GetForProfile(profile);
214 #endif 179 #endif
215 180
216 params->protocol_handler_registry = profile->GetProtocolHandlerRegistry(); 181 ProtocolHandlerRegistry* protocol_handler_registry =
182 ProtocolHandlerRegistryFactory::GetForProfile(profile);
183 DCHECK(protocol_handler_registry);
184
185 // the profile instance is only available here in the InitializeOnUIThread
186 // method, so we create the url interceptor here, then save it for
187 // later delivery to the job factory in LazyInitialize
188 params->protocol_handler_url_interceptor.reset(
189 protocol_handler_registry->CreateURLInterceptor());
217 190
218 ChromeProxyConfigService* proxy_config_service = 191 ChromeProxyConfigService* proxy_config_service =
219 ProxyServiceFactory::CreateProxyConfigService(true); 192 ProxyServiceFactory::CreateProxyConfigService(true);
220 params->proxy_config_service.reset(proxy_config_service); 193 params->proxy_config_service.reset(proxy_config_service);
221 profile->GetProxyConfigTracker()->SetChromeProxyConfigService( 194 profile->GetProxyConfigTracker()->SetChromeProxyConfigService(
222 proxy_config_service); 195 proxy_config_service);
223 params->profile = profile; 196 params->profile = profile;
224 profile_params_.reset(params.release()); 197 profile_params_.reset(params.release());
225 198
226 // The URLBlacklistManager has to be created on the UI thread to register 199 // The URLBlacklistManager has to be created on the UI thread to register
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 context->set_accept_language(profile_params_->accept_language); 509 context->set_accept_language(profile_params_->accept_language);
537 context->set_accept_charset(profile_params_->accept_charset); 510 context->set_accept_charset(profile_params_->accept_charset);
538 context->set_referrer_charset(profile_params_->referrer_charset); 511 context->set_referrer_charset(profile_params_->referrer_charset);
539 context->set_ssl_config_service(profile_params_->ssl_config_service); 512 context->set_ssl_config_service(profile_params_->ssl_config_service);
540 } 513 }
541 514
542 void ProfileIOData::SetUpJobFactoryDefaults( 515 void ProfileIOData::SetUpJobFactoryDefaults(
543 net::URLRequestJobFactory* job_factory) const { 516 net::URLRequestJobFactory* job_factory) const {
544 // NOTE(willchan): Keep these protocol handlers in sync with 517 // NOTE(willchan): Keep these protocol handlers in sync with
545 // ProfileIOData::IsHandledProtocol(). 518 // ProfileIOData::IsHandledProtocol().
546 if (profile_params_->protocol_handler_registry) { 519
520 if (profile_params_->protocol_handler_url_interceptor.get()) {
547 job_factory->AddInterceptor( 521 job_factory->AddInterceptor(
548 new ProtocolHandlerRegistryInterceptor( 522 profile_params_->protocol_handler_url_interceptor.release());
549 profile_params_->protocol_handler_registry));
550 } 523 }
524
551 bool set_protocol = job_factory->SetProtocolHandler( 525 bool set_protocol = job_factory->SetProtocolHandler(
552 chrome::kExtensionScheme, 526 chrome::kExtensionScheme,
553 CreateExtensionProtocolHandler(is_incognito(), 527 CreateExtensionProtocolHandler(is_incognito(),
554 profile_params_->extension_info_map)); 528 profile_params_->extension_info_map));
555 DCHECK(set_protocol); 529 DCHECK(set_protocol);
556 set_protocol = job_factory->SetProtocolHandler( 530 set_protocol = job_factory->SetProtocolHandler(
557 chrome::kExtensionResourceScheme, 531 chrome::kExtensionResourceScheme,
558 CreateExtensionResourceProtocolHandler()); 532 CreateExtensionResourceProtocolHandler());
559 DCHECK(set_protocol); 533 DCHECK(set_protocol);
560 set_protocol = job_factory->SetProtocolHandler( 534 set_protocol = job_factory->SetProtocolHandler(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 } 574 }
601 575
602 void ProfileIOData::set_server_bound_cert_service( 576 void ProfileIOData::set_server_bound_cert_service(
603 net::ServerBoundCertService* server_bound_cert_service) const { 577 net::ServerBoundCertService* server_bound_cert_service) const {
604 server_bound_cert_service_.reset(server_bound_cert_service); 578 server_bound_cert_service_.reset(server_bound_cert_service);
605 } 579 }
606 580
607 void ProfileIOData::DestroyResourceContext() { 581 void ProfileIOData::DestroyResourceContext() {
608 resource_context_.reset(); 582 resource_context_.reset();
609 } 583 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698