Commit 92e1a00d authored by sergeyu@chromium.org's avatar sergeyu@chromium.org

Always create URLRequestContextGetter in ChromotingHostContext.

BUG=124728


Review URL: http://codereview.chromium.org/10173009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133974 0039d316-1c4b-4281-b951-d872f2087c98
parent 8affc242
...@@ -37,13 +37,9 @@ bool ChromotingHostContext::Start() { ...@@ -37,13 +37,9 @@ bool ChromotingHostContext::Start() {
if (!started) if (!started)
return false; return false;
// net::ProxyService::CreateSystemProxyConfigService requires a UI thread. url_request_context_getter_ = new URLRequestContextGetter(
// TODO(jamiewalch): Clean up this dependency. ui_message_loop_, io_thread_.message_loop(),
MessageLoop* loop = MessageLoop::current(); static_cast<MessageLoopForIO*>(file_thread_.message_loop()));
if (loop && loop->type() == MessageLoop::TYPE_UI) {
url_request_context_getter_ = new URLRequestContextGetter(
io_thread_.message_loop(), file_thread_.message_loop());
}
return true; return true;
} }
......
...@@ -31,8 +31,10 @@ class UrlFetcherTest : public testing::Test { ...@@ -31,8 +31,10 @@ class UrlFetcherTest : public testing::Test {
base::Thread::Options(MessageLoop::TYPE_IO, 0))); base::Thread::Options(MessageLoop::TYPE_IO, 0)));
ASSERT_TRUE(file_thread_.StartWithOptions( ASSERT_TRUE(file_thread_.StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0))); base::Thread::Options(MessageLoop::TYPE_IO, 0)));
context_getter_ = new URLRequestContextGetter(io_thread_.message_loop(), context_getter_ = new URLRequestContextGetter(
file_thread_.message_loop()); message_loop_.message_loop_proxy(),
io_thread_.message_loop(),
static_cast<MessageLoopForIO*>(file_thread_.message_loop()));
ASSERT_TRUE(test_server_.Start()); ASSERT_TRUE(test_server_.Start());
} }
......
...@@ -16,8 +16,66 @@ ...@@ -16,8 +16,66 @@
#include "net/proxy/proxy_service.h" #include "net/proxy/proxy_service.h"
#include "remoting/host/vlog_net_log.h" #include "remoting/host/vlog_net_log.h"
#if defined(OS_WIN)
#include "net/proxy/proxy_config_service_win.h"
#elif defined(OS_MACOSX)
#include "net/proxy/proxy_config_service_mac.h"
#elif defined(OS_LINUX) && !defined(OS_CHROMEOS)
#include "net/proxy/proxy_config_service_linux.h"
#endif
namespace remoting { namespace remoting {
namespace {
// Config getter that always returns direct settings.
class ProxyConfigServiceDirect : public net::ProxyConfigService {
public:
// ProxyConfigService implementation:
virtual void AddObserver(Observer* observer) OVERRIDE {}
virtual void RemoveObserver(Observer* observer) OVERRIDE {}
virtual ConfigAvailability GetLatestProxyConfig(
net::ProxyConfig* config) OVERRIDE {
*config = net::ProxyConfig::CreateDirect();
return CONFIG_VALID;
}
};
net::ProxyConfigService* CreateSystemProxyConfigService(
base::MessageLoopProxy* ui_message_loop_,
MessageLoop* io_message_loop,
MessageLoopForIO* file_message_loop) {
DCHECK(ui_message_loop_->BelongsToCurrentThread());
#if defined(OS_WIN)
return new net::ProxyConfigServiceWin();
#elif defined(OS_MACOSX)
return new net::ProxyConfigServiceMac(io_message_loop);
#elif defined(OS_CHROMEOS)
NOTREACHED() << "ChromeOS is not a supported target for Chromoting host";
return NULL;
#elif defined(OS_LINUX)
// TODO(sergeyu): Currently ProxyConfigServiceLinux depends on
// base::OneShotTimer that doesn't work properly on main NPAPI
// thread. Fix that and uncomment the code below.
//
// net::ProxyConfigServiceLinux* linux_config_service =
// new net::ProxyConfigServiceLinux();
// linux_config_service->SetupAndFetchInitialConfig(
// ui_message_loop_, io_message_loop->message_loop_proxy(),
// file_message_loop);
// return linux_config_service;
return new ProxyConfigServiceDirect();
#else
LOG(WARNING) << "Failed to choose a system proxy settings fetcher "
"for this platform.";
return new ProxyConfigServiceDirect();
#endif
}
} // namespace
// TODO(willchan): This is largely copied from service_url_request_context.cc, // TODO(willchan): This is largely copied from service_url_request_context.cc,
// which is in turn copied from some test code. Move it somewhere reusable. // which is in turn copied from some test code. Move it somewhere reusable.
URLRequestContext::URLRequestContext( URLRequestContext::URLRequestContext(
...@@ -55,12 +113,12 @@ URLRequestContext::~URLRequestContext() { ...@@ -55,12 +113,12 @@ URLRequestContext::~URLRequestContext() {
} }
URLRequestContextGetter::URLRequestContextGetter( URLRequestContextGetter::URLRequestContextGetter(
base::MessageLoopProxy* ui_message_loop,
MessageLoop* io_message_loop, MessageLoop* io_message_loop,
MessageLoop* file_message_loop) MessageLoopForIO* file_message_loop)
: io_message_loop_proxy_(io_message_loop->message_loop_proxy()) { : io_message_loop_proxy_(io_message_loop->message_loop_proxy()) {
proxy_config_service_.reset( proxy_config_service_.reset(CreateSystemProxyConfigService(
net::ProxyService::CreateSystemProxyConfigService( ui_message_loop, io_message_loop, file_message_loop));
io_message_loop, file_message_loop));
} }
net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
......
...@@ -39,8 +39,9 @@ class URLRequestContext : public net::URLRequestContext { ...@@ -39,8 +39,9 @@ class URLRequestContext : public net::URLRequestContext {
class URLRequestContextGetter : public net::URLRequestContextGetter { class URLRequestContextGetter : public net::URLRequestContextGetter {
public: public:
URLRequestContextGetter(MessageLoop* io_message_loop, URLRequestContextGetter(base::MessageLoopProxy* ui_message_loop,
MessageLoop* file_message_loop); MessageLoop* io_message_loop,
MessageLoopForIO* file_message_loop);
// Overridden from net::URLRequestContextGetter: // Overridden from net::URLRequestContextGetter:
virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment