1 // Copyright 2014 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.
5 #ifndef COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_PEER_H_
6 #define COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_PEER_H_
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/thread.h"
15 #include "net/base/net_log.h"
16 #include "net/base/network_change_notifier.h"
17 #include "net/url_request/url_request_context.h"
18 #include "net/url_request/url_request_context_getter.h"
26 struct URLRequestContextConfig
;
28 // Implementation of the Chromium NetLog observer interface.
29 class NetLogObserver
: public net::NetLog::ThreadSafeObserver
{
31 explicit NetLogObserver() {}
33 virtual ~NetLogObserver() {}
35 virtual void OnAddEntry(const net::NetLog::Entry
& entry
) OVERRIDE
;
38 DISALLOW_COPY_AND_ASSIGN(NetLogObserver
);
41 // Fully configured |URLRequestContext|.
42 class URLRequestContextPeer
: public net::URLRequestContextGetter
{
44 class URLRequestContextPeerDelegate
45 : public base::RefCountedThreadSafe
<URLRequestContextPeerDelegate
> {
47 virtual void OnContextInitialized(URLRequestContextPeer
* context
) = 0;
50 friend class base::RefCountedThreadSafe
<URLRequestContextPeerDelegate
>;
52 virtual ~URLRequestContextPeerDelegate() {}
55 URLRequestContextPeer(URLRequestContextPeerDelegate
* delegate
,
56 std::string user_agent
);
57 void Initialize(scoped_ptr
<URLRequestContextConfig
> config
);
59 const std::string
& GetUserAgent(const GURL
& url
) const;
61 // net::URLRequestContextGetter implementation:
62 virtual net::URLRequestContext
* GetURLRequestContext() OVERRIDE
;
63 virtual scoped_refptr
<base::SingleThreadTaskRunner
> GetNetworkTaskRunner()
66 void StartNetLogToFile(const std::string
& file_name
);
70 scoped_refptr
<URLRequestContextPeerDelegate
> delegate_
;
71 scoped_ptr
<net::URLRequestContext
> context_
;
72 std::string user_agent_
;
73 base::Thread
* network_thread_
;
74 scoped_ptr
<net::NetworkChangeNotifier
> network_change_notifier_
;
75 scoped_ptr
<NetLogObserver
> net_log_observer_
;
76 scoped_ptr
<net::NetLogLogger
> net_log_logger_
;
78 virtual ~URLRequestContextPeer();
80 // Initializes |context_| on the IO thread.
81 void InitializeURLRequestContext(scoped_ptr
<URLRequestContextConfig
> config
);
83 DISALLOW_COPY_AND_ASSIGN(URLRequestContextPeer
);
88 #endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_PEER_H_