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

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

Issue 6825038: Create a content::ResourceContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix dependencies. Created 9 years, 8 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/off_the_record_profile_io_data.h" 5 #include "chrome/browser/profiles/off_the_record_profile_io_data.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/io_thread.h" 12 #include "chrome/browser/io_thread.h"
13 #include "chrome/browser/net/chrome_cookie_policy.h" 13 #include "chrome/browser/net/chrome_cookie_policy.h"
14 #include "chrome/browser/net/chrome_dns_cert_provenance_checker_factory.h" 14 #include "chrome/browser/net/chrome_dns_cert_provenance_checker_factory.h"
15 #include "chrome/browser/net/chrome_net_log.h" 15 #include "chrome/browser/net/chrome_net_log.h"
16 #include "chrome/browser/net/chrome_network_delegate.h" 16 #include "chrome/browser/net/chrome_network_delegate.h"
17 #include "chrome/browser/net/chrome_url_request_context.h" 17 #include "chrome/browser/net/chrome_url_request_context.h"
18 #include "chrome/browser/net/proxy_service_factory.h" 18 #include "chrome/browser/net/proxy_service_factory.h"
19 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
21 #include "content/browser/browser_thread.h" 21 #include "content/browser/browser_thread.h"
22 #include "content/browser/resource_context.h"
22 #include "net/ftp/ftp_network_layer.h" 23 #include "net/ftp/ftp_network_layer.h"
23 #include "net/http/http_cache.h" 24 #include "net/http/http_cache.h"
25 #include "webkit/database/database_tracker.h"
24 26
25 OffTheRecordProfileIOData::Handle::Handle(Profile* profile) 27 OffTheRecordProfileIOData::Handle::Handle(Profile* profile)
26 : io_data_(new OffTheRecordProfileIOData), 28 : io_data_(new OffTheRecordProfileIOData),
27 profile_(profile), 29 profile_(profile),
28 initialized_(false) { 30 initialized_(false) {
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
30 DCHECK(profile); 32 DCHECK(profile);
31 DCHECK(!io_data_->lazy_params_.get()); 33 DCHECK(!io_data_->lazy_params_.get());
32 LazyParams* lazy_params = new LazyParams; 34 LazyParams* lazy_params = new LazyParams;
33 lazy_params->io_thread = g_browser_process->io_thread(); 35 lazy_params->io_thread = g_browser_process->io_thread();
34 io_data_->lazy_params_.reset(lazy_params); 36 io_data_->lazy_params_.reset(lazy_params);
35 } 37 }
36 38
37 OffTheRecordProfileIOData::Handle::~Handle() { 39 OffTheRecordProfileIOData::Handle::~Handle() {
38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
39 if (main_request_context_getter_) 41 if (main_request_context_getter_)
40 main_request_context_getter_->CleanupOnUIThread(); 42 main_request_context_getter_->CleanupOnUIThread();
41 if (extensions_request_context_getter_) 43 if (extensions_request_context_getter_)
42 extensions_request_context_getter_->CleanupOnUIThread(); 44 extensions_request_context_getter_->CleanupOnUIThread();
43 45
44 // Clean up all isolated app request contexts. 46 // Clean up all isolated app request contexts.
45 for (ChromeURLRequestContextGetterMap::iterator iter = 47 for (ChromeURLRequestContextGetterMap::iterator iter =
46 app_request_context_getter_map_.begin(); 48 app_request_context_getter_map_.begin();
47 iter != app_request_context_getter_map_.end(); 49 iter != app_request_context_getter_map_.end();
48 ++iter) { 50 ++iter) {
49 iter->second->CleanupOnUIThread(); 51 iter->second->CleanupOnUIThread();
50 } 52 }
51 } 53 }
52 54
55 const content::ResourceContext&
56 OffTheRecordProfileIOData::Handle::GetResourceContext() const {
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
58 LazyInitialize();
59 return io_data_->GetResourceContext();
60 }
61
53 scoped_refptr<ChromeURLRequestContextGetter> 62 scoped_refptr<ChromeURLRequestContextGetter>
54 OffTheRecordProfileIOData::Handle::GetMainRequestContextGetter() const { 63 OffTheRecordProfileIOData::Handle::GetMainRequestContextGetter() const {
55 // TODO(oshima): Re-enable when ChromeOS only accesses the profile on the UI 64 // TODO(oshima): Re-enable when ChromeOS only accesses the profile on the UI
56 // thread. 65 // thread.
57 #if !defined(OS_CHROMEOS) 66 #if !defined(OS_CHROMEOS)
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
59 #endif // defined(OS_CHROMEOS) 68 #endif // defined(OS_CHROMEOS)
60 LazyInitialize(); 69 LazyInitialize();
61 if (!main_request_context_getter_) { 70 if (!main_request_context_getter_) {
62 main_request_context_getter_ = 71 main_request_context_getter_ =
(...skipping 30 matching lines...) Expand all
93 ChromeURLRequestContextGetter* context = 102 ChromeURLRequestContextGetter* context =
94 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( 103 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp(
95 profile_, io_data_, app_id); 104 profile_, io_data_, app_id);
96 app_request_context_getter_map_[app_id] = context; 105 app_request_context_getter_map_[app_id] = context;
97 106
98 return context; 107 return context;
99 } 108 }
100 109
101 void OffTheRecordProfileIOData::Handle::LazyInitialize() const { 110 void OffTheRecordProfileIOData::Handle::LazyInitialize() const {
102 if (!initialized_) { 111 if (!initialized_) {
103 InitializeProfileParams(profile_, &io_data_->lazy_params_->profile_params); 112 io_data_->InitializeProfileParams(profile_);
104 initialized_ = true; 113 initialized_ = true;
105 } 114 }
106 } 115 }
107 116
108 OffTheRecordProfileIOData::LazyParams::LazyParams() : io_thread(NULL) {} 117 OffTheRecordProfileIOData::LazyParams::LazyParams() : io_thread(NULL) {}
109 OffTheRecordProfileIOData::LazyParams::~LazyParams() {} 118 OffTheRecordProfileIOData::LazyParams::~LazyParams() {}
110 119
111 OffTheRecordProfileIOData::OffTheRecordProfileIOData() 120 OffTheRecordProfileIOData::OffTheRecordProfileIOData()
112 : ProfileIOData(true), 121 : ProfileIOData(true),
113 initialized_(false) {} 122 initialized_(false) {}
114 OffTheRecordProfileIOData::~OffTheRecordProfileIOData() { 123 OffTheRecordProfileIOData::~OffTheRecordProfileIOData() {
115 STLDeleteValues(&app_http_factory_map_); 124 STLDeleteValues(&app_http_factory_map_);
116 } 125 }
117 126
118 void OffTheRecordProfileIOData::LazyInitializeInternal() const { 127 void OffTheRecordProfileIOData::LazyInitializeInternal(
128 ProfileParams* profile_params) const {
119 main_request_context_ = new RequestContext; 129 main_request_context_ = new RequestContext;
120 extensions_request_context_ = new RequestContext; 130 extensions_request_context_ = new RequestContext;
121 131
122 IOThread* const io_thread = lazy_params_->io_thread; 132 IOThread* const io_thread = lazy_params_->io_thread;
123 IOThread::Globals* const io_thread_globals = io_thread->globals(); 133 IOThread::Globals* const io_thread_globals = io_thread->globals();
124 const ProfileParams& profile_params = lazy_params_->profile_params;
125 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 134 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
126 135
127 ApplyProfileParamsToContext(profile_params, main_request_context_); 136 ApplyProfileParamsToContext(main_request_context_);
128 ApplyProfileParamsToContext(profile_params, extensions_request_context_); 137 ApplyProfileParamsToContext(extensions_request_context_);
129 profile_params.appcache_service->set_request_context(main_request_context_); 138 profile_params->appcache_service->set_request_context(main_request_context_);
130 139
131 cookie_policy_.reset( 140 cookie_policy_.reset(
132 new ChromeCookiePolicy(profile_params.host_content_settings_map)); 141 new ChromeCookiePolicy(profile_params->host_content_settings_map));
133 main_request_context_->set_cookie_policy(cookie_policy_.get()); 142 main_request_context_->set_cookie_policy(cookie_policy_.get());
134 extensions_request_context_->set_cookie_policy(cookie_policy_.get()); 143 extensions_request_context_->set_cookie_policy(cookie_policy_.get());
135 144
136 main_request_context_->set_net_log(lazy_params_->io_thread->net_log()); 145 main_request_context_->set_net_log(lazy_params_->io_thread->net_log());
137 extensions_request_context_->set_net_log(lazy_params_->io_thread->net_log()); 146 extensions_request_context_->set_net_log(lazy_params_->io_thread->net_log());
138 147
139 network_delegate_.reset(new ChromeNetworkDelegate( 148 network_delegate_.reset(new ChromeNetworkDelegate(
140 io_thread_globals->extension_event_router_forwarder.get(), 149 io_thread_globals->extension_event_router_forwarder.get(),
141 profile_params.profile_id, 150 profile_params->profile_id,
142 profile_params.protocol_handler_registry)); 151 profile_params->protocol_handler_registry));
143 main_request_context_->set_network_delegate(network_delegate_.get()); 152 main_request_context_->set_network_delegate(network_delegate_.get());
144 153
145 main_request_context_->set_host_resolver( 154 main_request_context_->set_host_resolver(
146 io_thread_globals->host_resolver.get()); 155 io_thread_globals->host_resolver.get());
147 main_request_context_->set_cert_verifier( 156 main_request_context_->set_cert_verifier(
148 io_thread_globals->cert_verifier.get()); 157 io_thread_globals->cert_verifier.get());
149 main_request_context_->set_dnsrr_resolver( 158 main_request_context_->set_dnsrr_resolver(
150 io_thread_globals->dnsrr_resolver.get()); 159 io_thread_globals->dnsrr_resolver.get());
151 main_request_context_->set_http_auth_handler_factory( 160 main_request_context_->set_http_auth_handler_factory(
152 io_thread_globals->http_auth_handler_factory.get()); 161 io_thread_globals->http_auth_handler_factory.get());
153 162
154 dns_cert_checker_.reset( 163 dns_cert_checker_.reset(
155 CreateDnsCertProvenanceChecker(io_thread_globals->dnsrr_resolver.get(), 164 CreateDnsCertProvenanceChecker(io_thread_globals->dnsrr_resolver.get(),
156 main_request_context_)); 165 main_request_context_));
157 main_request_context_->set_dns_cert_checker(dns_cert_checker_.get()); 166 main_request_context_->set_dns_cert_checker(dns_cert_checker_.get());
158 167
159 main_request_context_->set_proxy_service( 168 main_request_context_->set_proxy_service(
160 ProxyServiceFactory::CreateProxyService( 169 ProxyServiceFactory::CreateProxyService(
161 io_thread->net_log(), 170 io_thread->net_log(),
162 io_thread_globals->proxy_script_fetcher_context.get(), 171 io_thread_globals->proxy_script_fetcher_context.get(),
163 lazy_params_->profile_params.proxy_config_service.release(), 172 profile_params->proxy_config_service.release(),
164 command_line)); 173 command_line));
165 174
166 main_request_context_->set_cookie_store( 175 main_request_context_->set_cookie_store(
167 new net::CookieMonster(NULL, profile_params.cookie_monster_delegate)); 176 new net::CookieMonster(NULL, profile_params->cookie_monster_delegate));
168 // All we care about for extensions is the cookie store. For incognito, we 177 // All we care about for extensions is the cookie store. For incognito, we
169 // use a non-persistent cookie store. 178 // use a non-persistent cookie store.
170 179
171 net::CookieMonster* extensions_cookie_store = 180 net::CookieMonster* extensions_cookie_store =
172 new net::CookieMonster(NULL, NULL); 181 new net::CookieMonster(NULL, NULL);
173 // Enable cookies for devtools and extension URLs. 182 // Enable cookies for devtools and extension URLs.
174 const char* schemes[] = {chrome::kChromeDevToolsScheme, 183 const char* schemes[] = {chrome::kChromeDevToolsScheme,
175 chrome::kExtensionScheme}; 184 chrome::kExtensionScheme};
176 extensions_cookie_store->SetCookieableSchemes(schemes, 2); 185 extensions_cookie_store->SetCookieableSchemes(schemes, 2);
177 186
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext( 266 OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext(
258 scoped_refptr<ChromeURLRequestContext> main_context, 267 scoped_refptr<ChromeURLRequestContext> main_context,
259 const std::string& app_id) const { 268 const std::string& app_id) const {
260 // We create per-app contexts on demand, unlike the others above. 269 // We create per-app contexts on demand, unlike the others above.
261 scoped_refptr<RequestContext> app_request_context = 270 scoped_refptr<RequestContext> app_request_context =
262 InitializeAppRequestContext(main_context, app_id); 271 InitializeAppRequestContext(main_context, app_id);
263 DCHECK(app_request_context); 272 DCHECK(app_request_context);
264 app_request_context->set_profile_io_data(this); 273 app_request_context->set_profile_io_data(this);
265 return app_request_context; 274 return app_request_context;
266 } 275 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698