| 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_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_ | 5 #ifndef COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_ |
| 6 #define COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_ | 6 #define COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 | 9 |
| 10 #include <queue> | 10 #include <queue> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/android/scoped_java_ref.h" | 13 #include "base/android/scoped_java_ref.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/prefs/json_pref_store.h" | 18 #include "base/prefs/json_pref_store.h" |
| 19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 20 | 20 |
| 21 class PrefService; |
| 22 |
| 21 namespace base { | 23 namespace base { |
| 22 class SingleThreadTaskRunner; | 24 class SingleThreadTaskRunner; |
| 23 } // namespace base | 25 } // namespace base |
| 24 | 26 |
| 25 namespace net { | 27 namespace net { |
| 26 class WriteToFileNetLogObserver; | 28 class HttpServerPropertiesManager; |
| 27 class URLRequestContext; | |
| 28 class ProxyConfigService; | 29 class ProxyConfigService; |
| 29 class SdchOwner; | 30 class SdchOwner; |
| 31 class URLRequestContext; |
| 32 class WriteToFileNetLogObserver; |
| 30 } // namespace net | 33 } // namespace net |
| 31 | 34 |
| 32 namespace cronet { | 35 namespace cronet { |
| 33 | 36 |
| 34 #if defined(DATA_REDUCTION_PROXY_SUPPORT) | 37 #if defined(DATA_REDUCTION_PROXY_SUPPORT) |
| 35 class CronetDataReductionProxy; | 38 class CronetDataReductionProxy; |
| 36 #endif | 39 #endif |
| 37 | 40 |
| 38 struct URLRequestContextConfig; | 41 struct URLRequestContextConfig; |
| 39 | 42 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 int default_load_flags() const { return default_load_flags_; } | 75 int default_load_flags() const { return default_load_flags_; } |
| 73 | 76 |
| 74 // Called on main Java thread to initialize URLRequestContext. | 77 // Called on main Java thread to initialize URLRequestContext. |
| 75 void InitRequestContextOnMainThread(); | 78 void InitRequestContextOnMainThread(); |
| 76 | 79 |
| 77 private: | 80 private: |
| 78 // Initializes |context_| on the Network thread. | 81 // Initializes |context_| on the Network thread. |
| 79 void InitializeOnNetworkThread(scoped_ptr<URLRequestContextConfig> config, | 82 void InitializeOnNetworkThread(scoped_ptr<URLRequestContextConfig> config, |
| 80 const base::android::ScopedJavaGlobalRef< | 83 const base::android::ScopedJavaGlobalRef< |
| 81 jobject>& jcronet_url_request_context); | 84 jobject>& jcronet_url_request_context); |
| 85 void DestroyOnNetworkThread(); |
| 82 | 86 |
| 83 // Runs a task that might depend on the context being initialized. | 87 // Runs a task that might depend on the context being initialized. |
| 84 // This method should only be run on the network thread. | 88 // This method should only be run on the network thread. |
| 85 void RunTaskAfterContextInitOnNetworkThread( | 89 void RunTaskAfterContextInitOnNetworkThread( |
| 86 const base::Closure& task_to_run_after_context_init); | 90 const base::Closure& task_to_run_after_context_init); |
| 87 | 91 |
| 88 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() const; | 92 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() const; |
| 89 | 93 |
| 90 void StartNetLogToFileOnNetworkThread(const std::string& file_name, | 94 void StartNetLogToFileOnNetworkThread(const std::string& file_name, |
| 91 bool log_all); | 95 bool log_all); |
| 92 | 96 |
| 93 void StopNetLogOnNetworkThread(); | 97 void StopNetLogOnNetworkThread(); |
| 94 | 98 |
| 95 // Gets the file thread. Create one if there is none. | 99 // Gets the file thread. Create one if there is none. |
| 96 base::Thread* GetFileThread(); | 100 base::Thread* GetFileThread(); |
| 97 | 101 |
| 98 // Network thread is owned by |this|, but is destroyed from java thread. | 102 // Network thread is owned by |this|, but is destroyed from java thread. |
| 99 base::Thread* network_thread_; | 103 base::Thread* network_thread_; |
| 100 | 104 |
| 101 // File thread should be destroyed last. | 105 // File thread should be destroyed last. |
| 102 scoped_ptr<base::Thread> file_thread_; | 106 scoped_ptr<base::Thread> file_thread_; |
| 103 | 107 |
| 104 // |write_to_file_observer_| and |context_| should only be accessed on | 108 // |write_to_file_observer_| and |context_| should only be accessed on |
| 105 // network thread. | 109 // network thread. |
| 106 scoped_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_; | 110 scoped_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_; |
| 111 // |pref_service_| should outlive |http_server_properties_manager_|. |
| 112 scoped_ptr<PrefService> pref_service_; |
| 107 scoped_ptr<net::URLRequestContext> context_; | 113 scoped_ptr<net::URLRequestContext> context_; |
| 108 scoped_ptr<net::ProxyConfigService> proxy_config_service_; | 114 scoped_ptr<net::ProxyConfigService> proxy_config_service_; |
| 109 | 115 |
| 116 scoped_refptr<JsonPrefStore> json_pref_store_; |
| 117 scoped_ptr<net::HttpServerPropertiesManager> http_server_properties_manager_; |
| 110 // |sdch_owner_| should be destroyed before |json_pref_store_|, because | 118 // |sdch_owner_| should be destroyed before |json_pref_store_|, because |
| 111 // tearing down |sdch_owner_| forces |json_pref_store_| to flush pending | 119 // tearing down |sdch_owner_| forces |json_pref_store_| to flush pending |
| 112 // writes to the disk. | 120 // writes to the disk. |
| 113 scoped_refptr<JsonPrefStore> json_pref_store_; | |
| 114 scoped_ptr<net::SdchOwner> sdch_owner_; | 121 scoped_ptr<net::SdchOwner> sdch_owner_; |
| 115 | 122 |
| 116 // Context config is only valid untng context is initialized. | 123 // Context config is only valid untng context is initialized. |
| 117 scoped_ptr<URLRequestContextConfig> context_config_; | 124 scoped_ptr<URLRequestContextConfig> context_config_; |
| 118 | 125 |
| 119 // A queue of tasks that need to be run after context has been initialized. | 126 // A queue of tasks that need to be run after context has been initialized. |
| 120 std::queue<base::Closure> tasks_waiting_for_context_; | 127 std::queue<base::Closure> tasks_waiting_for_context_; |
| 121 bool is_context_initialized_; | 128 bool is_context_initialized_; |
| 122 int default_load_flags_; | 129 int default_load_flags_; |
| 123 | 130 |
| 124 #if defined(DATA_REDUCTION_PROXY_SUPPORT) | 131 #if defined(DATA_REDUCTION_PROXY_SUPPORT) |
| 125 scoped_ptr<CronetDataReductionProxy> data_reduction_proxy_; | 132 scoped_ptr<CronetDataReductionProxy> data_reduction_proxy_; |
| 126 #endif | 133 #endif |
| 127 | 134 |
| 128 DISALLOW_COPY_AND_ASSIGN(CronetURLRequestContextAdapter); | 135 DISALLOW_COPY_AND_ASSIGN(CronetURLRequestContextAdapter); |
| 129 }; | 136 }; |
| 130 | 137 |
| 131 } // namespace cronet | 138 } // namespace cronet |
| 132 | 139 |
| 133 #endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_ | 140 #endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_ |
| OLD | NEW |