diff options
author | scottbyer@chromium.org <scottbyer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-02 21:23:13 +0000 |
---|---|---|
committer | scottbyer@chromium.org <scottbyer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-02 21:23:13 +0000 |
commit | 5dfa52b9e1e269faa84348fc84932b73e9cea7f7 (patch) | |
tree | 0477a757db6a1fce77d26ea63fccf65add4d3ca6 /chrome/service | |
parent | 66175145594a89b2ac64030e7790a84dc83df167 (diff) | |
download | chromium_src-5dfa52b9e1e269faa84348fc84932b73e9cea7f7.zip chromium_src-5dfa52b9e1e269faa84348fc84932b73e9cea7f7.tar.gz chromium_src-5dfa52b9e1e269faa84348fc84932b73e9cea7f7.tar.bz2 |
Service process fixes for Linux.
Linux requires that the proxy_config_service be created on the I/O
thread. Fortunately, ServiceURLRequestContextGetter was already thread safe ref
counted, so we lift creation of that and the (also, fortunately) thread safe
ref counted net::ProxyService up to service process initialization time. That
created proxy service now gets passed in to the dynamic creation of the
ServiceURLRequestContexts. Should have no effect on other platforms.
BUG=74226
TEST=Start Chromium on Linux with --enable-cloud-print-proxy, sign in, and examine ~/.config/chromium/Service State. With the fix, Service State properly contains the needed tokens to properly re-launch and be a proxy.
Review URL: http://codereview.chromium.org/6602041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76612 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/service')
-rw-r--r-- | chrome/service/cloud_print/cloud_print_url_fetcher.cc | 4 | ||||
-rw-r--r-- | chrome/service/gaia/service_gaia_authenticator.cc | 7 | ||||
-rw-r--r-- | chrome/service/net/service_url_request_context.cc | 39 | ||||
-rw-r--r-- | chrome/service/net/service_url_request_context.h | 11 | ||||
-rw-r--r-- | chrome/service/service_process.cc | 9 | ||||
-rw-r--r-- | chrome/service/service_process.h | 5 |
6 files changed, 54 insertions, 21 deletions
diff --git a/chrome/service/cloud_print/cloud_print_url_fetcher.cc b/chrome/service/cloud_print/cloud_print_url_fetcher.cc index 0d81e17..1482b50 100644 --- a/chrome/service/cloud_print/cloud_print_url_fetcher.cc +++ b/chrome/service/cloud_print/cloud_print_url_fetcher.cc @@ -10,6 +10,7 @@ #include "chrome/service/cloud_print/cloud_print_consts.h" #include "chrome/service/cloud_print/cloud_print_helpers.h" #include "chrome/service/net/service_url_request_context.h" +#include "chrome/service/service_process.h" #include "googleurl/src/gurl.h" #include "net/url_request/url_request_status.h" @@ -145,11 +146,10 @@ CloudPrintURLFetcher::~CloudPrintURLFetcher() {} URLRequestContextGetter* CloudPrintURLFetcher::GetRequestContextGetter() { ServiceURLRequestContextGetter* getter = - new ServiceURLRequestContextGetter(); + g_service_process->GetServiceURLRequestContextGetter(); // Now set up the user agent for cloudprint. std::string user_agent = getter->user_agent(); base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); getter->set_user_agent(user_agent); return getter; } - diff --git a/chrome/service/gaia/service_gaia_authenticator.cc b/chrome/service/gaia/service_gaia_authenticator.cc index 1f57626..af795a8 100644 --- a/chrome/service/gaia/service_gaia_authenticator.cc +++ b/chrome/service/gaia/service_gaia_authenticator.cc @@ -6,6 +6,7 @@ #include "base/message_loop_proxy.h" #include "chrome/service/net/service_url_request_context.h" +#include "chrome/service/service_process.h" #include "googleurl/src/gurl.h" ServiceGaiaAuthenticator::ServiceGaiaAuthenticator( @@ -63,9 +64,8 @@ void ServiceGaiaAuthenticator::DoPost(const GURL& post_url, const std::string& post_body) { DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); URLFetcher* request = new URLFetcher(post_url, URLFetcher::POST, this); - ServiceURLRequestContextGetter* context_getter = - new ServiceURLRequestContextGetter(); - request->set_request_context(context_getter); + request->set_request_context( + g_service_process->GetServiceURLRequestContextGetter()); request->set_upload_data("application/x-www-form-urlencoded", post_body); request->Start(); } @@ -89,4 +89,3 @@ void ServiceGaiaAuthenticator::OnURLFetchComplete( http_post_completed_.Signal(); // WARNING: DONT DO ANYTHING AFTER THIS CALL! |this| may be deleted! } - diff --git a/chrome/service/net/service_url_request_context.cc b/chrome/service/net/service_url_request_context.cc index b09794e..4f12f54 100644 --- a/chrome/service/net/service_url_request_context.cc +++ b/chrome/service/net/service_url_request_context.cc @@ -104,20 +104,12 @@ std::string MakeUserAgentForServiceProcess() { } // namespace ServiceURLRequestContext::ServiceURLRequestContext( - const std::string& user_agent) : user_agent_(user_agent) { + const std::string& user_agent, + net::ProxyService* net_proxy_service) : user_agent_(user_agent) { set_host_resolver( net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, NULL, NULL)); - DCHECK(g_service_process); - // TODO(sanjeevr): Change CreateSystemProxyConfigService to accept a - // MessageLoopProxy* instead of MessageLoop*. - // Also this needs to be created on the UI thread on Linux. Fix this. - net::ProxyConfigService * proxy_config_service = - net::ProxyService::CreateSystemProxyConfigService( - g_service_process->io_thread()->message_loop(), - g_service_process->file_thread()->message_loop()); - set_proxy_service(net::ProxyService::CreateUsingSystemProxyResolver( - proxy_config_service, 0u, NULL)); + set_proxy_service(net_proxy_service); set_cert_verifier(new net::CertVerifier); set_dnsrr_resolver(new net::DnsRRResolver); set_ftp_transaction_factory(new net::FtpNetworkLayer(host_resolver())); @@ -164,12 +156,23 @@ ServiceURLRequestContextGetter::ServiceURLRequestContextGetter() g_service_process->io_thread()->message_loop_proxy()) { // Build the default user agent. user_agent_ = MakeUserAgentForServiceProcess(); + +#if !defined(OS_MACOSX) + // Create the proxy service now, at initialization time, on the main thread. + // The Mac needs it created later, on the I/O thread. + CreateProxyService(); +#endif } net::URLRequestContext* ServiceURLRequestContextGetter::GetURLRequestContext() { +#if defined(OS_MACOSX) + if (!proxy_service_) + CreateProxyService(); +#endif if (!url_request_context_) - url_request_context_ = new ServiceURLRequestContext(user_agent_); + url_request_context_ = new ServiceURLRequestContext(user_agent_, + proxy_service_); return url_request_context_; } @@ -179,3 +182,15 @@ ServiceURLRequestContextGetter::GetIOMessageLoopProxy() const { } ServiceURLRequestContextGetter::~ServiceURLRequestContextGetter() {} + +void ServiceURLRequestContextGetter::CreateProxyService() { + // TODO(sanjeevr): Change CreateSystemProxyConfigService to accept a + // MessageLoopProxy* instead of MessageLoop*. + DCHECK(g_service_process); + net::ProxyConfigService * proxy_config_service = + net::ProxyService::CreateSystemProxyConfigService( + g_service_process->io_thread()->message_loop(), + g_service_process->file_thread()->message_loop()); + proxy_service_ = net::ProxyService::CreateUsingSystemProxyResolver( + proxy_config_service, 0u, NULL); +} diff --git a/chrome/service/net/service_url_request_context.h b/chrome/service/net/service_url_request_context.h index 7ffda3c..becc21a 100644 --- a/chrome/service/net/service_url_request_context.h +++ b/chrome/service/net/service_url_request_context.h @@ -31,7 +31,8 @@ class MessageLoopProxy; // class ServiceURLRequestContext : public net::URLRequestContext { public: - explicit ServiceURLRequestContext(const std::string& user_agent); + explicit ServiceURLRequestContext(const std::string& user_agent, + net::ProxyService* net_proxy_service); // Overridden from net::URLRequestContext: virtual const std::string& GetUserAgent(const GURL& url) const; @@ -45,8 +46,6 @@ class ServiceURLRequestContext : public net::URLRequestContext { class ServiceURLRequestContextGetter : public URLRequestContextGetter { public: - ServiceURLRequestContextGetter(); - virtual net::URLRequestContext* GetURLRequestContext(); virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const; @@ -56,12 +55,18 @@ class ServiceURLRequestContextGetter : public URLRequestContextGetter { std::string user_agent() const { return user_agent_; } + private: + friend class ServiceProcess; + ServiceURLRequestContextGetter(); virtual ~ServiceURLRequestContextGetter(); + void CreateProxyService(); + std::string user_agent_; scoped_refptr<net::URLRequestContext> url_request_context_; scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; + scoped_refptr<net::ProxyService> proxy_service_; }; #endif // CHROME_SERVICE_NET_SERVICE_URL_REQUEST_CONTEXT_H_ diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc index 6a8b689..1335936 100644 --- a/chrome/service/service_process.cc +++ b/chrome/service/service_process.cc @@ -23,6 +23,7 @@ #include "chrome/common/pref_names.h" #include "chrome/common/service_process_util.h" #include "chrome/service/cloud_print/cloud_print_proxy.h" +#include "chrome/service/net/service_url_request_context.h" #include "chrome/service/service_ipc_server.h" #include "chrome/service/service_process_prefs.h" #include "grit/chromium_strings.h" @@ -141,6 +142,8 @@ bool ServiceProcess::Initialize(MessageLoopForUI* message_loop, return false; } + request_context_getter_ = new ServiceURLRequestContextGetter(); + // See if we have been suppiled an LSID in the command line. This LSID will // override the credentials we use for Cloud Print. std::string lsid = command_line.GetSwitchValueASCII( @@ -306,6 +309,12 @@ void ServiceProcess::OnChromotingHostDisabled() { OnServiceDisabled(); } +ServiceURLRequestContextGetter* +ServiceProcess::GetServiceURLRequestContextGetter() { + DCHECK(request_context_getter_.get()); + return request_context_getter_.get(); +} + void ServiceProcess::OnServiceEnabled() { enabled_services_++; if ((1 == enabled_services_) && diff --git a/chrome/service/service_process.h b/chrome/service/service_process.h index 7c2606c..a3b8cdc 100644 --- a/chrome/service/service_process.h +++ b/chrome/service/service_process.h @@ -19,6 +19,7 @@ class ServiceProcessPrefs; class ServiceIPCServer; class CommandLine; +class ServiceURLRequestContextGetter; namespace net { class NetworkChangeNotifier; @@ -98,6 +99,8 @@ class ServiceProcess : public CloudPrintProxy::Client, } #endif + ServiceURLRequestContextGetter* GetServiceURLRequestContextGetter(); + private: // Schedule a call to ShutdownIfNeeded. void ScheduleShutdownCheck(); @@ -130,6 +133,8 @@ class ServiceProcess : public CloudPrintProxy::Client, // Speficies whether a product update is available. bool update_available_; + scoped_refptr<ServiceURLRequestContextGetter> request_context_getter_; + #if defined(ENABLE_REMOTING) scoped_refptr<remoting::ChromotingHostManager> remoting_host_manager_; #endif |