OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_ADAPTER_H_ | 5 #ifndef COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_ADAPTER_H_ |
6 #define COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_ADAPTER_H_ | 6 #define COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_ADAPTER_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "net/base/net_log.h" | 18 #include "net/base/net_log.h" |
19 #include "net/base/network_change_notifier.h" | 19 #include "net/base/network_change_notifier.h" |
20 #include "net/url_request/url_request_context.h" | 20 #include "net/url_request/url_request_context.h" |
21 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
22 | 22 |
23 namespace net { | 23 namespace net { |
24 | 24 |
25 class NetLogLogger; | 25 class NetLogLogger; |
26 | 26 |
| 27 class ProxyConfigService; |
| 28 |
27 } // namespace net | 29 } // namespace net |
28 | 30 |
29 namespace cronet { | 31 namespace cronet { |
30 | 32 |
31 struct URLRequestContextConfig; | 33 struct URLRequestContextConfig; |
32 typedef base::Callback<void(void)> RunAfterContextInitTask; | 34 typedef base::Callback<void(void)> RunAfterContextInitTask; |
33 | 35 |
34 // Implementation of the Chromium NetLog observer interface. | 36 // Implementation of the Chromium NetLog observer interface. |
35 class NetLogObserver : public net::NetLog::ThreadSafeObserver { | 37 class NetLogObserver : public net::NetLog::ThreadSafeObserver { |
36 public: | 38 public: |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 const std::string& GetUserAgent(const GURL& url) const; | 77 const std::string& GetUserAgent(const GURL& url) const; |
76 | 78 |
77 // net::URLRequestContextGetter implementation: | 79 // net::URLRequestContextGetter implementation: |
78 net::URLRequestContext* GetURLRequestContext() override; | 80 net::URLRequestContext* GetURLRequestContext() override; |
79 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() | 81 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() |
80 const override; | 82 const override; |
81 | 83 |
82 void StartNetLogToFile(const std::string& file_name); | 84 void StartNetLogToFile(const std::string& file_name); |
83 void StopNetLog(); | 85 void StopNetLog(); |
84 | 86 |
| 87 // Called on main Java thread to initialize URLRequestContext. |
| 88 void InitRequestContextOnMainThread(); |
| 89 |
85 private: | 90 private: |
86 scoped_refptr<URLRequestContextAdapterDelegate> delegate_; | 91 scoped_refptr<URLRequestContextAdapterDelegate> delegate_; |
87 scoped_ptr<net::URLRequestContext> context_; | 92 scoped_ptr<net::URLRequestContext> context_; |
88 std::string user_agent_; | 93 std::string user_agent_; |
89 base::Thread* network_thread_; | 94 base::Thread* network_thread_; |
90 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 95 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
91 scoped_ptr<NetLogObserver> net_log_observer_; | 96 scoped_ptr<NetLogObserver> net_log_observer_; |
92 scoped_ptr<net::NetLogLogger> net_log_logger_; | 97 scoped_ptr<net::NetLogLogger> net_log_logger_; |
| 98 scoped_ptr<net::ProxyConfigService> proxy_config_service_; |
| 99 scoped_ptr<URLRequestContextConfig> config_; |
93 | 100 |
94 // A queue of tasks that need to be run after context has been initialized. | 101 // A queue of tasks that need to be run after context has been initialized. |
95 std::queue<RunAfterContextInitTask> tasks_waiting_for_context_; | 102 std::queue<RunAfterContextInitTask> tasks_waiting_for_context_; |
96 bool is_context_initialized_; | 103 bool is_context_initialized_ = false; |
97 | 104 |
98 virtual ~URLRequestContextAdapter(); | 105 virtual ~URLRequestContextAdapter(); |
99 | 106 |
100 // Initializes |context_| on the Network thread. | 107 // Initializes |context_| on the Network thread. |
101 void InitializeURLRequestContext(scoped_ptr<URLRequestContextConfig> config); | 108 void InitRequestContextOnNetworkThread(); |
102 | 109 |
103 // Helper function to start writing NetLog data to file. This should only be | 110 // Helper function to start writing NetLog data to file. This should only be |
104 // run after context is initialized. | 111 // run after context is initialized. |
105 void StartNetLogToFileHelper(const std::string& file_name); | 112 void StartNetLogToFileHelper(const std::string& file_name); |
106 // Helper function to stop writing NetLog data to file. This should only be | 113 // Helper function to stop writing NetLog data to file. This should only be |
107 // run after context is initialized. | 114 // run after context is initialized. |
108 void StopNetLogHelper(); | 115 void StopNetLogHelper(); |
109 | 116 |
110 DISALLOW_COPY_AND_ASSIGN(URLRequestContextAdapter); | 117 DISALLOW_COPY_AND_ASSIGN(URLRequestContextAdapter); |
111 }; | 118 }; |
112 | 119 |
113 } // namespace cronet | 120 } // namespace cronet |
114 | 121 |
115 #endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_ADAPTER_H_ | 122 #endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_ADAPTER_H_ |
OLD | NEW |