Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: components/cronet/android/cronet_url_request_context_adapter.h

Issue 1273173002: Added Network Quality Estimator Real-time interface to Cronet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed remaining comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/cronet.gypi ('k') | components/cronet/android/cronet_url_request_context_adapter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "net/base/network_quality_estimator.h"
20 21
21 class PrefService; 22 class PrefService;
22 23
23 namespace base { 24 namespace base {
24 class SingleThreadTaskRunner; 25 class SingleThreadTaskRunner;
26 class TimeTicks;
25 } // namespace base 27 } // namespace base
26 28
27 namespace net { 29 namespace net {
28 class HttpServerPropertiesManager; 30 class HttpServerPropertiesManager;
29 class NetLog; 31 class NetLog;
32 class NetworkQualityEstimator;
30 class ProxyConfigService; 33 class ProxyConfigService;
31 class SdchOwner; 34 class SdchOwner;
32 class URLRequestContext; 35 class URLRequestContext;
33 class WriteToFileNetLogObserver; 36 class WriteToFileNetLogObserver;
34 } // namespace net 37 } // namespace net
35 38
36 namespace cronet { 39 namespace cronet {
37 40
38 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 41 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
39 class CronetDataReductionProxy; 42 class CronetDataReductionProxy;
40 #endif 43 #endif
41 44
42 struct URLRequestContextConfig; 45 struct URLRequestContextConfig;
43 46
44 bool CronetUrlRequestContextAdapterRegisterJni(JNIEnv* env); 47 bool CronetUrlRequestContextAdapterRegisterJni(JNIEnv* env);
45 48
46 // Adapter between Java CronetUrlRequestContext and net::URLRequestContext. 49 // Adapter between Java CronetUrlRequestContext and net::URLRequestContext.
47 class CronetURLRequestContextAdapter { 50 class CronetURLRequestContextAdapter
51 : public net::NetworkQualityEstimator::RTTObserver,
52 public net::NetworkQualityEstimator::ThroughputObserver {
48 public: 53 public:
49 explicit CronetURLRequestContextAdapter( 54 explicit CronetURLRequestContextAdapter(
50 scoped_ptr<URLRequestContextConfig> context_config); 55 scoped_ptr<URLRequestContextConfig> context_config);
51 56
52 ~CronetURLRequestContextAdapter(); 57 ~CronetURLRequestContextAdapter() override;
53 58
54 // Called on main Java thread to initialize URLRequestContext. 59 // Called on main Java thread to initialize URLRequestContext.
55 void InitRequestContextOnMainThread(JNIEnv* env, jobject jcaller); 60 void InitRequestContextOnMainThread(JNIEnv* env, jobject jcaller);
56 61
57 // Releases all resources for the request context and deletes the object. 62 // Releases all resources for the request context and deletes the object.
58 // Blocks until network thread is destroyed after running all pending tasks. 63 // Blocks until network thread is destroyed after running all pending tasks.
59 void Destroy(JNIEnv* env, jobject jcaller); 64 void Destroy(JNIEnv* env, jobject jcaller);
60 65
61 // Posts a task that might depend on the context being initialized 66 // Posts a task that might depend on the context being initialized
62 // to the network thread. 67 // to the network thread.
63 void PostTaskToNetworkThread(const tracked_objects::Location& posted_from, 68 void PostTaskToNetworkThread(const tracked_objects::Location& posted_from,
64 const base::Closure& callback); 69 const base::Closure& callback);
65 70
66 bool IsOnNetworkThread() const; 71 bool IsOnNetworkThread() const;
67 72
68 net::URLRequestContext* GetURLRequestContext(); 73 net::URLRequestContext* GetURLRequestContext();
69 74
70 void StartNetLogToFile(JNIEnv* env, jobject jcaller, jstring jfile_name, 75 void StartNetLogToFile(JNIEnv* env, jobject jcaller, jstring jfile_name,
71 jboolean jlog_all); 76 jboolean jlog_all);
72 77
73 void StopNetLog(JNIEnv* env, jobject jcaller); 78 void StopNetLog(JNIEnv* env, jobject jcaller);
74 79
75 // Default net::LOAD flags used to create requests. 80 // Default net::LOAD flags used to create requests.
76 int default_load_flags() const { return default_load_flags_; } 81 int default_load_flags() const { return default_load_flags_; }
77 82
78 // Called on main Java thread to initialize URLRequestContext. 83 // Called on main Java thread to initialize URLRequestContext.
79 void InitRequestContextOnMainThread(); 84 void InitRequestContextOnMainThread();
80 85
86 // Enables the network quality estimator and optionally configures it to
87 // observe localhost requests, and to consider smaller responses when
88 // observing throughput. It is recommended that both options be set to false.
89 void EnableNetworkQualityEstimator(JNIEnv* env,
90 jobject jcaller,
91 jboolean use_local_host_requests,
92 jboolean use_smaller_responses);
93
94 // Request that RTT and/or throughput observations should or should not be
95 // provided by the network quality estimator.
96 void ProvideRTTObservations(JNIEnv* env, jobject jcaller, bool should);
97 void ProvideThroughputObservations(JNIEnv* env, jobject jcaller, bool should);
98
81 private: 99 private:
82 // Initializes |context_| on the Network thread. 100 // Initializes |context_| on the Network thread.
83 void InitializeOnNetworkThread(scoped_ptr<URLRequestContextConfig> config, 101 void InitializeOnNetworkThread(scoped_ptr<URLRequestContextConfig> config,
84 const base::android::ScopedJavaGlobalRef< 102 const base::android::ScopedJavaGlobalRef<
85 jobject>& jcronet_url_request_context); 103 jobject>& jcronet_url_request_context);
86 104
87 // Runs a task that might depend on the context being initialized. 105 // Runs a task that might depend on the context being initialized.
88 // This method should only be run on the network thread. 106 // This method should only be run on the network thread.
89 void RunTaskAfterContextInitOnNetworkThread( 107 void RunTaskAfterContextInitOnNetworkThread(
90 const base::Closure& task_to_run_after_context_init); 108 const base::Closure& task_to_run_after_context_init);
91 109
92 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() const; 110 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() const;
93 111
94 void StartNetLogToFileOnNetworkThread(const std::string& file_name, 112 void StartNetLogToFileOnNetworkThread(const std::string& file_name,
95 bool log_all); 113 bool log_all);
96 114
97 void StopNetLogOnNetworkThread(); 115 void StopNetLogOnNetworkThread();
98 116
99 // Gets the file thread. Create one if there is none. 117 // Gets the file thread. Create one if there is none.
100 base::Thread* GetFileThread(); 118 base::Thread* GetFileThread();
101 119
120 // Instantiate and configure the network quality estimator. For default
121 // behavior, parameters should be set to false; otherwise the estimator
122 // can be configured to observe requests to localhost, as well as to use
123 // observe smaller responses when estimating throughput.
124 void EnableNetworkQualityEstimatorOnNetworkThread(
125 bool use_local_host_requests,
126 bool use_smaller_responses);
127
128 void ProvideRTTObservationsOnNetworkThread(bool should);
129 void ProvideThroughputObservationsOnNetworkThread(bool should);
130
131 // net::NetworkQualityEstimator::RTTObserver implementation.
132 void OnRTTObservation(
133 int32_t rtt_ms,
134 const base::TimeTicks& timestamp,
135 net::NetworkQualityEstimator::ObservationSource source) override;
136
137 // net::NetworkQualityEstimator::ThroughputObserver implementation.
138 void OnThroughputObservation(
139 int32_t throughput_kbps,
140 const base::TimeTicks& timestamp,
141 net::NetworkQualityEstimator::ObservationSource source) override;
142
102 // Network thread is owned by |this|, but is destroyed from java thread. 143 // Network thread is owned by |this|, but is destroyed from java thread.
103 base::Thread* network_thread_; 144 base::Thread* network_thread_;
104 145
105 // File thread should be destroyed last. 146 // File thread should be destroyed last.
106 scoped_ptr<base::Thread> file_thread_; 147 scoped_ptr<base::Thread> file_thread_;
107 148
108 // |write_to_file_observer_| and |context_| should only be accessed on 149 // |write_to_file_observer_| and |context_| should only be accessed on
109 // network thread. 150 // network thread.
110 scoped_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_; 151 scoped_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_;
111 152
(...skipping 12 matching lines...) Expand all
124 scoped_ptr<net::SdchOwner> sdch_owner_; 165 scoped_ptr<net::SdchOwner> sdch_owner_;
125 166
126 // Context config is only valid until context is initialized. 167 // Context config is only valid until context is initialized.
127 scoped_ptr<URLRequestContextConfig> context_config_; 168 scoped_ptr<URLRequestContextConfig> context_config_;
128 169
129 // A queue of tasks that need to be run after context has been initialized. 170 // A queue of tasks that need to be run after context has been initialized.
130 std::queue<base::Closure> tasks_waiting_for_context_; 171 std::queue<base::Closure> tasks_waiting_for_context_;
131 bool is_context_initialized_; 172 bool is_context_initialized_;
132 int default_load_flags_; 173 int default_load_flags_;
133 174
175 // A network quality estimator.
176 scoped_ptr<net::NetworkQualityEstimator> network_quality_estimator_;
177
178 // Java object that owns this CronetURLRequestContextAdapter.
179 base::android::ScopedJavaGlobalRef<jobject> jcronet_url_request_context_;
180
134 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 181 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
135 scoped_ptr<CronetDataReductionProxy> data_reduction_proxy_; 182 scoped_ptr<CronetDataReductionProxy> data_reduction_proxy_;
136 #endif 183 #endif
137 184
138 DISALLOW_COPY_AND_ASSIGN(CronetURLRequestContextAdapter); 185 DISALLOW_COPY_AND_ASSIGN(CronetURLRequestContextAdapter);
139 }; 186 };
140 187
141 } // namespace cronet 188 } // namespace cronet
142 189
143 #endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_ 190 #endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_
OLDNEW
« no previous file with comments | « components/cronet.gypi ('k') | components/cronet/android/cronet_url_request_context_adapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698