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

Unified Diff: chrome/browser/net/chrome_url_request_context.cc

Issue 360030: Reorder the definitions in chrome_url_request_context.cc to match the declara... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: link to a bug number Created 11 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/chrome_url_request_context.cc
===================================================================
--- chrome/browser/net/chrome_url_request_context.cc (revision 31010)
+++ chrome/browser/net/chrome_url_request_context.cc (working copy)
@@ -33,81 +33,29 @@
#include "net/ocsp/nss_ocsp.h"
#endif
-// TODO(eroman): Fix the definition ordering to match-up with the declaration
-// ordering (this was done to help keep the diffs simple during
-// refactor).
-
+namespace {
// TODO(eroman): The ChromeURLRequestContext's Blacklist* is shared with the
// Profile... This is a problem since the Profile dies before
// the IO thread, so we may end up accessing a deleted variable.
+// http://crbug.com/26733.
-static void CheckCurrentlyOnIOThread() {
+// ----------------------------------------------------------------------------
+// Helper methods to check current thread
+// ----------------------------------------------------------------------------
+
+void CheckCurrentlyOnIOThread() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
}
-static void CheckCurrentlyOnMainThread() {
+void CheckCurrentlyOnMainThread() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
}
-net::ProxyConfig* CreateProxyConfig(const CommandLine& command_line) {
- // Scan for all "enable" type proxy switches.
- static const char* proxy_switches[] = {
- switches::kProxyServer,
- switches::kProxyPacUrl,
- switches::kProxyAutoDetect,
- switches::kProxyBypassList
- };
+// ----------------------------------------------------------------------------
+// Helper methods to initialize proxy
+// ----------------------------------------------------------------------------
- bool found_enable_proxy_switch = false;
- for (size_t i = 0; i < arraysize(proxy_switches); i++) {
- if (command_line.HasSwitch(proxy_switches[i])) {
- found_enable_proxy_switch = true;
- break;
- }
- }
-
- if (!found_enable_proxy_switch &&
- !command_line.HasSwitch(switches::kNoProxyServer)) {
- return NULL;
- }
-
- net::ProxyConfig* proxy_config = new net::ProxyConfig();
- if (command_line.HasSwitch(switches::kNoProxyServer)) {
- // Ignore (and warn about) all the other proxy config switches we get if
- // the --no-proxy-server command line argument is present.
- if (found_enable_proxy_switch) {
- LOG(WARNING) << "Additional command line proxy switches found when --"
- << switches::kNoProxyServer << " was specified.";
- }
- return proxy_config;
- }
-
- if (command_line.HasSwitch(switches::kProxyServer)) {
- const std::wstring& proxy_server =
- command_line.GetSwitchValue(switches::kProxyServer);
- proxy_config->proxy_rules.ParseFromString(WideToASCII(proxy_server));
- }
-
- if (command_line.HasSwitch(switches::kProxyPacUrl)) {
- proxy_config->pac_url =
- GURL(WideToASCII(command_line.GetSwitchValue(
- switches::kProxyPacUrl)));
- }
-
- if (command_line.HasSwitch(switches::kProxyAutoDetect)) {
- proxy_config->auto_detect = true;
- }
-
- if (command_line.HasSwitch(switches::kProxyBypassList)) {
- proxy_config->ParseNoProxyList(
- WideToASCII(command_line.GetSwitchValue(
- switches::kProxyBypassList)));
- }
-
- return proxy_config;
-}
-
-static net::ProxyConfigService* CreateProxyConfigService(
+net::ProxyConfigService* CreateProxyConfigService(
const CommandLine& command_line) {
// The linux gconf-based proxy settings getter relies on being initialized
// from the UI thread.
@@ -131,7 +79,7 @@
}
// Create a proxy service according to the options on command line.
-static net::ProxyService* CreateProxyService(
+net::ProxyService* CreateProxyService(
URLRequestContext* context,
net::ProxyConfigService* proxy_config_service,
const CommandLine& command_line,
@@ -153,19 +101,10 @@
io_loop);
}
-// Lazily create a ChromeURLRequestContext using our factory.
-URLRequestContext* ChromeURLRequestContextGetter::GetURLRequestContext() {
- CheckCurrentlyOnIOThread();
+// ----------------------------------------------------------------------------
+// Helper factories
+// ----------------------------------------------------------------------------
- if (!url_request_context_) {
- DCHECK(factory_.get());
- url_request_context_ = factory_->Create();
- factory_.reset();
- }
-
- return url_request_context_;
-}
-
// Factory that creates the main ChromeURLRequestContext.
class FactoryForOriginal : public ChromeURLRequestContextFactory {
public:
@@ -195,19 +134,6 @@
scoped_ptr<net::ProxyConfigService> proxy_config_service_;
};
-// static
-ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::CreateOriginal(
- Profile* profile, const FilePath& cookie_store_path,
- const FilePath& disk_cache_path, int cache_size) {
- DCHECK(!profile->IsOffTheRecord());
- return new ChromeURLRequestContextGetter(
- profile,
- new FactoryForOriginal(profile,
- cookie_store_path,
- disk_cache_path,
- cache_size));
-}
-
ChromeURLRequestContext* FactoryForOriginal::Create() {
ChromeURLRequestContext* context = new ChromeURLRequestContext;
ApplyProfileParametersToContext(context);
@@ -278,15 +204,6 @@
return context;
}
-// static
-ChromeURLRequestContextGetter*
-ChromeURLRequestContextGetter::CreateOriginalForMedia(
- Profile* profile, const FilePath& disk_cache_path, int cache_size) {
- DCHECK(!profile->IsOffTheRecord());
- return CreateRequestContextForMedia(profile, disk_cache_path, cache_size,
- false);
-}
-
// Factory that creates the ChromeURLRequestContext for extensions.
class FactoryForExtensions : public ChromeURLRequestContextFactory {
public:
@@ -301,16 +218,6 @@
FilePath cookie_store_path_;
};
-// static
-ChromeURLRequestContextGetter*
-ChromeURLRequestContextGetter::CreateOriginalForExtensions(
- Profile* profile, const FilePath& cookie_store_path) {
- DCHECK(!profile->IsOffTheRecord());
- return new ChromeURLRequestContextGetter(
- profile,
- new FactoryForExtensions(profile, cookie_store_path));
-}
-
ChromeURLRequestContext* FactoryForExtensions::Create() {
ChromeURLRequestContext* context = new ChromeURLRequestContext;
ApplyProfileParametersToContext(context);
@@ -346,14 +253,6 @@
scoped_refptr<ChromeURLRequestContextGetter> original_context_getter_;
};
-// static
-ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::CreateOffTheRecord(
- Profile* profile) {
- DCHECK(profile->IsOffTheRecord());
- return new ChromeURLRequestContextGetter(
- profile, new FactoryForOffTheRecord(profile));
-}
-
ChromeURLRequestContext* FactoryForOffTheRecord::Create() {
ChromeURLRequestContext* context = new ChromeURLRequestContext;
ApplyProfileParametersToContext(context);
@@ -410,15 +309,6 @@
virtual ChromeURLRequestContext* Create();
};
-// static
-ChromeURLRequestContextGetter*
-ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(Profile* profile) {
- DCHECK(profile->IsOffTheRecord());
- return new ChromeURLRequestContextGetter(
- profile,
- new FactoryForOffTheRecordExtensions(profile));
-}
-
ChromeURLRequestContext* FactoryForOffTheRecordExtensions::Create() {
ChromeURLRequestContext* context = new ChromeURLRequestContext;
ApplyProfileParametersToContext(context);
@@ -459,19 +349,6 @@
int cache_size_;
};
-// static
-ChromeURLRequestContextGetter*
-ChromeURLRequestContextGetter::CreateRequestContextForMedia(
- Profile* profile, const FilePath& disk_cache_path, int cache_size,
- bool off_the_record) {
- return new ChromeURLRequestContextGetter(
- profile,
- new FactoryForMedia(profile,
- disk_cache_path,
- cache_size,
- off_the_record));
-}
-
ChromeURLRequestContext* FactoryForMedia::Create() {
ChromeURLRequestContext* context = new ChromeURLRequestContext;
ApplyProfileParametersToContext(context);
@@ -524,6 +401,12 @@
return context;
}
+} // namespace
+
+// ----------------------------------------------------------------------------
+// ChromeURLRequestContextGetter
+// ----------------------------------------------------------------------------
+
ChromeURLRequestContextGetter::ChromeURLRequestContextGetter(
Profile* profile,
ChromeURLRequestContextFactory* factory)
@@ -537,127 +420,137 @@
RegisterPrefsObserver(profile);
}
-// Extract values from |profile| and copy them into
-// ChromeURLRequestContextFactory. We will use them later when constructing the
-// ChromeURLRequestContext on the IO thread (see
-// ApplyProfileParametersToContext() which reverses this).
-ChromeURLRequestContextFactory::ChromeURLRequestContextFactory(Profile* profile)
- : is_media_(false),
- is_off_the_record_(profile->IsOffTheRecord()) {
- CheckCurrentlyOnMainThread();
- PrefService* prefs = profile->GetPrefs();
+ChromeURLRequestContextGetter::~ChromeURLRequestContextGetter() {
+ CheckCurrentlyOnIOThread();
- // Set up Accept-Language and Accept-Charset header values
- accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader(
- WideToASCII(prefs->GetString(prefs::kAcceptLanguages)));
- std::string default_charset =
- WideToASCII(prefs->GetString(prefs::kDefaultCharset));
- accept_charset_ =
- net::HttpUtil::GenerateAcceptCharsetHeader(default_charset);
+ DCHECK(!prefs_) << "Probably didn't call CleanupOnUIThread";
- // At this point, we don't know the charset of the referring page
- // where a url request originates from. This is used to get a suggested
- // filename from Content-Disposition header made of raw 8bit characters.
- // Down the road, it can be overriden if it becomes known (for instance,
- // when download request is made through the context menu in a web page).
- // At the moment, it'll remain 'undeterministic' when a user
- // types a URL in the omnibar or click on a download link in a page.
- // For the latter, we need a change on the webkit-side.
- // We initialize it to the default charset here and a user will
- // have an *arguably* better default charset for interpreting a raw 8bit
- // C-D header field. It means the native OS codepage fallback in
- // net_util::GetSuggestedFilename is unlikely to be taken.
- referrer_charset_ = default_charset;
+ // Either we already transformed the factory into a URLRequestContext, or
+ // we still have a pending factory.
+ DCHECK((factory_.get() && !url_request_context_.get()) ||
+ (!factory_.get() && url_request_context_.get()));
- cookie_policy_type_ = net::CookiePolicy::FromInt(
- prefs->GetInteger(prefs::kCookieBehavior));
+ // The scoped_refptr / scoped_ptr destructors take care of releasing
+ // |factory_| and |url_request_context_| now.
+}
- // TODO(eroman): this doesn't look safe; sharing between IO and UI threads!
- blacklist_ = profile->GetBlacklist();
+// Lazily create a ChromeURLRequestContext using our factory.
+URLRequestContext* ChromeURLRequestContextGetter::GetURLRequestContext() {
+ CheckCurrentlyOnIOThread();
- // TODO(eroman): this doesn't look safe; sharing between IO and UI threads!
- strict_transport_security_state_ = profile->GetStrictTransportSecurityState();
-
- if (profile->GetExtensionsService()) {
- const ExtensionList* extensions =
- profile->GetExtensionsService()->extensions();
- for (ExtensionList::const_iterator iter = extensions->begin();
- iter != extensions->end(); ++iter) {
- extension_paths_[(*iter)->id()] = (*iter)->path();
- }
+ if (!url_request_context_) {
+ DCHECK(factory_.get());
+ url_request_context_ = factory_->Create();
+ factory_.reset();
}
- if (profile->GetUserScriptMaster())
- user_script_dir_path_ = profile->GetUserScriptMaster()->user_script_dir();
+ return url_request_context_;
+}
- // TODO(eroman): this doesn't look safe; sharing between IO and UI threads!
- ssl_config_service_ = profile->GetSSLConfigService();
+net::CookieStore* ChromeURLRequestContextGetter::GetCookieStore() {
+ // If we are running on the IO thread this is real easy.
+ if (ChromeThread::CurrentlyOn(ChromeThread::IO))
+ return GetURLRequestContext()->cookie_store();
- profile_dir_path_ = profile->GetPath();
+ // If we aren't running on the IO thread, we cannot call
+ // GetURLRequestContext(). Instead we will post a task to the IO loop
+ // and wait for it to complete.
+
+ base::WaitableEvent completion(false, false);
+ net::CookieStore* result = NULL;
+
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this,
+ &ChromeURLRequestContextGetter::GetCookieStoreAsyncHelper,
+ &completion,
+ &result));
+
+ completion.Wait();
+ DCHECK(result);
+ return result;
}
-ChromeURLRequestContextFactory::~ChromeURLRequestContextFactory() {
- CheckCurrentlyOnIOThread();
+// static
+ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::CreateOriginal(
+ Profile* profile, const FilePath& cookie_store_path,
+ const FilePath& disk_cache_path, int cache_size) {
+ DCHECK(!profile->IsOffTheRecord());
+ return new ChromeURLRequestContextGetter(
+ profile,
+ new FactoryForOriginal(profile,
+ cookie_store_path,
+ disk_cache_path,
+ cache_size));
}
-void ChromeURLRequestContextFactory::ApplyProfileParametersToContext(
- ChromeURLRequestContext* context) {
- // Apply all the parameters. NOTE: keep this in sync with
- // ChromeURLRequestContextFactory(Profile*).
- context->set_is_media(is_media_);
- context->set_is_off_the_record(is_off_the_record_);
- context->set_accept_language(accept_language_);
- context->set_accept_charset(accept_charset_);
- context->set_referrer_charset(referrer_charset_);
- context->set_cookie_policy_type(cookie_policy_type_);
- context->set_extension_paths(extension_paths_);
- context->set_user_script_dir_path(user_script_dir_path_);
- context->set_blacklist(blacklist_);
- context->set_strict_transport_security_state(
- strict_transport_security_state_);
- context->set_ssl_config_service(ssl_config_service_);
+// static
+ChromeURLRequestContextGetter*
+ChromeURLRequestContextGetter::CreateOriginalForMedia(
+ Profile* profile, const FilePath& disk_cache_path, int cache_size) {
+ DCHECK(!profile->IsOffTheRecord());
+ return CreateRequestContextForMedia(profile, disk_cache_path, cache_size,
+ false);
}
-void ChromeURLRequestContextGetter::RegisterPrefsObserver(Profile* profile) {
- CheckCurrentlyOnMainThread();
+// static
+ChromeURLRequestContextGetter*
+ChromeURLRequestContextGetter::CreateOriginalForExtensions(
+ Profile* profile, const FilePath& cookie_store_path) {
+ DCHECK(!profile->IsOffTheRecord());
+ return new ChromeURLRequestContextGetter(
+ profile,
+ new FactoryForExtensions(profile, cookie_store_path));
+}
- prefs_ = profile->GetPrefs();
+// static
+ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::CreateOffTheRecord(
+ Profile* profile) {
+ DCHECK(profile->IsOffTheRecord());
+ return new ChromeURLRequestContextGetter(
+ profile, new FactoryForOffTheRecord(profile));
+}
- prefs_->AddPrefObserver(prefs::kAcceptLanguages, this);
- prefs_->AddPrefObserver(prefs::kCookieBehavior, this);
- prefs_->AddPrefObserver(prefs::kDefaultCharset, this);
+// static
+ChromeURLRequestContextGetter*
+ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(Profile* profile) {
+ DCHECK(profile->IsOffTheRecord());
+ return new ChromeURLRequestContextGetter(
+ profile,
+ new FactoryForOffTheRecordExtensions(profile));
}
-ChromeURLRequestContext::ChromeURLRequestContext(
- ChromeURLRequestContext* other) {
- CheckCurrentlyOnIOThread();
+void ChromeURLRequestContextGetter::CleanupOnUIThread() {
+ CheckCurrentlyOnMainThread();
- // Set URLRequestContext members
- host_resolver_ = other->host_resolver_;
- proxy_service_ = other->proxy_service_;
- ssl_config_service_ = other->ssl_config_service_;
- http_transaction_factory_ = other->http_transaction_factory_;
- ftp_transaction_factory_ = other->ftp_transaction_factory_;
- cookie_store_ = other->cookie_store_;
- cookie_policy_.set_type(other->cookie_policy_.type());
- strict_transport_security_state_ = other->strict_transport_security_state_;
- accept_language_ = other->accept_language_;
- accept_charset_ = other->accept_charset_;
- referrer_charset_ = other->referrer_charset_;
+ if (prefs_) {
+ // Unregister for pref notifications.
+ prefs_->RemovePrefObserver(prefs::kAcceptLanguages, this);
+ prefs_->RemovePrefObserver(prefs::kCookieBehavior, this);
+ prefs_->RemovePrefObserver(prefs::kDefaultCharset, this);
+ prefs_ = NULL;
+ }
- // Set ChromeURLRequestContext members
- appcache_service_ = other->appcache_service_;
- extension_paths_ = other->extension_paths_;
- user_script_dir_path_ = other->user_script_dir_path_;
- blacklist_ = other->blacklist_;
- is_media_ = other->is_media_;
- is_off_the_record_ = other->is_off_the_record_;
+ // TODO(eroman): Doesn't look like this member is even used...
+ // can probably be deleted.
+ registrar_.RemoveAll();
}
+void ChromeURLRequestContextGetter::OnNewExtensions(const std::string& id,
+ const FilePath& path) {
+ GetIOContext()->OnNewExtensions(id, path);
+}
+
+void ChromeURLRequestContextGetter::OnUnloadedExtension(
+ const std::string& id) {
+ GetIOContext()->OnUnloadedExtension(id);
+}
+
// NotificationObserver implementation.
-void ChromeURLRequestContextGetter::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
+void ChromeURLRequestContextGetter::Observe(
+ NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
CheckCurrentlyOnMainThread();
if (NotificationType::PREF_CHANGED == type) {
@@ -697,6 +590,29 @@
}
}
+void ChromeURLRequestContextGetter::RegisterPrefsObserver(Profile* profile) {
+ CheckCurrentlyOnMainThread();
+
+ prefs_ = profile->GetPrefs();
+
+ prefs_->AddPrefObserver(prefs::kAcceptLanguages, this);
+ prefs_->AddPrefObserver(prefs::kCookieBehavior, this);
+ prefs_->AddPrefObserver(prefs::kDefaultCharset, this);
+}
+
+// static
+ChromeURLRequestContextGetter*
+ChromeURLRequestContextGetter::CreateRequestContextForMedia(
+ Profile* profile, const FilePath& disk_cache_path, int cache_size,
+ bool off_the_record) {
+ return new ChromeURLRequestContextGetter(
+ profile,
+ new FactoryForMedia(profile,
+ disk_cache_path,
+ cache_size,
+ off_the_record));
+}
+
void ChromeURLRequestContextGetter::OnAcceptLanguageChange(
const std::string& accept_language) {
GetIOContext()->OnAcceptLanguageChange(accept_language);
@@ -712,50 +628,36 @@
GetIOContext()->OnDefaultCharsetChange(default_charset);
}
-void ChromeURLRequestContextGetter::OnNewExtensions(const std::string& id,
- const FilePath& path) {
- GetIOContext()->OnNewExtensions(id, path);
+void ChromeURLRequestContextGetter::GetCookieStoreAsyncHelper(
+ base::WaitableEvent* completion,
+ net::CookieStore** result) {
+ // Note that CookieStore is refcounted, yet we do not add a reference.
+ *result = GetURLRequestContext()->cookie_store();
+ completion->Signal();
}
-void ChromeURLRequestContextGetter::OnUnloadedExtension(
- const std::string& id) {
- GetIOContext()->OnUnloadedExtension(id);
-}
+// ----------------------------------------------------------------------------
+// ChromeURLRequestContext
+// ----------------------------------------------------------------------------
-void ChromeURLRequestContextGetter::CleanupOnUIThread() {
- CheckCurrentlyOnMainThread();
-
- if (prefs_) {
- // Unregister for pref notifications.
- prefs_->RemovePrefObserver(prefs::kAcceptLanguages, this);
- prefs_->RemovePrefObserver(prefs::kCookieBehavior, this);
- prefs_->RemovePrefObserver(prefs::kDefaultCharset, this);
- prefs_ = NULL;
- }
-
- // TODO(eroman): Doesn't look like this member is even used...
- // can probably be deleted.
- registrar_.RemoveAll();
+ChromeURLRequestContext::ChromeURLRequestContext() {
+ CheckCurrentlyOnIOThread();
}
-ChromeURLRequestContextGetter::~ChromeURLRequestContextGetter() {
+ChromeURLRequestContext::~ChromeURLRequestContext() {
CheckCurrentlyOnIOThread();
+ if (appcache_service_.get() && appcache_service_->request_context() == this)
+ appcache_service_->set_request_context(NULL);
- DCHECK(!prefs_) << "Probably didn't call CleanupOnUIThread";
+ NotificationService::current()->Notify(
+ NotificationType::URL_REQUEST_CONTEXT_RELEASED,
+ Source<URLRequestContext>(this),
+ NotificationService::NoDetails());
- // Either we already transformed the factory into a URLRequestContext, or
- // we still have a pending factory.
- DCHECK((factory_.get() && !url_request_context_.get()) ||
- (!factory_.get() && url_request_context_.get()));
-
- // The scoped_refptr / scoped_ptr destructors take care of releasing
- // |factory_| and |url_request_context_| now.
+ delete ftp_transaction_factory_;
+ delete http_transaction_factory_;
}
-ChromeURLRequestContext::ChromeURLRequestContext() {
- CheckCurrentlyOnIOThread();
-}
-
FilePath ChromeURLRequestContext::GetPathForExtension(const std::string& id) {
ExtensionPaths::iterator iter = extension_paths_.find(id);
if (iter != extension_paths_.end()) {
@@ -810,6 +712,47 @@
return true;
}
+void ChromeURLRequestContext::OnNewExtensions(const std::string& id,
+ const FilePath& path) {
+ if (!is_off_the_record_)
+ extension_paths_[id] = path;
+}
+
+void ChromeURLRequestContext::OnUnloadedExtension(const std::string& id) {
+ CheckCurrentlyOnIOThread();
+ if (is_off_the_record_)
+ return;
+ ExtensionPaths::iterator iter = extension_paths_.find(id);
+ DCHECK(iter != extension_paths_.end());
+ extension_paths_.erase(iter);
+}
+
+ChromeURLRequestContext::ChromeURLRequestContext(
+ ChromeURLRequestContext* other) {
+ CheckCurrentlyOnIOThread();
+
+ // Set URLRequestContext members
+ host_resolver_ = other->host_resolver_;
+ proxy_service_ = other->proxy_service_;
+ ssl_config_service_ = other->ssl_config_service_;
+ http_transaction_factory_ = other->http_transaction_factory_;
+ ftp_transaction_factory_ = other->ftp_transaction_factory_;
+ cookie_store_ = other->cookie_store_;
+ cookie_policy_.set_type(other->cookie_policy_.type());
+ strict_transport_security_state_ = other->strict_transport_security_state_;
+ accept_language_ = other->accept_language_;
+ accept_charset_ = other->accept_charset_;
+ referrer_charset_ = other->referrer_charset_;
+
+ // Set ChromeURLRequestContext members
+ appcache_service_ = other->appcache_service_;
+ extension_paths_ = other->extension_paths_;
+ user_script_dir_path_ = other->user_script_dir_path_;
+ blacklist_ = other->blacklist_;
+ is_media_ = other->is_media_;
+ is_off_the_record_ = other->is_off_the_record_;
+}
+
void ChromeURLRequestContext::OnAcceptLanguageChange(
const std::string& accept_language) {
CheckCurrentlyOnIOThread();
@@ -831,63 +774,147 @@
net::HttpUtil::GenerateAcceptCharsetHeader(default_charset);
}
-void ChromeURLRequestContext::OnNewExtensions(const std::string& id,
- const FilePath& path) {
- if (!is_off_the_record_)
- extension_paths_[id] = path;
+// ----------------------------------------------------------------------------
+// ChromeURLRequestContextFactory
+// ----------------------------------------------------------------------------
+
+// Extract values from |profile| and copy them into
+// ChromeURLRequestContextFactory. We will use them later when constructing the
+// ChromeURLRequestContext on the IO thread (see
+// ApplyProfileParametersToContext() which reverses this).
+ChromeURLRequestContextFactory::ChromeURLRequestContextFactory(Profile* profile)
+ : is_media_(false),
+ is_off_the_record_(profile->IsOffTheRecord()) {
+ CheckCurrentlyOnMainThread();
+ PrefService* prefs = profile->GetPrefs();
+
+ // Set up Accept-Language and Accept-Charset header values
+ accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader(
+ WideToASCII(prefs->GetString(prefs::kAcceptLanguages)));
+ std::string default_charset =
+ WideToASCII(prefs->GetString(prefs::kDefaultCharset));
+ accept_charset_ =
+ net::HttpUtil::GenerateAcceptCharsetHeader(default_charset);
+
+ // At this point, we don't know the charset of the referring page
+ // where a url request originates from. This is used to get a suggested
+ // filename from Content-Disposition header made of raw 8bit characters.
+ // Down the road, it can be overriden if it becomes known (for instance,
+ // when download request is made through the context menu in a web page).
+ // At the moment, it'll remain 'undeterministic' when a user
+ // types a URL in the omnibar or click on a download link in a page.
+ // For the latter, we need a change on the webkit-side.
+ // We initialize it to the default charset here and a user will
+ // have an *arguably* better default charset for interpreting a raw 8bit
+ // C-D header field. It means the native OS codepage fallback in
+ // net_util::GetSuggestedFilename is unlikely to be taken.
+ referrer_charset_ = default_charset;
+
+ cookie_policy_type_ = net::CookiePolicy::FromInt(
+ prefs->GetInteger(prefs::kCookieBehavior));
+
+ // TODO(eroman): this doesn't look safe; sharing between IO and UI threads!
+ blacklist_ = profile->GetBlacklist();
+
+ // TODO(eroman): this doesn't look safe; sharing between IO and UI threads!
+ strict_transport_security_state_ = profile->GetStrictTransportSecurityState();
+
+ if (profile->GetExtensionsService()) {
+ const ExtensionList* extensions =
+ profile->GetExtensionsService()->extensions();
+ for (ExtensionList::const_iterator iter = extensions->begin();
+ iter != extensions->end(); ++iter) {
+ extension_paths_[(*iter)->id()] = (*iter)->path();
+ }
+ }
+
+ if (profile->GetUserScriptMaster())
+ user_script_dir_path_ = profile->GetUserScriptMaster()->user_script_dir();
+
+ // TODO(eroman): this doesn't look safe; sharing between IO and UI threads!
+ ssl_config_service_ = profile->GetSSLConfigService();
+
+ profile_dir_path_ = profile->GetPath();
}
-void ChromeURLRequestContext::OnUnloadedExtension(const std::string& id) {
+ChromeURLRequestContextFactory::~ChromeURLRequestContextFactory() {
CheckCurrentlyOnIOThread();
- if (is_off_the_record_)
- return;
- ExtensionPaths::iterator iter = extension_paths_.find(id);
- DCHECK(iter != extension_paths_.end());
- extension_paths_.erase(iter);
}
-ChromeURLRequestContext::~ChromeURLRequestContext() {
- CheckCurrentlyOnIOThread();
- if (appcache_service_.get() && appcache_service_->request_context() == this)
- appcache_service_->set_request_context(NULL);
+void ChromeURLRequestContextFactory::ApplyProfileParametersToContext(
+ ChromeURLRequestContext* context) {
+ // Apply all the parameters. NOTE: keep this in sync with
+ // ChromeURLRequestContextFactory(Profile*).
+ context->set_is_media(is_media_);
+ context->set_is_off_the_record(is_off_the_record_);
+ context->set_accept_language(accept_language_);
+ context->set_accept_charset(accept_charset_);
+ context->set_referrer_charset(referrer_charset_);
+ context->set_cookie_policy_type(cookie_policy_type_);
+ context->set_extension_paths(extension_paths_);
+ context->set_user_script_dir_path(user_script_dir_path_);
+ context->set_blacklist(blacklist_);
+ context->set_strict_transport_security_state(
+ strict_transport_security_state_);
+ context->set_ssl_config_service(ssl_config_service_);
+}
- NotificationService::current()->Notify(
- NotificationType::URL_REQUEST_CONTEXT_RELEASED,
- Source<URLRequestContext>(this),
- NotificationService::NoDetails());
+// ----------------------------------------------------------------------------
- delete ftp_transaction_factory_;
- delete http_transaction_factory_;
-}
+net::ProxyConfig* CreateProxyConfig(const CommandLine& command_line) {
+ // Scan for all "enable" type proxy switches.
+ static const char* proxy_switches[] = {
+ switches::kProxyServer,
+ switches::kProxyPacUrl,
+ switches::kProxyAutoDetect,
+ switches::kProxyBypassList
+ };
-net::CookieStore* ChromeURLRequestContextGetter::GetCookieStore() {
- // If we are running on the IO thread this is real easy.
- if (ChromeThread::CurrentlyOn(ChromeThread::IO))
- return GetURLRequestContext()->cookie_store();
+ bool found_enable_proxy_switch = false;
+ for (size_t i = 0; i < arraysize(proxy_switches); i++) {
+ if (command_line.HasSwitch(proxy_switches[i])) {
+ found_enable_proxy_switch = true;
+ break;
+ }
+ }
- // If we aren't running on the IO thread, we cannot call
- // GetURLRequestContext(). Instead we will post a task to the IO loop
- // and wait for it to complete.
+ if (!found_enable_proxy_switch &&
+ !command_line.HasSwitch(switches::kNoProxyServer)) {
+ return NULL;
+ }
- base::WaitableEvent completion(false, false);
- net::CookieStore* result = NULL;
+ net::ProxyConfig* proxy_config = new net::ProxyConfig();
+ if (command_line.HasSwitch(switches::kNoProxyServer)) {
+ // Ignore (and warn about) all the other proxy config switches we get if
+ // the --no-proxy-server command line argument is present.
+ if (found_enable_proxy_switch) {
+ LOG(WARNING) << "Additional command line proxy switches found when --"
+ << switches::kNoProxyServer << " was specified.";
+ }
+ return proxy_config;
+ }
- ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- NewRunnableMethod(this,
- &ChromeURLRequestContextGetter::GetCookieStoreAsyncHelper,
- &completion,
- &result));
+ if (command_line.HasSwitch(switches::kProxyServer)) {
+ const std::wstring& proxy_server =
+ command_line.GetSwitchValue(switches::kProxyServer);
+ proxy_config->proxy_rules.ParseFromString(WideToASCII(proxy_server));
+ }
- completion.Wait();
- DCHECK(result);
- return result;
-}
+ if (command_line.HasSwitch(switches::kProxyPacUrl)) {
+ proxy_config->pac_url =
+ GURL(WideToASCII(command_line.GetSwitchValue(
+ switches::kProxyPacUrl)));
+ }
-void ChromeURLRequestContextGetter::GetCookieStoreAsyncHelper(
- base::WaitableEvent* completion,
- net::CookieStore** result) {
- // Note that CookieStore is refcounted, yet we do not add a reference.
- *result = GetURLRequestContext()->cookie_store();
- completion->Signal();
+ if (command_line.HasSwitch(switches::kProxyAutoDetect)) {
+ proxy_config->auto_detect = true;
+ }
+
+ if (command_line.HasSwitch(switches::kProxyBypassList)) {
+ proxy_config->ParseNoProxyList(
+ WideToASCII(command_line.GetSwitchValue(
+ switches::kProxyBypassList)));
+ }
+
+ return proxy_config;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698