| 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 <string> | |
| 9 | |
| 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" | |
| 19 | |
| 20 namespace net { | |
| 21 class NetLogLogger; | |
| 22 } // namespace net | |
| 23 | |
| 24 // Implementation of the Chromium NetLog observer interface. | |
| 25 class NetLogObserver : public net::NetLog::ThreadSafeObserver { | |
| 26 public: | |
| 27 explicit NetLogObserver(int log_level) { log_level_ = log_level; } | |
| 28 | |
| 29 virtual ~NetLogObserver() {} | |
| 30 | |
| 31 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE; | |
| 32 | |
| 33 private: | |
| 34 int log_level_; | |
| 35 | |
| 36 DISALLOW_COPY_AND_ASSIGN(NetLogObserver); | |
| 37 }; | |
| 38 | |
| 39 // Fully configured |URLRequestContext|. | |
| 40 class URLRequestContextPeer : public net::URLRequestContextGetter { | |
| 41 public: | |
| 42 class URLRequestContextPeerDelegate | |
| 43 : public base::RefCountedThreadSafe<URLRequestContextPeerDelegate> { | |
| 44 public: | |
| 45 virtual void OnContextInitialized(URLRequestContextPeer* context) = 0; | |
| 46 | |
| 47 protected: | |
| 48 friend class base::RefCountedThreadSafe<URLRequestContextPeerDelegate>; | |
| 49 | |
| 50 virtual ~URLRequestContextPeerDelegate() {} | |
| 51 }; | |
| 52 | |
| 53 URLRequestContextPeer(URLRequestContextPeerDelegate* delegate, | |
| 54 std::string user_agent, | |
| 55 int log_level, | |
| 56 const char* version); | |
| 57 void Initialize(); | |
| 58 | |
| 59 const std::string& GetUserAgent(const GURL& url) const; | |
| 60 | |
| 61 int logging_level() const { return logging_level_; } | |
| 62 | |
| 63 const char* version() const { return version_; } | |
| 64 | |
| 65 // net::URLRequestContextGetter implementation: | |
| 66 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; | |
| 67 virtual scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() | |
| 68 const OVERRIDE; | |
| 69 | |
| 70 void StartNetLogToFile(const std::string& file_name); | |
| 71 void StopNetLog(); | |
| 72 | |
| 73 private: | |
| 74 scoped_refptr<URLRequestContextPeerDelegate> delegate_; | |
| 75 scoped_ptr<net::URLRequestContext> context_; | |
| 76 int logging_level_; | |
| 77 const char* version_; | |
| 78 std::string user_agent_; | |
| 79 base::Thread* network_thread_; | |
| 80 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | |
| 81 scoped_ptr<NetLogObserver> net_log_observer_; | |
| 82 scoped_ptr<net::NetLogLogger> net_log_logger_; | |
| 83 | |
| 84 virtual ~URLRequestContextPeer(); | |
| 85 | |
| 86 // Initializes |context_| on the IO thread. | |
| 87 void InitializeURLRequestContext(); | |
| 88 | |
| 89 DISALLOW_COPY_AND_ASSIGN(URLRequestContextPeer); | |
| 90 }; | |
| 91 | |
| 92 #endif // NET_CRONET_ANDROID_URL_REQUEST_CONTEXT_PEER_H_ | |
| OLD | NEW |