Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/io_thread.h" | 11 #include "chrome/browser/io_thread.h" |
| 12 #include "chrome/browser/net/chrome_cookie_policy.h" | 12 #include "chrome/browser/net/chrome_cookie_policy.h" |
| 13 #include "chrome/browser/net/chrome_dns_cert_provenance_checker_factory.h" | 13 #include "chrome/browser/net/chrome_dns_cert_provenance_checker_factory.h" |
| 14 #include "chrome/browser/net/chrome_net_log.h" | 14 #include "chrome/browser/net/chrome_net_log.h" |
| 15 #include "chrome/browser/net/chrome_network_delegate.h" | 15 #include "chrome/browser/net/chrome_network_delegate.h" |
| 16 #include "chrome/browser/net/chrome_url_request_context.h" | 16 #include "chrome/browser/net/chrome_url_request_context.h" |
| 17 #include "chrome/common/extensions/extension.h" | |
| 17 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 18 #include "content/browser/browser_thread.h" | 19 #include "content/browser/browser_thread.h" |
| 19 #include "net/ftp/ftp_network_layer.h" | 20 #include "net/ftp/ftp_network_layer.h" |
| 20 #include "net/http/http_cache.h" | 21 #include "net/http/http_cache.h" |
| 21 | 22 |
| 22 OffTheRecordProfileIOData::Handle::Handle(Profile* profile) | 23 OffTheRecordProfileIOData::Handle::Handle(Profile* profile) |
| 23 : io_data_(new OffTheRecordProfileIOData), | 24 : io_data_(new OffTheRecordProfileIOData), |
| 24 profile_(profile), | 25 profile_(profile), |
| 25 initialized_(false) { | 26 initialized_(false) { |
| 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 27 DCHECK(profile); | 28 DCHECK(profile); |
| 28 DCHECK(!io_data_->lazy_params_.get()); | 29 DCHECK(!io_data_->lazy_params_.get()); |
| 29 LazyParams* lazy_params = new LazyParams; | 30 LazyParams* lazy_params = new LazyParams; |
| 30 lazy_params->io_thread = g_browser_process->io_thread(); | 31 lazy_params->io_thread = g_browser_process->io_thread(); |
| 31 io_data_->lazy_params_.reset(lazy_params); | 32 io_data_->lazy_params_.reset(lazy_params); |
| 32 } | 33 } |
| 33 | 34 |
| 34 OffTheRecordProfileIOData::Handle::~Handle() { | 35 OffTheRecordProfileIOData::Handle::~Handle() { |
| 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 36 if (main_request_context_getter_) | 37 if (main_request_context_getter_) |
| 37 main_request_context_getter_->CleanupOnUIThread(); | 38 main_request_context_getter_->CleanupOnUIThread(); |
| 38 if (extensions_request_context_getter_) | 39 if (extensions_request_context_getter_) |
| 39 extensions_request_context_getter_->CleanupOnUIThread(); | 40 extensions_request_context_getter_->CleanupOnUIThread(); |
| 41 | |
| 42 // Clean up all isolated app request contexts. | |
| 43 for (ChromeURLRequestContextGetterMap::iterator iter = | |
| 44 app_request_context_getter_map_.begin(); | |
| 45 iter != app_request_context_getter_map_.end(); | |
| 46 ++iter) { | |
| 47 iter->second->CleanupOnUIThread(); | |
| 48 } | |
| 40 } | 49 } |
| 41 | 50 |
| 42 scoped_refptr<ChromeURLRequestContextGetter> | 51 scoped_refptr<ChromeURLRequestContextGetter> |
| 43 OffTheRecordProfileIOData::Handle::GetMainRequestContextGetter() const { | 52 OffTheRecordProfileIOData::Handle::GetMainRequestContextGetter() const { |
| 44 // TODO(oshima): Re-enable when ChromeOS only accesses the profile on the UI | 53 // TODO(oshima): Re-enable when ChromeOS only accesses the profile on the UI |
| 45 // thread. | 54 // thread. |
| 46 #if !defined(OS_CHROMEOS) | 55 #if !defined(OS_CHROMEOS) |
| 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 48 #endif // defined(OS_CHROMEOS) | 57 #endif // defined(OS_CHROMEOS) |
| 49 LazyInitialize(); | 58 LazyInitialize(); |
| 50 if (!main_request_context_getter_) { | 59 if (!main_request_context_getter_) { |
| 51 main_request_context_getter_ = | 60 main_request_context_getter_ = |
| 52 ChromeURLRequestContextGetter::CreateOffTheRecord(profile_, io_data_); | 61 ChromeURLRequestContextGetter::CreateOffTheRecord(profile_, io_data_); |
| 53 } | 62 } |
| 54 return main_request_context_getter_; | 63 return main_request_context_getter_; |
| 55 } | 64 } |
| 56 | 65 |
| 57 scoped_refptr<ChromeURLRequestContextGetter> | 66 scoped_refptr<ChromeURLRequestContextGetter> |
| 58 OffTheRecordProfileIOData::Handle::GetExtensionsRequestContextGetter() const { | 67 OffTheRecordProfileIOData::Handle::GetExtensionsRequestContextGetter() const { |
| 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 60 LazyInitialize(); | 69 LazyInitialize(); |
| 61 if (!extensions_request_context_getter_) { | 70 if (!extensions_request_context_getter_) { |
| 62 extensions_request_context_getter_ = | 71 extensions_request_context_getter_ = |
| 63 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( | 72 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( |
| 64 profile_, io_data_); | 73 profile_, io_data_); |
| 65 } | 74 } |
| 66 return extensions_request_context_getter_; | 75 return extensions_request_context_getter_; |
| 67 } | 76 } |
| 68 | 77 |
| 78 scoped_refptr<ChromeURLRequestContextGetter> | |
| 79 OffTheRecordProfileIOData::Handle::GetIsolatedAppRequestContextGetter( | |
| 80 const Extension* installed_app) const { | |
| 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 82 CHECK(installed_app); | |
| 83 LazyInitialize(); | |
| 84 | |
| 85 // Keep a map of request context getters, one per requested app ID. | |
| 86 std::string id = installed_app->id(); | |
| 87 ChromeURLRequestContextGetterMap::iterator iter = | |
| 88 app_request_context_getter_map_.find(id); | |
| 89 if (iter != app_request_context_getter_map_.end()) | |
| 90 return iter->second; | |
| 91 | |
| 92 ChromeURLRequestContextGetter* context = | |
| 93 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( | |
| 94 profile_, io_data_, installed_app); | |
| 95 app_request_context_getter_map_[id] = context; | |
| 96 | |
| 97 return context; | |
| 98 } | |
| 99 | |
| 69 void OffTheRecordProfileIOData::Handle::LazyInitialize() const { | 100 void OffTheRecordProfileIOData::Handle::LazyInitialize() const { |
| 70 if (!initialized_) { | 101 if (!initialized_) { |
| 71 InitializeProfileParams(profile_, &io_data_->lazy_params_->profile_params); | 102 InitializeProfileParams(profile_, &io_data_->lazy_params_->profile_params); |
| 72 initialized_ = true; | 103 initialized_ = true; |
| 73 } | 104 } |
| 74 } | 105 } |
| 75 | 106 |
| 76 OffTheRecordProfileIOData::LazyParams::LazyParams() : io_thread(NULL) {} | 107 OffTheRecordProfileIOData::LazyParams::LazyParams() : io_thread(NULL) {} |
| 77 OffTheRecordProfileIOData::LazyParams::~LazyParams() {} | 108 OffTheRecordProfileIOData::LazyParams::~LazyParams() {} |
| 78 | 109 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 | 154 |
| 124 main_request_context_->set_proxy_service( | 155 main_request_context_->set_proxy_service( |
| 125 CreateProxyService( | 156 CreateProxyService( |
| 126 io_thread->net_log(), | 157 io_thread->net_log(), |
| 127 io_thread_globals->proxy_script_fetcher_context.get(), | 158 io_thread_globals->proxy_script_fetcher_context.get(), |
| 128 lazy_params_->profile_params.proxy_config_service.release(), | 159 lazy_params_->profile_params.proxy_config_service.release(), |
| 129 command_line)); | 160 command_line)); |
| 130 | 161 |
| 131 main_request_context_->set_cookie_store( | 162 main_request_context_->set_cookie_store( |
| 132 new net::CookieMonster(NULL, profile_params.cookie_monster_delegate)); | 163 new net::CookieMonster(NULL, profile_params.cookie_monster_delegate)); |
| 164 main_request_context_->set_cookie_delegate( | |
| 165 profile_params.cookie_monster_delegate); | |
| 133 // All we care about for extensions is the cookie store. For incognito, we | 166 // All we care about for extensions is the cookie store. For incognito, we |
| 134 // use a non-persistent cookie store. | 167 // use a non-persistent cookie store. |
| 135 | 168 |
| 136 net::CookieMonster* extensions_cookie_store = | 169 net::CookieMonster* extensions_cookie_store = |
| 137 new net::CookieMonster(NULL, NULL); | 170 new net::CookieMonster(NULL, NULL); |
| 138 // Enable cookies for devtools and extension URLs. | 171 // Enable cookies for devtools and extension URLs. |
| 139 const char* schemes[] = {chrome::kChromeDevToolsScheme, | 172 const char* schemes[] = {chrome::kChromeDevToolsScheme, |
| 140 chrome::kExtensionScheme}; | 173 chrome::kExtensionScheme}; |
| 141 extensions_cookie_store->SetCookieableSchemes(schemes, 2); | 174 extensions_cookie_store->SetCookieableSchemes(schemes, 2); |
| 142 | 175 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 156 main_request_context_->network_delegate(), | 189 main_request_context_->network_delegate(), |
| 157 main_request_context_->net_log(), | 190 main_request_context_->net_log(), |
| 158 main_backend); | 191 main_backend); |
| 159 | 192 |
| 160 main_http_factory_.reset(cache); | 193 main_http_factory_.reset(cache); |
| 161 main_request_context_->set_http_transaction_factory(cache); | 194 main_request_context_->set_http_transaction_factory(cache); |
| 162 main_request_context_->set_ftp_transaction_factory( | 195 main_request_context_->set_ftp_transaction_factory( |
| 163 new net::FtpNetworkLayer(main_request_context_->host_resolver())); | 196 new net::FtpNetworkLayer(main_request_context_->host_resolver())); |
| 164 } | 197 } |
| 165 | 198 |
| 199 scoped_refptr<ProfileIOData::RequestContext> | |
| 200 OffTheRecordProfileIOData::InitializeAppRequestContext( | |
| 201 scoped_refptr<ChromeURLRequestContext> main_context, | |
| 202 const Extension *app) const { | |
| 203 scoped_refptr<ProfileIOData::RequestContext> context = new RequestContext; | |
| 204 | |
| 205 // Copy most state from the main context. | |
| 206 main_context->Copy(context); | |
|
willchan no longer on Chromium
2011/03/03 18:16:59
As I read this now, I realize that Copy() makes it
Charlie Reis
2011/03/04 22:34:53
Fixed.
| |
| 207 | |
| 208 // Use a separate in-memory cookie store for the app. | |
| 209 context->set_cookie_store( | |
| 210 new net::CookieMonster(NULL, main_context->cookie_delegate())); | |
| 211 context->set_cookie_delegate(main_context->cookie_delegate()); | |
|
willchan no longer on Chromium
2011/03/03 18:16:59
Rather than forcing cookie_delegate to be a member
Charlie Reis
2011/03/04 22:34:53
Hmm, this is a tricky question to answer, since th
| |
| 212 | |
| 213 // Use a separate in-memory cache for the app. | |
| 214 net::HttpCache::BackendFactory* app_backend = | |
| 215 net::HttpCache::DefaultBackend::InMemory(0); | |
| 216 net::HttpNetworkSession* main_network_session = | |
| 217 main_http_factory_->GetSession(); | |
| 218 net::HttpCache* app_cache = | |
|
willchan no longer on Chromium
2011/03/03 18:16:59
app_cache is used elsewhere in ChromeURLRequestCon
Charlie Reis
2011/03/04 22:34:53
Done.
| |
| 219 new net::HttpCache(main_network_session, app_backend); | |
| 220 context->set_http_transaction_factory(app_cache); | |
|
willchan no longer on Chromium
2011/03/03 18:16:59
Are you leaking the HttpCache?
Note that URLReque
Charlie Reis
2011/03/04 22:34:53
Ah! That answers my question from before about wh
| |
| 221 | |
| 222 return context; | |
| 223 } | |
| 224 | |
| 166 scoped_refptr<ChromeURLRequestContext> | 225 scoped_refptr<ChromeURLRequestContext> |
| 167 OffTheRecordProfileIOData::AcquireMainRequestContext() const { | 226 OffTheRecordProfileIOData::AcquireMainRequestContext() const { |
| 168 DCHECK(main_request_context_); | 227 DCHECK(main_request_context_); |
| 169 scoped_refptr<ChromeURLRequestContext> context = main_request_context_; | 228 scoped_refptr<ChromeURLRequestContext> context = main_request_context_; |
| 170 main_request_context_->set_profile_io_data(this); | 229 main_request_context_->set_profile_io_data(this); |
| 171 main_request_context_ = NULL; | 230 main_request_context_ = NULL; |
| 172 return context; | 231 return context; |
| 173 } | 232 } |
| 174 | 233 |
| 175 scoped_refptr<ChromeURLRequestContext> | 234 scoped_refptr<ChromeURLRequestContext> |
| 176 OffTheRecordProfileIOData::AcquireMediaRequestContext() const { | 235 OffTheRecordProfileIOData::AcquireMediaRequestContext() const { |
| 177 NOTREACHED(); | 236 NOTREACHED(); |
| 178 return NULL; | 237 return NULL; |
| 179 } | 238 } |
| 180 | 239 |
| 181 scoped_refptr<ChromeURLRequestContext> | 240 scoped_refptr<ChromeURLRequestContext> |
| 182 OffTheRecordProfileIOData::AcquireExtensionsRequestContext() const { | 241 OffTheRecordProfileIOData::AcquireExtensionsRequestContext() const { |
| 183 DCHECK(extensions_request_context_); | 242 DCHECK(extensions_request_context_); |
| 184 scoped_refptr<ChromeURLRequestContext> context = extensions_request_context_; | 243 scoped_refptr<ChromeURLRequestContext> context = extensions_request_context_; |
| 185 extensions_request_context_->set_profile_io_data(this); | 244 extensions_request_context_->set_profile_io_data(this); |
| 186 extensions_request_context_ = NULL; | 245 extensions_request_context_ = NULL; |
| 187 return context; | 246 return context; |
| 188 } | 247 } |
| 248 | |
| 249 scoped_refptr<ChromeURLRequestContext> | |
| 250 OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext( | |
| 251 scoped_refptr<ChromeURLRequestContext> main_context, | |
| 252 const Extension* installed_app) const { | |
| 253 // We create per-app contexts on demand, unlike the others above. | |
| 254 scoped_refptr<RequestContext> app_request_context = | |
| 255 InitializeAppRequestContext(main_context, installed_app); | |
| 256 DCHECK(app_request_context); | |
| 257 app_request_context->set_profile_io_data(this); | |
| 258 return app_request_context; | |
| 259 } | |
| OLD | NEW |