| 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/log/net_log.h" | 18 #include "net/log/net_log.h" |
| 19 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
| 20 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
| 21 | 21 |
| 22 namespace net { | 22 namespace net { |
| 23 class WriteToFileNetLogObserver; | 23 class CertVerifier; |
| 24 class ProxyConfigService; | 24 class ProxyConfigService; |
| 25 class SdchOwner; | 25 class SdchOwner; |
| 26 class URLRequestContextBuilder; |
| 27 class WriteToFileNetLogObserver; |
| 26 } // namespace net | 28 } // namespace net |
| 27 | 29 |
| 28 namespace cronet { | 30 namespace cronet { |
| 29 | 31 |
| 30 struct URLRequestContextConfig; | 32 struct URLRequestContextConfig; |
| 31 typedef base::Callback<void(void)> RunAfterContextInitTask; | 33 typedef base::Callback<void(void)> RunAfterContextInitTask; |
| 32 | 34 |
| 33 // Implementation of the Chromium NetLog observer interface. | 35 // Implementation of the Chromium NetLog observer interface. |
| 34 class NetLogObserver : public net::NetLog::ThreadSafeObserver { | 36 class NetLogObserver : public net::NetLog::ThreadSafeObserver { |
| 35 public: | 37 public: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 net::URLRequestContext* GetURLRequestContext() override; | 81 net::URLRequestContext* GetURLRequestContext() override; |
| 80 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() | 82 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() |
| 81 const override; | 83 const override; |
| 82 | 84 |
| 83 void StartNetLogToFile(const std::string& file_name, bool log_all); | 85 void StartNetLogToFile(const std::string& file_name, bool log_all); |
| 84 void StopNetLog(); | 86 void StopNetLog(); |
| 85 | 87 |
| 86 // Called on main Java thread to initialize URLRequestContext. | 88 // Called on main Java thread to initialize URLRequestContext. |
| 87 void InitRequestContextOnMainThread(); | 89 void InitRequestContextOnMainThread(); |
| 88 | 90 |
| 91 // Sets a net::CertVerifier for testing. |
| 92 void SetMockCertVerifierForTesting(net::CertVerifier* cert_verifier); |
| 93 |
| 89 private: | 94 private: |
| 90 ~URLRequestContextAdapter() override; | 95 ~URLRequestContextAdapter() override; |
| 91 | 96 |
| 92 // Initializes |context_| on the Network thread. | 97 // Initializes |context_| on the Network thread. |
| 93 void InitRequestContextOnNetworkThread(); | 98 void InitRequestContextOnNetworkThread(); |
| 94 | 99 |
| 95 // Helper function to start writing NetLog data to file. This should only be | 100 // Helper function to start writing NetLog data to file. This should only be |
| 96 // run after context is initialized. | 101 // run after context is initialized. |
| 97 void StartNetLogToFileHelper(const std::string& file_name, bool log_all); | 102 void StartNetLogToFileHelper(const std::string& file_name, bool log_all); |
| 98 // Helper function to stop writing NetLog data to file. This should only be | 103 // Helper function to stop writing NetLog data to file. This should only be |
| 99 // run after context is initialized. | 104 // run after context is initialized. |
| 100 void StopNetLogHelper(); | 105 void StopNetLogHelper(); |
| 101 | 106 |
| 107 void SetMockCertVerifierForTestingOnNetworkThread( |
| 108 net::CertVerifier* cert_verifier); |
| 109 |
| 102 scoped_refptr<URLRequestContextAdapterDelegate> delegate_; | 110 scoped_refptr<URLRequestContextAdapterDelegate> delegate_; |
| 103 scoped_ptr<net::URLRequestContext> context_; | 111 scoped_ptr<net::URLRequestContext> context_; |
| 104 std::string user_agent_; | 112 std::string user_agent_; |
| 105 bool load_disable_cache_; | 113 bool load_disable_cache_; |
| 106 base::Thread* network_thread_; | 114 base::Thread* network_thread_; |
| 115 scoped_ptr<net::URLRequestContextBuilder> context_builder_; |
| 107 scoped_ptr<NetLogObserver> net_log_observer_; | 116 scoped_ptr<NetLogObserver> net_log_observer_; |
| 108 scoped_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_; | 117 scoped_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_; |
| 109 scoped_ptr<net::ProxyConfigService> proxy_config_service_; | 118 scoped_ptr<net::ProxyConfigService> proxy_config_service_; |
| 110 scoped_ptr<net::SdchOwner> sdch_owner_; | 119 scoped_ptr<net::SdchOwner> sdch_owner_; |
| 111 scoped_ptr<URLRequestContextConfig> config_; | 120 scoped_ptr<URLRequestContextConfig> config_; |
| 112 | 121 |
| 113 // A queue of tasks that need to be run after context has been initialized. | 122 // A queue of tasks that need to be run after context has been initialized. |
| 114 std::queue<RunAfterContextInitTask> tasks_waiting_for_context_; | 123 std::queue<RunAfterContextInitTask> tasks_waiting_for_context_; |
| 115 bool is_context_initialized_; | 124 bool is_context_initialized_; |
| 116 | 125 |
| 117 DISALLOW_COPY_AND_ASSIGN(URLRequestContextAdapter); | 126 DISALLOW_COPY_AND_ASSIGN(URLRequestContextAdapter); |
| 118 }; | 127 }; |
| 119 | 128 |
| 120 } // namespace cronet | 129 } // namespace cronet |
| 121 | 130 |
| 122 #endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_ADAPTER_H_ | 131 #endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_ADAPTER_H_ |
| OLD | NEW |