summaryrefslogtreecommitdiffstats
path: root/chrome/browser/profiles
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-12 10:02:36 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-12 10:02:36 +0000
commit8b241822a6eb2ee3ae99eeeac4dd11dda343c42e (patch)
tree7ecea29ab143e1657920cb76fe6e02c2f447a38b /chrome/browser/profiles
parent9a2b3016bd0ecc3d0fef6056b50bd231ff2b8c1b (diff)
downloadchromium_src-8b241822a6eb2ee3ae99eeeac4dd11dda343c42e.zip
chromium_src-8b241822a6eb2ee3ae99eeeac4dd11dda343c42e.tar.gz
chromium_src-8b241822a6eb2ee3ae99eeeac4dd11dda343c42e.tar.bz2
Make ProfileIOData keep track of the app specific request contexts.
Previously, it kept track of just the HttpTransactionFactory objects. Now it tracks the request contexts which define storage for the HttpTransactionFactory. This is a step towards inverting the ownership so the ProfileIOData owns its request contexts, rather than the request contexts sharing ownership of the ProfileIOData. BUG=none TEST=none Review URL: http://codereview.chromium.org/7326033 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92137 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/profiles')
-rw-r--r--chrome/browser/profiles/off_the_record_profile_io_data.cc18
-rw-r--r--chrome/browser/profiles/off_the_record_profile_io_data.h5
-rw-r--r--chrome/browser/profiles/profile_impl_io_data.cc20
-rw-r--r--chrome/browser/profiles/profile_impl_io_data.h5
-rw-r--r--chrome/browser/profiles/profile_io_data.cc36
-rw-r--r--chrome/browser/profiles/profile_io_data.h30
6 files changed, 73 insertions, 41 deletions
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 2a14b28..476c41f 100644
--- a/chrome/browser/profiles/off_the_record_profile_io_data.cc
+++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc
@@ -114,9 +114,7 @@ void OffTheRecordProfileIOData::Handle::LazyInitialize() const {
OffTheRecordProfileIOData::OffTheRecordProfileIOData()
: ProfileIOData(true) {}
-OffTheRecordProfileIOData::~OffTheRecordProfileIOData() {
- STLDeleteValues(&app_http_factory_map_);
-}
+OffTheRecordProfileIOData::~OffTheRecordProfileIOData() {}
void OffTheRecordProfileIOData::LazyInitializeInternal(
ProfileParams* profile_params) const {
@@ -188,7 +186,7 @@ scoped_refptr<ProfileIOData::RequestContext>
OffTheRecordProfileIOData::InitializeAppRequestContext(
scoped_refptr<ChromeURLRequestContext> main_context,
const std::string& app_id) const {
- scoped_refptr<ProfileIOData::RequestContext> context = new RequestContext;
+ AppRequestContext* context = new AppRequestContext(app_id);
// Copy most state from the main context.
context->CopyFrom(main_context);
@@ -196,8 +194,7 @@ OffTheRecordProfileIOData::InitializeAppRequestContext(
// Use a separate in-memory cookie store for the app.
// TODO(creis): We should have a cookie delegate for notifying the cookie
// extensions API, but we need to update it to understand isolated apps first.
- context->set_cookie_store(
- new net::CookieMonster(NULL, NULL));
+ context->SetCookieStore(new net::CookieMonster(NULL, NULL));
// Use a separate in-memory cache for the app.
net::HttpCache::BackendFactory* app_backend =
@@ -207,11 +204,7 @@ OffTheRecordProfileIOData::InitializeAppRequestContext(
net::HttpCache* app_http_cache =
new net::HttpCache(main_network_session, app_backend);
- // Keep track of app_http_cache to delete it when we go away.
- DCHECK(!app_http_factory_map_[app_id]);
- app_http_factory_map_[app_id] = app_http_cache;
- context->set_http_transaction_factory(app_http_cache);
-
+ context->SetHttpTransactionFactory(app_http_cache);
return context;
}
@@ -221,7 +214,7 @@ OffTheRecordProfileIOData::AcquireMediaRequestContext() const {
return NULL;
}
-scoped_refptr<ChromeURLRequestContext>
+scoped_refptr<ProfileIOData::RequestContext>
OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext(
scoped_refptr<ChromeURLRequestContext> main_context,
const std::string& app_id) const {
@@ -229,6 +222,5 @@ OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext(
scoped_refptr<RequestContext> app_request_context =
InitializeAppRequestContext(main_context, app_id);
DCHECK(app_request_context);
- app_request_context->set_profile_io_data(this);
return app_request_context;
}
diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.h b/chrome/browser/profiles/off_the_record_profile_io_data.h
index cad94cb..3904952 100644
--- a/chrome/browser/profiles/off_the_record_profile_io_data.h
+++ b/chrome/browser/profiles/off_the_record_profile_io_data.h
@@ -93,16 +93,13 @@ class OffTheRecordProfileIOData : public ProfileIOData {
const std::string& app_id) const;
virtual scoped_refptr<ChromeURLRequestContext>
AcquireMediaRequestContext() const;
- virtual scoped_refptr<ChromeURLRequestContext>
+ virtual scoped_refptr<RequestContext>
AcquireIsolatedAppRequestContext(
scoped_refptr<ChromeURLRequestContext> main_context,
const std::string& app_id) const;
mutable scoped_ptr<net::HttpTransactionFactory> main_http_factory_;
- // One HttpTransactionFactory per isolated app.
- mutable HttpTransactionFactoryMap app_http_factory_map_;
-
DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileIOData);
};
diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc
index d9a694a..b5cb886 100644
--- a/chrome/browser/profiles/profile_impl_io_data.cc
+++ b/chrome/browser/profiles/profile_impl_io_data.cc
@@ -159,9 +159,7 @@ ProfileImplIOData::LazyParams::~LazyParams() {}
ProfileImplIOData::ProfileImplIOData()
: ProfileIOData(false),
clear_local_state_on_exit_(false) {}
-ProfileImplIOData::~ProfileImplIOData() {
- STLDeleteValues(&app_http_factory_map_);
-}
+ProfileImplIOData::~ProfileImplIOData() {}
void ProfileImplIOData::LazyInitializeInternal(
ProfileParams* profile_params) const {
@@ -299,7 +297,7 @@ scoped_refptr<ProfileIOData::RequestContext>
ProfileImplIOData::InitializeAppRequestContext(
scoped_refptr<ChromeURLRequestContext> main_context,
const std::string& app_id) const {
- scoped_refptr<ProfileIOData::RequestContext> context = new RequestContext;
+ ProfileIOData::AppRequestContext* context = new AppRequestContext(app_id);
// Copy most state from the main context.
context->CopyFrom(main_context);
@@ -351,12 +349,8 @@ ProfileImplIOData::InitializeAppRequestContext(
cookie_store = new net::CookieMonster(cookie_db.get(), NULL);
}
- context->set_cookie_store(cookie_store);
-
- // Keep track of app_http_cache to delete it when we go away.
- DCHECK(!app_http_factory_map_[app_id]);
- app_http_factory_map_[app_id] = app_http_cache;
- context->set_http_transaction_factory(app_http_cache);
+ context->SetCookieStore(cookie_store);
+ context->SetHttpTransactionFactory(app_http_cache);
return context;
}
@@ -365,12 +359,13 @@ scoped_refptr<ChromeURLRequestContext>
ProfileImplIOData::AcquireMediaRequestContext() const {
DCHECK(media_request_context_);
scoped_refptr<ChromeURLRequestContext> context = media_request_context_;
- media_request_context_->set_profile_io_data(this);
+ media_request_context_->set_profile_io_data(
+ const_cast<ProfileImplIOData*>(this));
media_request_context_ = NULL;
return context;
}
-scoped_refptr<ChromeURLRequestContext>
+scoped_refptr<ProfileIOData::RequestContext>
ProfileImplIOData::AcquireIsolatedAppRequestContext(
scoped_refptr<ChromeURLRequestContext> main_context,
const std::string& app_id) const {
@@ -378,6 +373,5 @@ ProfileImplIOData::AcquireIsolatedAppRequestContext(
scoped_refptr<RequestContext> app_request_context =
InitializeAppRequestContext(main_context, app_id);
DCHECK(app_request_context);
- app_request_context->set_profile_io_data(this);
return app_request_context;
}
diff --git a/chrome/browser/profiles/profile_impl_io_data.h b/chrome/browser/profiles/profile_impl_io_data.h
index 105a444..188fa7f 100644
--- a/chrome/browser/profiles/profile_impl_io_data.h
+++ b/chrome/browser/profiles/profile_impl_io_data.h
@@ -109,7 +109,7 @@ class ProfileImplIOData : public ProfileIOData {
const std::string& app_id) const;
virtual scoped_refptr<ChromeURLRequestContext>
AcquireMediaRequestContext() const;
- virtual scoped_refptr<ChromeURLRequestContext>
+ virtual scoped_refptr<RequestContext>
AcquireIsolatedAppRequestContext(
scoped_refptr<ChromeURLRequestContext> main_context,
const std::string& app_id) const;
@@ -122,9 +122,6 @@ class ProfileImplIOData : public ProfileIOData {
mutable scoped_ptr<net::HttpTransactionFactory> main_http_factory_;
mutable scoped_ptr<net::HttpTransactionFactory> media_http_factory_;
- // One HttpTransactionFactory per isolated app.
- mutable HttpTransactionFactoryMap app_http_factory_map_;
-
// Parameters needed for isolated apps.
FilePath app_path_;
mutable bool clear_local_state_on_exit_;
diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc
index fefb5cb..89b40efb 100644
--- a/chrome/browser/profiles/profile_io_data.cc
+++ b/chrome/browser/profiles/profile_io_data.cc
@@ -39,6 +39,7 @@
#include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
#include "content/browser/resource_context.h"
#include "content/common/notification_service.h"
+#include "net/http/http_transaction_factory.h"
#include "net/http/http_util.h"
#include "net/proxy/proxy_config_service_fixed.h"
#include "net/proxy/proxy_script_fetcher_impl.h"
@@ -268,6 +269,25 @@ void ProfileIOData::InitializeProfileParams(Profile* profile) {
ProfileIOData::RequestContext::RequestContext() {}
ProfileIOData::RequestContext::~RequestContext() {}
+ProfileIOData::AppRequestContext::AppRequestContext(const std::string& app_id)
+ : app_id_(app_id) {}
+ProfileIOData::AppRequestContext::~AppRequestContext() {
+ DCHECK(ContainsKey(profile_io_data()->app_request_context_map_, app_id_));
+ profile_io_data()->app_request_context_map_.erase(app_id_);
+}
+
+void ProfileIOData::AppRequestContext::SetCookieStore(
+ net::CookieStore* cookie_store) {
+ cookie_store_ = cookie_store;
+ set_cookie_store(cookie_store);
+}
+
+void ProfileIOData::AppRequestContext::SetHttpTransactionFactory(
+ net::HttpTransactionFactory* http_factory) {
+ http_factory_.reset(http_factory);
+ set_http_transaction_factory(http_factory);
+}
+
ProfileIOData::ProfileParams::ProfileParams()
: is_incognito(false),
clear_local_state_on_exit(false),
@@ -326,7 +346,7 @@ scoped_refptr<ChromeURLRequestContext>
ProfileIOData::GetMainRequestContext() const {
LazyInitialize();
scoped_refptr<RequestContext> context = main_request_context_;
- context->set_profile_io_data(this);
+ context->set_profile_io_data(const_cast<ProfileIOData*>(this));
main_request_context_ = NULL;
return context;
}
@@ -345,7 +365,7 @@ ProfileIOData::GetExtensionsRequestContext() const {
LazyInitialize();
scoped_refptr<RequestContext> context =
extensions_request_context_;
- context->set_profile_io_data(this);
+ context->set_profile_io_data(const_cast<ProfileIOData*>(this));
extensions_request_context_ = NULL;
return context;
}
@@ -355,8 +375,16 @@ ProfileIOData::GetIsolatedAppRequestContext(
scoped_refptr<ChromeURLRequestContext> main_context,
const std::string& app_id) const {
LazyInitialize();
- scoped_refptr<ChromeURLRequestContext> context =
- AcquireIsolatedAppRequestContext(main_context, app_id);
+ scoped_refptr<ChromeURLRequestContext> context;
+ if (ContainsKey(app_request_context_map_, app_id)) {
+ context = app_request_context_map_[app_id];
+ } else {
+ scoped_refptr<RequestContext> request_context =
+ AcquireIsolatedAppRequestContext(main_context, app_id);
+ request_context->set_profile_io_data(const_cast<ProfileIOData*>(this));
+ app_request_context_map_[app_id] = request_context;
+ context = request_context;
+ }
DCHECK(context);
return context;
}
diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h
index 4e7b9c5..dab07ab 100644
--- a/chrome/browser/profiles/profile_io_data.h
+++ b/chrome/browser/profiles/profile_io_data.h
@@ -35,7 +35,9 @@ class FileSystemContext;
} // namespace fileapi
namespace net {
+class CookieStore;
class DnsCertProvenanceChecker;
+class HttpTransactionFactory;
class NetLog;
class ProxyConfigService;
class ProxyService;
@@ -113,12 +115,29 @@ class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> {
virtual ~RequestContext();
// Setter is used to transfer ownership of the ProfileIOData to the context.
- void set_profile_io_data(const ProfileIOData* profile_io_data) {
+ void set_profile_io_data(ProfileIOData* profile_io_data) {
profile_io_data_ = profile_io_data;
}
+ protected:
+ ProfileIOData* profile_io_data() { return profile_io_data_; }
+
private:
- scoped_refptr<const ProfileIOData> profile_io_data_;
+ scoped_refptr<ProfileIOData> profile_io_data_;
+ };
+
+ class AppRequestContext : public RequestContext {
+ public:
+ explicit AppRequestContext(const std::string& app_id);
+ virtual ~AppRequestContext();
+
+ void SetCookieStore(net::CookieStore* cookie_store);
+ void SetHttpTransactionFactory(net::HttpTransactionFactory* http_factory);
+
+ private:
+ const std::string app_id_;
+ scoped_refptr<net::CookieStore> cookie_store_;
+ scoped_ptr<net::HttpTransactionFactory> http_factory_;
};
// Created on the UI thread, read on the IO thread during ProfileIOData lazy
@@ -210,6 +229,9 @@ class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> {
const ProfileIOData* const io_data_;
};
+ typedef base::hash_map<std::string, ChromeURLRequestContext*>
+ AppRequestContextMap;
+
// --------------------------------------------
// Virtual interface for subtypes to implement:
// --------------------------------------------
@@ -228,7 +250,7 @@ class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> {
// context from ProfileIOData to the URLRequestContextGetter.
virtual scoped_refptr<ChromeURLRequestContext>
AcquireMediaRequestContext() const = 0;
- virtual scoped_refptr<ChromeURLRequestContext>
+ virtual scoped_refptr<RequestContext>
AcquireIsolatedAppRequestContext(
scoped_refptr<ChromeURLRequestContext> main_context,
const std::string& app_id) const = 0;
@@ -272,6 +294,8 @@ class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> {
// called.
mutable scoped_refptr<RequestContext> main_request_context_;
mutable scoped_refptr<RequestContext> extensions_request_context_;
+ // One AppRequestContext per isolated app.
+ mutable AppRequestContextMap app_request_context_map_;
// Weak pointers to the request contexts. Only valid after LazyInitialize.
// These are weak so that they don't hold a reference to the RequestContext,