summaryrefslogtreecommitdiffstats
path: root/remoting/base
diff options
context:
space:
mode:
authorsolb@chromium.org <solb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-04 22:58:18 +0000
committersolb@chromium.org <solb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-04 22:58:18 +0000
commit87b327a7dc81ba041d208e768373064b4c6b9957 (patch)
tree9db662d823ca7624f1aeac3a5f2b531a2dc2be7a /remoting/base
parent49eb97bfaabbd5ac764e624fa9f8678e0c83504f (diff)
downloadchromium_src-87b327a7dc81ba041d208e768373064b4c6b9957.zip
chromium_src-87b327a7dc81ba041d208e768373064b4c6b9957.tar.gz
chromium_src-87b327a7dc81ba041d208e768373064b4c6b9957.tar.bz2
Move url_request_context from remoting/host/ to remoting/base/
This will make it easy for future non--Web app client implementations to make use of this class. The vlog_net_log class also had to be relocated. Review URL: https://chromiumcodereview.appspot.com/18460003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210235 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/base')
-rw-r--r--remoting/base/url_request_context.cc139
-rw-r--r--remoting/base/url_request_context.h64
-rw-r--r--remoting/base/vlog_net_log.cc52
-rw-r--r--remoting/base/vlog_net_log.h32
4 files changed, 287 insertions, 0 deletions
diff --git a/remoting/base/url_request_context.cc b/remoting/base/url_request_context.cc
new file mode 100644
index 0000000..98c7f37
--- /dev/null
+++ b/remoting/base/url_request_context.cc
@@ -0,0 +1,139 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/base/url_request_context.h"
+
+#include "base/message_loop/message_loop_proxy.h"
+#include "net/cert/cert_verifier.h"
+#include "net/dns/host_resolver.h"
+#include "net/http/http_auth_handler_factory.h"
+#include "net/http/http_network_layer.h"
+#include "net/http/http_network_session.h"
+#include "net/http/http_server_properties_impl.h"
+#include "net/http/transport_security_state.h"
+#include "net/proxy/proxy_config_service.h"
+#include "net/proxy/proxy_service.h"
+#include "net/ssl/ssl_config_service_defaults.h"
+#include "remoting/base/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 {
+
+// 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::SingleThreadTaskRunner* ui_task_runner,
+ base::SingleThreadTaskRunner* io_thread_task_runner) {
+ DCHECK(ui_task_runner->BelongsToCurrentThread());
+
+#if defined(OS_WIN)
+ return new net::ProxyConfigServiceWin();
+#elif defined(OS_MACOSX)
+ return new net::ProxyConfigServiceMac(io_thread_task_runner);
+#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,
+// which is in turn copied from some test code. Move it somewhere reusable.
+URLRequestContext::URLRequestContext(
+ scoped_ptr<net::ProxyConfigService> proxy_config_service)
+ : storage_(this) {
+ scoped_ptr<VlogNetLog> net_log(new VlogNetLog());
+ storage_.set_host_resolver(
+ net::HostResolver::CreateDefaultResolver(net_log.get()));
+ storage_.set_proxy_service(net::ProxyService::CreateUsingSystemProxyResolver(
+ proxy_config_service.release(), 0u, net_log.get()));
+ storage_.set_cert_verifier(net::CertVerifier::CreateDefault());
+ storage_.set_ssl_config_service(new net::SSLConfigServiceDefaults);
+ storage_.set_http_auth_handler_factory(
+ net::HttpAuthHandlerFactory::CreateDefault(host_resolver()));
+ storage_.set_http_server_properties(new net::HttpServerPropertiesImpl);
+ storage_.set_transport_security_state(new net::TransportSecurityState);
+
+ net::HttpNetworkSession::Params session_params;
+ session_params.host_resolver = host_resolver();
+ session_params.cert_verifier = cert_verifier();
+ session_params.transport_security_state = transport_security_state();
+ session_params.proxy_service = proxy_service();
+ session_params.ssl_config_service = ssl_config_service();
+ session_params.http_auth_handler_factory = http_auth_handler_factory();
+ session_params.http_server_properties = http_server_properties();
+ session_params.net_log = net_log.get();
+ scoped_refptr<net::HttpNetworkSession> network_session(
+ new net::HttpNetworkSession(session_params));
+ storage_.set_http_transaction_factory(
+ new net::HttpNetworkLayer(network_session.get()));
+ storage_.set_net_log(net_log.release());
+}
+
+URLRequestContext::~URLRequestContext() {
+}
+
+URLRequestContextGetter::URLRequestContextGetter(
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner)
+ : network_task_runner_(network_task_runner) {
+ proxy_config_service_.reset(CreateSystemProxyConfigService(
+ ui_task_runner.get(), network_task_runner_.get()));
+}
+
+net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
+ if (!url_request_context_.get()) {
+ url_request_context_.reset(
+ new URLRequestContext(proxy_config_service_.Pass()));
+ }
+ return url_request_context_.get();
+}
+
+scoped_refptr<base::SingleThreadTaskRunner>
+URLRequestContextGetter::GetNetworkTaskRunner() const {
+ return network_task_runner_;
+}
+
+URLRequestContextGetter::~URLRequestContextGetter() {
+}
+
+} // namespace remoting
diff --git a/remoting/base/url_request_context.h b/remoting/base/url_request_context.h
new file mode 100644
index 0000000..7399241
--- /dev/null
+++ b/remoting/base/url_request_context.h
@@ -0,0 +1,64 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_BASE_URL_REQUEST_CONTEXT_H_
+#define REMOTING_BASE_URL_REQUEST_CONTEXT_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
+#include "net/proxy/proxy_config_service.h"
+#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_context_getter.h"
+#include "net/url_request/url_request_context_storage.h"
+
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
+namespace remoting {
+
+// Subclass of net::URLRequestContext which can be used to store extra
+// information for requests. This subclass is meant to be used in the
+// remoting Me2Me host process where the profile is not available.
+class URLRequestContext : public net::URLRequestContext {
+ public:
+ explicit URLRequestContext(
+ scoped_ptr<net::ProxyConfigService> proxy_config_service);
+
+ private:
+ virtual ~URLRequestContext();
+
+ net::URLRequestContextStorage storage_;
+
+ DISALLOW_COPY_AND_ASSIGN(URLRequestContext);
+};
+
+class URLRequestContextGetter : public net::URLRequestContextGetter {
+ public:
+ URLRequestContextGetter(
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner);
+
+ // Overridden from net::URLRequestContextGetter:
+ virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
+ virtual scoped_refptr<base::SingleThreadTaskRunner>
+ GetNetworkTaskRunner() const OVERRIDE;
+
+ protected:
+ virtual ~URLRequestContextGetter();
+
+ private:
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
+ scoped_ptr<net::ProxyConfigService> proxy_config_service_;
+ scoped_ptr<net::URLRequestContext> url_request_context_;
+
+ DISALLOW_COPY_AND_ASSIGN(URLRequestContextGetter);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_BASE_URL_REQUEST_CONTEXT_H_
diff --git a/remoting/base/vlog_net_log.cc b/remoting/base/vlog_net_log.cc
new file mode 100644
index 0000000..ff2e3e3
--- /dev/null
+++ b/remoting/base/vlog_net_log.cc
@@ -0,0 +1,52 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/base/vlog_net_log.h"
+
+#include "base/json/json_writer.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/threading/thread_restrictions.h"
+#include "base/time/time.h"
+#include "base/values.h"
+
+namespace remoting {
+
+class VlogNetLog::Observer : public net::NetLog::ThreadSafeObserver {
+ public:
+ Observer();
+ virtual ~Observer();
+
+ // NetLog::ThreadSafeObserver overrides:
+ virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Observer);
+};
+
+VlogNetLog::Observer::Observer() {
+}
+
+VlogNetLog::Observer::~Observer() {
+}
+
+void VlogNetLog::Observer::OnAddEntry(const net::NetLog::Entry& entry) {
+ if (VLOG_IS_ON(4)) {
+ scoped_ptr<Value> value(entry.ToValue());
+ std::string json;
+ base::JSONWriter::Write(value.get(), &json);
+ VLOG(4) << json;
+ }
+}
+
+VlogNetLog::VlogNetLog()
+ : observer_(new Observer()) {
+ AddThreadSafeObserver(observer_.get(), LOG_ALL_BUT_BYTES);
+}
+
+VlogNetLog::~VlogNetLog() {
+ RemoveThreadSafeObserver(observer_.get());
+}
+
+} // namespace remoting
diff --git a/remoting/base/vlog_net_log.h b/remoting/base/vlog_net_log.h
new file mode 100644
index 0000000..9bbd384
--- /dev/null
+++ b/remoting/base/vlog_net_log.h
@@ -0,0 +1,32 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_BASE_VLOG_NET_LOG_H_
+#define REMOTING_BASE_VLOG_NET_LOG_H_
+
+#include "base/memory/scoped_handle.h"
+#include "base/memory/scoped_ptr.h"
+#include "net/base/net_log.h"
+
+namespace remoting {
+
+// Redirectes all networking events (i.e. events logged through net::NetLog) to
+// VLOG(4). Note that an explicit reference to a net::NetLog object has to be
+// passed to networking classes to receive the events. There is no global
+// network events logger exists.
+class VlogNetLog : public net::NetLog {
+ public:
+ VlogNetLog();
+ virtual ~VlogNetLog();
+
+ private:
+ class Observer;
+ scoped_ptr<Observer> observer_;
+
+ DISALLOW_COPY_AND_ASSIGN(VlogNetLog);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_BASE_VLOG_NET_LOG_H_