OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef NET_CRONET_ANDROID_URL_REQUEST_CONTEXT_PEER_H_ | |
6 #define NET_CRONET_ANDROID_URL_REQUEST_CONTEXT_PEER_H_ | |
7 | |
8 #include "base/compiler_specific.h" | |
9 #include "base/macros.h" | |
10 #include "base/memory/ref_counted.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/threading/thread.h" | |
13 #include "net/base/net_log.h" | |
14 #include "net/base/network_change_notifier.h" | |
15 #include "net/url_request/url_request_context.h" | |
16 #include "net/url_request/url_request_context_getter.h" | |
17 | |
18 // Implementation of the Chromium NetLog observer interface. | |
19 class NetLogObserver : public net::NetLog::ThreadSafeObserver { | |
20 public: | |
21 explicit NetLogObserver(int log_level) { log_level_ = log_level; } | |
22 | |
23 virtual ~NetLogObserver() {} | |
24 | |
25 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE; | |
26 | |
27 private: | |
28 int log_level_; | |
mmenke
2014/03/04 19:36:21
DISALLOW_COPY_AND_ASSIGN?
mef
2014/03/05 20:54:13
Done.
| |
29 }; | |
30 | |
31 // Fully configured |URLRequestContext|. | |
32 class URLRequestContextPeer : public net::URLRequestContextGetter { | |
33 public: | |
34 class URLRequestContextPeerDelegate | |
35 : public base::RefCountedThreadSafe<URLRequestContextPeerDelegate> { | |
36 public: | |
37 virtual void OnContextInitialized(URLRequestContextPeer* context) = 0; | |
38 | |
39 protected: | |
40 friend class base::RefCountedThreadSafe<URLRequestContextPeerDelegate>; | |
41 | |
42 virtual ~URLRequestContextPeerDelegate() {} | |
43 }; | |
44 | |
45 URLRequestContextPeer(URLRequestContextPeerDelegate* delegate, | |
46 std::string user_agent, | |
47 int log_level, | |
48 const char* version); | |
49 void Initialize(); | |
50 | |
51 const std::string& GetUserAgent(const GURL& url) const; | |
52 | |
53 int logging_level() const { return logging_level_; } | |
54 | |
55 const char* version() const { return version_; } | |
56 | |
57 // net::URLRequestContextGetter implementation: | |
58 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; | |
59 virtual scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() | |
60 const OVERRIDE; | |
61 | |
62 private: | |
63 scoped_refptr<URLRequestContextPeerDelegate> delegate_; | |
64 scoped_ptr<net::URLRequestContext> context_; | |
65 int logging_level_; | |
66 const char* version_; | |
67 std::string user_agent_; | |
68 base::Thread* network_thread_; | |
69 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | |
70 scoped_ptr<NetLogObserver> netlog_observer_; | |
71 | |
72 virtual ~URLRequestContextPeer(); | |
73 | |
74 // Initializes |context_| on the IO thread. | |
75 void InitializeURLRequestContext(); | |
76 | |
77 DISALLOW_COPY_AND_ASSIGN(URLRequestContextPeer); | |
78 }; | |
79 | |
80 #endif // NET_CRONET_ANDROID_URL_REQUEST_CONTEXT_PEER_H_ | |
OLD | NEW |