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

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: Add ChromeURLRequestContext::Copy. 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 663bbe187a8191664ff5a41851e8f1d1442786bd..a03f3cc02921cf2332f9c5fdf575dc20d177e478 100644
--- a/chrome/browser/profiles/off_the_record_profile_io_data.cc
+++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc
@@ -14,6 +14,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 "content/browser/browser_thread.h"
#include "net/ftp/ftp_network_layer.h"
@@ -37,6 +38,14 @@ 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();
+ }
}
scoped_refptr<ChromeURLRequestContextGetter>
@@ -66,6 +75,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 context getters, 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);
@@ -130,6 +161,8 @@ void OffTheRecordProfileIOData::LazyInitializeInternal() const {
main_request_context_->set_cookie_store(
new net::CookieMonster(NULL, profile_params.cookie_monster_delegate));
+ main_request_context_->set_cookie_delegate(
+ profile_params.cookie_monster_delegate);
// All we care about for extensions is the cookie store. For incognito, we
// use a non-persistent cookie store.
@@ -163,6 +196,32 @@ void OffTheRecordProfileIOData::LazyInitializeInternal() const {
new net::FtpNetworkLayer(main_request_context_->host_resolver()));
}
+scoped_refptr<ProfileIOData::RequestContext>
+OffTheRecordProfileIOData::InitializeAppRequestContext(
+ scoped_refptr<ChromeURLRequestContext> main_context,
+ const Extension *app) const {
+ scoped_refptr<ProfileIOData::RequestContext> context = new RequestContext;
+
+ // Copy most state from the main context.
+ 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.
+
+ // Use a separate in-memory cookie store for the app.
+ context->set_cookie_store(
+ new net::CookieMonster(NULL, main_context->cookie_delegate()));
+ 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
+
+ // Use a separate in-memory cache for the app.
+ net::HttpCache::BackendFactory* app_backend =
+ net::HttpCache::DefaultBackend::InMemory(0);
+ net::HttpNetworkSession* main_network_session =
+ main_http_factory_->GetSession();
+ 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.
+ new net::HttpCache(main_network_session, app_backend);
+ 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
+
+ return context;
+}
+
scoped_refptr<ChromeURLRequestContext>
OffTheRecordProfileIOData::AcquireMainRequestContext() const {
DCHECK(main_request_context_);
@@ -186,3 +245,15 @@ OffTheRecordProfileIOData::AcquireExtensionsRequestContext() const {
extensions_request_context_ = NULL;
return context;
}
+
+scoped_refptr<ChromeURLRequestContext>
+OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext(
+ scoped_refptr<ChromeURLRequestContext> main_context,
+ const Extension* installed_app) const {
+ // We create per-app contexts on demand, unlike the others above.
+ scoped_refptr<RequestContext> app_request_context =
+ InitializeAppRequestContext(main_context, 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