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

Unified Diff: chrome/browser/profiles/off_the_record_profile_io_data.cc

Issue 6201005: Initial support for partitioning cookies for isolated apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactor and address comments. Created 9 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profiles/off_the_record_profile_io_data.cc
diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.cc b/chrome/browser/profiles/off_the_record_profile_io_data.cc
index 72cce734a916a16c2859d9b43b38ef9b1e964f7f..456a1e1ee30f413633fc5fd43c41350233cc9760 100644
--- a/chrome/browser/profiles/off_the_record_profile_io_data.cc
+++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/net/chrome_net_log.h"
#include "chrome/browser/net/chrome_network_delegate.h"
#include "chrome/browser/net/chrome_url_request_context.h"
+#include "chrome/common/extensions/extension.h"
#include "chrome/common/url_constants.h"
#include "net/ftp/ftp_network_layer.h"
#include "net/http/http_cache.h"
@@ -38,6 +39,33 @@ OffTheRecordProfileIOData::Handle::~Handle() {
main_request_context_getter_->CleanupOnUIThread();
if (extensions_request_context_getter_)
extensions_request_context_getter_->CleanupOnUIThread();
+
+ // Clean up all isolated app request contexts.
+ for (ChromeURLRequestContextGetterMap::iterator iter =
+ app_request_context_getter_map_.begin();
+ iter != app_request_context_getter_map_.end();
+ ++iter) {
+ iter->second->CleanupOnUIThread();
+ }
+}
+
+void OffTheRecordProfileIOData::Handle::InitIsolatedApp(
+ const Extension* installed_app) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ // This may be called multiple times before InitializeAppRequestContext.
+ // Only do the initialization once.
+ std::string id = installed_app->id();
+ if (io_data_->lazy_params_map_.find(id) != io_data_->lazy_params_map_.end())
+ return;
+
+ LazyParams* lazy_params = new LazyParams;
+ lazy_params->io_thread = g_browser_process->io_thread();
+
+ InitializeProfileParams(profile_, &lazy_params->profile_params);
+
+ // Keep track of this app's LazyParams until InitializeAppRequestContext.
+ io_data_->lazy_params_map_[id] = lazy_params;
}
scoped_refptr<ChromeURLRequestContextGetter>
@@ -67,6 +95,28 @@ OffTheRecordProfileIOData::Handle::GetExtensionsRequestContextGetter() const {
return extensions_request_context_getter_;
}
+scoped_refptr<ChromeURLRequestContextGetter>
+OffTheRecordProfileIOData::Handle::GetIsolatedAppRequestContextGetter(
+ const Extension* installed_app) const {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ CHECK(installed_app);
+ LazyInitialize();
+
+ // Keep a map of request contexts, one per requested app ID.
+ std::string id = installed_app->id();
+ ChromeURLRequestContextGetterMap::iterator iter =
+ app_request_context_getter_map_.find(id);
+ if (iter != app_request_context_getter_map_.end())
+ return iter->second;
+
+ ChromeURLRequestContextGetter* context =
+ ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp(
+ profile_, io_data_, installed_app);
+ app_request_context_getter_map_[id] = context;
+
+ return context;
+}
+
void OffTheRecordProfileIOData::Handle::LazyInitialize() const {
if (!initialized_) {
InitializeProfileParams(profile_, &io_data_->lazy_params_->profile_params);
@@ -164,6 +214,66 @@ void OffTheRecordProfileIOData::LazyInitializeInternal() const {
new net::FtpNetworkLayer(main_request_context_->host_resolver()));
}
+scoped_refptr<ProfileIOData::RequestContext>
+OffTheRecordProfileIOData::InitializeAppRequestContext(
+ const Extension *app) const {
+ scoped_refptr<ProfileIOData::RequestContext> context = new RequestContext;
+
+ // Get the app-specific LazyParams, which was created in InitIsolatedApp.
+ std::string id = app->id();
+ LazyParamsMap::iterator iter = lazy_params_map_.find(id);
+ DCHECK(iter != lazy_params_map_.end());
+ scoped_ptr<LazyParams> lazy_params(iter->second);
+
+ IOThread* const io_thread = lazy_params->io_thread;
+ IOThread::Globals* const io_thread_globals = io_thread->globals();
+ const ProfileParams& profile_params = lazy_params->profile_params;
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+
+ ApplyProfileParamsToContext(profile_params, context);
willchan no longer on Chromium 2011/03/01 23:39:24 I'm concerned about all this code duplication here
Charlie Reis 2011/03/03 01:08:05 Yes, this is a better approach. I think I still n
+
+ scoped_refptr<ChromeCookiePolicy> cookie_policy =
+ new ChromeCookiePolicy(profile_params.host_content_settings_map);
+ context->set_chrome_cookie_policy(cookie_policy);
+
+ context->set_net_log(lazy_params->io_thread->net_log());
+
+ DCHECK(network_delegate_.get());
+ context->set_network_delegate(network_delegate_.get());
+
+ context->set_host_resolver(io_thread_globals->host_resolver.get());
+ context->set_cert_verifier(io_thread_globals->cert_verifier.get());
+ context->set_dnsrr_resolver(io_thread_globals->dnsrr_resolver.get());
+ context->set_http_auth_handler_factory(
+ io_thread_globals->http_auth_handler_factory.get());
+
+ DCHECK(dns_cert_checker_.get());
+ context->set_dns_cert_checker(dns_cert_checker_.get());
willchan no longer on Chromium 2011/03/01 23:39:24 In answer to your earlier question, this is OK to
Charlie Reis 2011/03/03 01:08:05 Thanks.
+
+ context->set_proxy_service(
willchan no longer on Chromium 2011/03/01 23:39:24 We should be sharing this guy.
Charlie Reis 2011/03/03 01:08:05 Fixed (via the new Copy method).
+ CreateProxyService(
+ io_thread->net_log(),
+ io_thread_globals->proxy_script_fetcher_context.get(),
+ lazy_params->profile_params.proxy_config_service.release(),
+ command_line));
+
+ context->set_cookie_store(
+ new net::CookieMonster(NULL, profile_params.cookie_monster_delegate));
+
+ net::HttpCache::BackendFactory* app_backend =
+ net::HttpCache::DefaultBackend::InMemory(0);
+ net::HttpNetworkSession* main_network_session = main_http_factory_->GetSession();
+ net::HttpCache* app_cache =
+ new net::HttpCache(main_network_session, app_backend);
+
+ context->set_http_transaction_factory(app_cache);
+ context->set_ftp_transaction_factory(
+ new net::FtpNetworkLayer(context->host_resolver()));
+
+ lazy_params_map_.erase(iter);
+ return context;
+}
+
scoped_refptr<ChromeURLRequestContext>
OffTheRecordProfileIOData::AcquireMainRequestContext() const {
DCHECK(main_request_context_);
@@ -187,3 +297,14 @@ OffTheRecordProfileIOData::AcquireExtensionsRequestContext() const {
extensions_request_context_ = NULL;
return context;
}
+
+scoped_refptr<ChromeURLRequestContext>
+OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext(
+ const Extension* installed_app) const {
+ // We create per-app contexts on demand, unlike the others above.
+ scoped_refptr<RequestContext> app_request_context =
+ InitializeAppRequestContext(installed_app);
+ DCHECK(app_request_context);
+ app_request_context->set_profile_io_data(this);
+ return app_request_context;
+}

Powered by Google App Engine
This is Rietveld 408576698