Chromium Code Reviews| 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 #include "base/time/time.h" | |
| 21 #include "net/base/network_quality_estimator.h" | |
| 20 | 22 |
| 21 class PrefService; | 23 class PrefService; |
| 22 | 24 |
| 23 namespace base { | 25 namespace base { |
| 24 class SingleThreadTaskRunner; | 26 class SingleThreadTaskRunner; |
| 27 class Time; | |
| 25 } // namespace base | 28 } // namespace base |
| 26 | 29 |
| 27 namespace net { | 30 namespace net { |
| 28 class HttpServerPropertiesManager; | 31 class HttpServerPropertiesManager; |
| 32 class NetworkQualityEstimator; | |
| 29 class ProxyConfigService; | 33 class ProxyConfigService; |
| 30 class SdchOwner; | 34 class SdchOwner; |
| 31 class URLRequestContext; | 35 class URLRequestContext; |
| 32 class WriteToFileNetLogObserver; | 36 class WriteToFileNetLogObserver; |
| 33 } // namespace net | 37 } // namespace net |
| 34 | 38 |
| 35 namespace cronet { | 39 namespace cronet { |
| 36 | 40 |
| 37 #if defined(DATA_REDUCTION_PROXY_SUPPORT) | 41 #if defined(DATA_REDUCTION_PROXY_SUPPORT) |
| 38 class CronetDataReductionProxy; | 42 class CronetDataReductionProxy; |
| 39 #endif | 43 #endif |
| 40 | 44 |
| 41 struct URLRequestContextConfig; | 45 struct URLRequestContextConfig; |
| 42 | 46 |
| 43 bool CronetUrlRequestContextAdapterRegisterJni(JNIEnv* env); | 47 bool CronetUrlRequestContextAdapterRegisterJni(JNIEnv* env); |
| 44 | 48 |
| 45 // Adapter between Java CronetUrlRequestContext and net::URLRequestContext. | 49 // Adapter between Java CronetUrlRequestContext and net::URLRequestContext. |
| 46 class CronetURLRequestContextAdapter { | 50 class CronetURLRequestContextAdapter |
| 51 : public net::NetworkQualityEstimator::RTTObserver, | |
| 52 public net::NetworkQualityEstimator::BandwidthObserver { | |
| 47 public: | 53 public: |
| 48 explicit CronetURLRequestContextAdapter( | 54 explicit CronetURLRequestContextAdapter( |
| 49 scoped_ptr<URLRequestContextConfig> context_config); | 55 scoped_ptr<URLRequestContextConfig> context_config); |
| 50 | 56 |
| 51 ~CronetURLRequestContextAdapter(); | 57 ~CronetURLRequestContextAdapter() override; |
| 52 | 58 |
| 53 // Called on main Java thread to initialize URLRequestContext. | 59 // Called on main Java thread to initialize URLRequestContext. |
| 54 void InitRequestContextOnMainThread(JNIEnv* env, jobject jcaller); | 60 void InitRequestContextOnMainThread(JNIEnv* env, jobject jcaller); |
| 55 | 61 |
| 56 // Releases all resources for the request context and deletes the object. | 62 // Releases all resources for the request context and deletes the object. |
| 57 // Blocks until network thread is destroyed after running all pending tasks. | 63 // Blocks until network thread is destroyed after running all pending tasks. |
| 58 void Destroy(JNIEnv* env, jobject jcaller); | 64 void Destroy(JNIEnv* env, jobject jcaller); |
| 59 | 65 |
| 60 // Posts a task that might depend on the context being initialized | 66 // Posts a task that might depend on the context being initialized |
| 61 // to the network thread. | 67 // to the network thread. |
| 62 void PostTaskToNetworkThread(const tracked_objects::Location& posted_from, | 68 void PostTaskToNetworkThread(const tracked_objects::Location& posted_from, |
| 63 const base::Closure& callback); | 69 const base::Closure& callback); |
| 64 | 70 |
| 65 bool IsOnNetworkThread() const; | 71 bool IsOnNetworkThread() const; |
| 66 | 72 |
| 67 net::URLRequestContext* GetURLRequestContext(); | 73 net::URLRequestContext* GetURLRequestContext(); |
| 68 | 74 |
| 69 void StartNetLogToFile(JNIEnv* env, jobject jcaller, jstring jfile_name, | 75 void StartNetLogToFile(JNIEnv* env, jobject jcaller, jstring jfile_name, |
| 70 jboolean jlog_all); | 76 jboolean jlog_all); |
| 71 | 77 |
| 72 void StopNetLog(JNIEnv* env, jobject jcaller); | 78 void StopNetLog(JNIEnv* env, jobject jcaller); |
| 73 | 79 |
| 74 // Default net::LOAD flags used to create requests. | 80 // Default net::LOAD flags used to create requests. |
| 75 int default_load_flags() const { return default_load_flags_; } | 81 int default_load_flags() const { return default_load_flags_; } |
| 76 | 82 |
| 77 // Called on main Java thread to initialize URLRequestContext. | 83 // Called on main Java thread to initialize URLRequestContext. |
| 78 void InitRequestContextOnMainThread(); | 84 void InitRequestContextOnMainThread(); |
| 79 | 85 |
| 86 | |
| 87 void ConfigureNetworkQualityEstimator(JNIEnv* env, jobject jcaller, | |
|
mef
2015/08/11 17:16:26
need comment, don't need nl above.
bengr
2015/08/25 23:43:34
Done.
| |
| 88 jboolean use_local_host_requests, | |
| 89 jboolean use_smaller_responses); | |
| 90 | |
| 91 // Request that RTT and/or bandwidth observations should or should not be | |
| 92 // provided by the network quality estimator. | |
| 93 void ProvideRTTObservations(JNIEnv* env, jobject jcaller, bool should); | |
|
mef
2015/08/11 17:16:26
Would it make sens to combine these 3 methods into
bengr
2015/08/25 23:43:34
Not really. These two are optimizations so that NQ
mef
2015/08/26 16:58:59
Acknowledged.
| |
| 94 void ProvideBandwidthObservations(JNIEnv* env, jobject jcaller, bool should); | |
| 95 | |
| 80 private: | 96 private: |
| 81 // Initializes |context_| on the Network thread. | 97 // Initializes |context_| on the Network thread. |
| 82 void InitializeOnNetworkThread(scoped_ptr<URLRequestContextConfig> config, | 98 void InitializeOnNetworkThread(scoped_ptr<URLRequestContextConfig> config, |
| 83 const base::android::ScopedJavaGlobalRef< | 99 const base::android::ScopedJavaGlobalRef< |
| 84 jobject>& jcronet_url_request_context); | 100 jobject>& jcronet_url_request_context); |
| 85 | 101 |
| 86 // Runs a task that might depend on the context being initialized. | 102 // Runs a task that might depend on the context being initialized. |
| 87 // This method should only be run on the network thread. | 103 // This method should only be run on the network thread. |
| 88 void RunTaskAfterContextInitOnNetworkThread( | 104 void RunTaskAfterContextInitOnNetworkThread( |
| 89 const base::Closure& task_to_run_after_context_init); | 105 const base::Closure& task_to_run_after_context_init); |
| 90 | 106 |
| 91 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() const; | 107 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() const; |
| 92 | 108 |
| 93 void StartNetLogToFileOnNetworkThread(const std::string& file_name, | 109 void StartNetLogToFileOnNetworkThread(const std::string& file_name, |
| 94 bool log_all); | 110 bool log_all); |
| 95 | 111 |
| 96 void StopNetLogOnNetworkThread(); | 112 void StopNetLogOnNetworkThread(); |
| 97 | 113 |
| 98 // Gets the file thread. Create one if there is none. | 114 // Gets the file thread. Create one if there is none. |
| 99 base::Thread* GetFileThread(); | 115 base::Thread* GetFileThread(); |
| 100 | 116 |
| 117 // net::NetworkQualityEstimator::RTTObserver implementation. | |
| 118 void OnRTTObservation( | |
| 119 int32_t value, const base::TimeTicks& timestamp, | |
| 120 net::NetworkQualityEstimator::ObservationSource source) override; | |
| 121 | |
| 122 // net::NetworkQualityEstimator::BandwidthObserver implementation. | |
| 123 void OnBandwidthObservation( | |
| 124 int32_t value, const base::TimeTicks& timestamp, | |
| 125 net::NetworkQualityEstimator::ObservationSource source) override; | |
| 126 | |
| 101 // Network thread is owned by |this|, but is destroyed from java thread. | 127 // Network thread is owned by |this|, but is destroyed from java thread. |
| 102 base::Thread* network_thread_; | 128 base::Thread* network_thread_; |
| 103 | 129 |
| 104 // File thread should be destroyed last. | 130 // File thread should be destroyed last. |
| 105 scoped_ptr<base::Thread> file_thread_; | 131 scoped_ptr<base::Thread> file_thread_; |
| 106 | 132 |
| 107 // |write_to_file_observer_| and |context_| should only be accessed on | 133 // |write_to_file_observer_| and |context_| should only be accessed on |
| 108 // network thread. | 134 // network thread. |
| 109 scoped_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_; | 135 scoped_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_; |
| 110 | 136 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 122 scoped_ptr<net::SdchOwner> sdch_owner_; | 148 scoped_ptr<net::SdchOwner> sdch_owner_; |
| 123 | 149 |
| 124 // Context config is only valid until context is initialized. | 150 // Context config is only valid until context is initialized. |
| 125 scoped_ptr<URLRequestContextConfig> context_config_; | 151 scoped_ptr<URLRequestContextConfig> context_config_; |
| 126 | 152 |
| 127 // A queue of tasks that need to be run after context has been initialized. | 153 // A queue of tasks that need to be run after context has been initialized. |
| 128 std::queue<base::Closure> tasks_waiting_for_context_; | 154 std::queue<base::Closure> tasks_waiting_for_context_; |
| 129 bool is_context_initialized_; | 155 bool is_context_initialized_; |
| 130 int default_load_flags_; | 156 int default_load_flags_; |
| 131 | 157 |
| 158 // A network quality estimator. | |
| 159 scoped_ptr<net::NetworkQualityEstimator> network_quality_estimator_; | |
|
mef
2015/08/11 17:16:26
does it need special shutdown handling?
bengr
2015/08/25 23:43:34
Nope.
| |
| 160 | |
| 161 base::android::ScopedJavaGlobalRef<jobject> jcronet_url_request_context_; | |
| 162 | |
| 132 #if defined(DATA_REDUCTION_PROXY_SUPPORT) | 163 #if defined(DATA_REDUCTION_PROXY_SUPPORT) |
| 133 scoped_ptr<CronetDataReductionProxy> data_reduction_proxy_; | 164 scoped_ptr<CronetDataReductionProxy> data_reduction_proxy_; |
| 134 #endif | 165 #endif |
| 135 | 166 |
| 136 DISALLOW_COPY_AND_ASSIGN(CronetURLRequestContextAdapter); | 167 DISALLOW_COPY_AND_ASSIGN(CronetURLRequestContextAdapter); |
| 137 }; | 168 }; |
| 138 | 169 |
| 139 } // namespace cronet | 170 } // namespace cronet |
| 140 | 171 |
| 141 #endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_ | 172 #endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_ |
| OLD | NEW |