Home | History | Annotate | Download | only in net
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef ANDROID_WEBVIEW_BROWSER_NET_AW_URL_REQUEST_CONTEXT_GETTER_H_
      6 #define ANDROID_WEBVIEW_BROWSER_NET_AW_URL_REQUEST_CONTEXT_GETTER_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/compiler_specific.h"
     10 #include "base/memory/scoped_ptr.h"
     11 #include "content/public/browser/browser_thread_delegate.h"
     12 #include "content/public/browser/content_browser_client.h"
     13 #include "net/http/http_network_session.h"
     14 #include "net/url_request/url_request_context_getter.h"
     15 #include "net/url_request/url_request_job_factory.h"
     16 
     17 namespace net {
     18 class HttpTransactionFactory;
     19 class ProxyConfigService;
     20 class URLRequestContext;
     21 class URLRequestJobFactory;
     22 }
     23 
     24 namespace android_webview {
     25 
     26 class AwBrowserContext;
     27 class AwNetworkDelegate;
     28 
     29 class AwURLRequestContextGetter : public net::URLRequestContextGetter,
     30                                   public content::BrowserThreadDelegate {
     31  public:
     32   explicit AwURLRequestContextGetter(AwBrowserContext* browser_context);
     33 
     34   void InitializeOnNetworkThread();
     35 
     36   // content::BrowserThreadDelegate implementation.
     37   virtual void Init() OVERRIDE;
     38   virtual void InitAsync() OVERRIDE;
     39   virtual void CleanUp() OVERRIDE {}
     40 
     41   // net::URLRequestContextGetter implementation.
     42   virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
     43   virtual scoped_refptr<base::SingleThreadTaskRunner>
     44       GetNetworkTaskRunner() const OVERRIDE;
     45 
     46  private:
     47   friend class AwBrowserContext;
     48 
     49   virtual ~AwURLRequestContextGetter();
     50 
     51   // Prior to GetURLRequestContext() being called, SetProtocolHandlers() is
     52   // called to hand over the ProtocolHandlers that GetURLRequestContext() will
     53   // later install into |job_factory_|.  This ordering is enforced by having
     54   // AwBrowserContext::CreateRequestContext() call SetProtocolHandlers().
     55   // SetProtocolHandlers() is necessary because the ProtocolHandlers are created
     56   // on the UI thread while |job_factory_| must be created on the IO thread.
     57   void SetProtocolHandlers(content::ProtocolHandlerMap* protocol_handlers);
     58 
     59   void PopulateNetworkSessionParams(net::HttpNetworkSession::Params* params);
     60 
     61   AwBrowserContext* browser_context_;  // weak
     62   scoped_refptr<net::CookieStore> cookie_store_;
     63   scoped_ptr<net::URLRequestContext> url_request_context_;
     64   scoped_ptr<net::ProxyConfigService> proxy_config_service_;
     65   scoped_ptr<net::URLRequestJobFactory> job_factory_;
     66   scoped_ptr<net::HttpTransactionFactory> main_http_factory_;
     67 
     68   // ProtocolHandlers are stored here between SetProtocolHandlers() and the
     69   // first GetURLRequestContext() call.
     70   content::ProtocolHandlerMap protocol_handlers_;
     71 
     72   DISALLOW_COPY_AND_ASSIGN(AwURLRequestContextGetter);
     73 };
     74 
     75 }  // namespace android_webview
     76 
     77 #endif  // ANDROID_WEBVIEW_BROWSER_NET_AW_URL_REQUEST_CONTEXT_GETTER_H_
     78