diff options
author | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-12 19:25:07 +0000 |
---|---|---|
committer | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-12 19:25:07 +0000 |
commit | 1d0ee423b6a0bb307c7c19fe28c95d8761691e9a (patch) | |
tree | 5766edd6b8b8a7b2eb3942e75008388a0ecfeff0 /chrome/service/net | |
parent | b90b874fe7023537531fbd08df403694e3e3a520 (diff) | |
download | chromium_src-1d0ee423b6a0bb307c7c19fe28c95d8761691e9a.zip chromium_src-1d0ee423b6a0bb307c7c19fe28c95d8761691e9a.tar.gz chromium_src-1d0ee423b6a0bb307c7c19fe28c95d8761691e9a.tar.bz2 |
Created a new process type called the service process to host background tasks such as the Cloud Print Proxy.
BUG=None.
TEST=None.
Review URL: http://codereview.chromium.org/2001009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47055 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/service/net')
-rw-r--r-- | chrome/service/net/service_url_request_context.cc | 55 | ||||
-rw-r--r-- | chrome/service/net/service_url_request_context.h | 78 |
2 files changed, 133 insertions, 0 deletions
diff --git a/chrome/service/net/service_url_request_context.cc b/chrome/service/net/service_url_request_context.cc new file mode 100644 index 0000000..ab5e61a --- /dev/null +++ b/chrome/service/net/service_url_request_context.cc @@ -0,0 +1,55 @@ +// Copyright (c) 2010 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 "chrome/service/net/service_url_request_context.h" + +#include "chrome/service/service_process.h" +#include "net/base/cookie_monster.h" +#include "net/base/cookie_policy.h" +#include "net/base/host_resolver.h" +#include "net/base/ssl_config_service_defaults.h" +#include "net/ftp/ftp_network_layer.h" +#include "net/http/http_auth_handler_factory.h" +#include "net/http/http_cache.h" +#include "net/http/http_network_layer.h" +#include "net/proxy/proxy_service.h" + +ServiceURLRequestContextGetter::ServiceURLRequestContextGetter() + : io_message_loop_proxy_( + g_service_process->io_thread()->message_loop_proxy()) { +} + +ServiceURLRequestContext::ServiceURLRequestContext() { + host_resolver_ = net::CreateSystemHostResolver(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()); + proxy_service_ = net::ProxyService::Create(proxy_config_service, false, this, + NULL, NULL, NULL); + ftp_transaction_factory_ = new net::FtpNetworkLayer(host_resolver_); + ssl_config_service_ = new net::SSLConfigServiceDefaults; + http_auth_handler_factory_ = net::HttpAuthHandlerFactory::CreateDefault(); + http_transaction_factory_ = new net::HttpCache( + net::HttpNetworkLayer::CreateFactory(NULL, host_resolver_, + proxy_service_, + ssl_config_service_, + http_auth_handler_factory_), + disk_cache::CreateInMemoryCacheBackend(0)); + // In-memory cookie store. + cookie_store_ = new net::CookieMonster(NULL, NULL); + accept_language_ = "en-us,fr"; + accept_charset_ = "iso-8859-1,*,utf-8"; +} + +ServiceURLRequestContext::~ServiceURLRequestContext() { + delete ftp_transaction_factory_; + delete http_transaction_factory_; + delete http_auth_handler_factory_; +} + diff --git a/chrome/service/net/service_url_request_context.h b/chrome/service/net/service_url_request_context.h new file mode 100644 index 0000000..90c9733 --- /dev/null +++ b/chrome/service/net/service_url_request_context.h @@ -0,0 +1,78 @@ +// Copyright (c) 2010 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 CHROME_SERVICE_NET_SERVICE_URL_REQUEST_CONTEXT_H_ +#define CHROME_SERVICE_NET_SERVICE_URL_REQUEST_CONTEXT_H_ + +#include <string> + +#include "base/message_loop_proxy.h" +#include "chrome/common/net/url_request_context_getter.h" +#include "net/base/cookie_monster.h" +#include "net/base/cookie_policy.h" +#include "net/base/host_resolver.h" +#include "net/base/ssl_config_service_defaults.h" +#include "net/disk_cache/disk_cache.h" +#include "net/ftp/ftp_network_layer.h" +#include "net/http/http_auth_handler_factory.h" +#include "net/http/http_cache.h" +#include "net/http/http_network_layer.h" +#include "net/proxy/proxy_service.h" +#include "net/url_request/url_request_context.h" + +// Subclass of URLRequestContext which can be used to store extra information +// for requests. This subclass is meant to be used in the service process where +// the profile is not available. +// +class ServiceURLRequestContext : public URLRequestContext { + public: + ServiceURLRequestContext(); + void set_cookie_policy(net::CookiePolicy* policy) { + cookie_policy_ = policy; + } + void set_user_agent(const std::string& ua) { + user_agent_ = ua; + } + + // URLRequestContext overrides + virtual const std::string& GetUserAgent(const GURL& url) const { + // If the user agent is set explicitly return that, otherwise call the + // base class method to return default value. + return user_agent_.empty() ? + URLRequestContext::GetUserAgent(url) : user_agent_; + } + + protected: + virtual ~ServiceURLRequestContext(); + + private: + std::string user_agent_; +}; + +class ServiceURLRequestContextGetter : public URLRequestContextGetter { + public: + ServiceURLRequestContextGetter(); + + virtual URLRequestContext* GetURLRequestContext() { + if (!url_request_context_) + url_request_context_ = new ServiceURLRequestContext(); + return url_request_context_; + } + virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() { + return io_message_loop_proxy_; + } + + void set_user_agent(const std::string& ua) { + user_agent_ = ua; + } + private: + ~ServiceURLRequestContextGetter() {} + + std::string user_agent_; + scoped_refptr<URLRequestContext> url_request_context_; + scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; +}; + +#endif // CHROME_SERVICE_NET_SERVICE_URL_REQUEST_CONTEXT_H_ + |