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

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 comments from Paul 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
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 ProxyConfigService; 31 class ProxyConfigService;
30 class SdchOwner; 32 class SdchOwner;
31 class URLRequestContext; 33 class URLRequestContext;
32 class WriteToFileNetLogObserver; 34 class WriteToFileNetLogObserver;
33 } // namespace net 35 } // namespace net
34 36
35 namespace cronet { 37 namespace cronet {
36 38
37 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 39 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
38 class CronetDataReductionProxy; 40 class CronetDataReductionProxy;
39 #endif 41 #endif
40 42
41 struct URLRequestContextConfig; 43 struct URLRequestContextConfig;
42 44
43 bool CronetUrlRequestContextAdapterRegisterJni(JNIEnv* env); 45 bool CronetUrlRequestContextAdapterRegisterJni(JNIEnv* env);
44 46
45 // Adapter between Java CronetUrlRequestContext and net::URLRequestContext. 47 // Adapter between Java CronetUrlRequestContext and net::URLRequestContext.
46 class CronetURLRequestContextAdapter { 48 class CronetURLRequestContextAdapter
49 : public net::NetworkQualityEstimator::RTTObserver,
50 public net::NetworkQualityEstimator::ThroughputObserver {
47 public: 51 public:
48 explicit CronetURLRequestContextAdapter( 52 explicit CronetURLRequestContextAdapter(
49 scoped_ptr<URLRequestContextConfig> context_config); 53 scoped_ptr<URLRequestContextConfig> context_config);
50 54
51 ~CronetURLRequestContextAdapter(); 55 ~CronetURLRequestContextAdapter() override;
52 56
53 // Called on main Java thread to initialize URLRequestContext. 57 // Called on main Java thread to initialize URLRequestContext.
54 void InitRequestContextOnMainThread(JNIEnv* env, jobject jcaller); 58 void InitRequestContextOnMainThread(JNIEnv* env, jobject jcaller);
55 59
56 // Releases all resources for the request context and deletes the object. 60 // Releases all resources for the request context and deletes the object.
57 // Blocks until network thread is destroyed after running all pending tasks. 61 // Blocks until network thread is destroyed after running all pending tasks.
58 void Destroy(JNIEnv* env, jobject jcaller); 62 void Destroy(JNIEnv* env, jobject jcaller);
59 63
60 // Posts a task that might depend on the context being initialized 64 // Posts a task that might depend on the context being initialized
61 // to the network thread. 65 // to the network thread.
62 void PostTaskToNetworkThread(const tracked_objects::Location& posted_from, 66 void PostTaskToNetworkThread(const tracked_objects::Location& posted_from,
63 const base::Closure& callback); 67 const base::Closure& callback);
64 68
65 bool IsOnNetworkThread() const; 69 bool IsOnNetworkThread() const;
66 70
67 net::URLRequestContext* GetURLRequestContext(); 71 net::URLRequestContext* GetURLRequestContext();
68 72
69 void StartNetLogToFile(JNIEnv* env, jobject jcaller, jstring jfile_name, 73 void StartNetLogToFile(JNIEnv* env, jobject jcaller, jstring jfile_name,
70 jboolean jlog_all); 74 jboolean jlog_all);
71 75
72 void StopNetLog(JNIEnv* env, jobject jcaller); 76 void StopNetLog(JNIEnv* env, jobject jcaller);
73 77
74 // Default net::LOAD flags used to create requests. 78 // Default net::LOAD flags used to create requests.
75 int default_load_flags() const { return default_load_flags_; } 79 int default_load_flags() const { return default_load_flags_; }
76 80
77 // Called on main Java thread to initialize URLRequestContext. 81 // Called on main Java thread to initialize URLRequestContext.
78 void InitRequestContextOnMainThread(); 82 void InitRequestContextOnMainThread();
79 83
84 // Enables the network quality estimator and optionally configures it to
85 // observe localhost requests, and to consider smaller responses when
86 // observing throughput. It is recommended that both options be set to false.
87 void EnableNetworkQualityEstimator(JNIEnv* env,
88 jobject jcaller,
89 jboolean use_local_host_requests,
90 jboolean use_smaller_responses);
91
92 // Request that RTT and/or throughput observations should or should not be
93 // provided by the network quality estimator.
94 void ProvideRTTObservations(JNIEnv* env, jobject jcaller, bool should);
95 void ProvideThroughputObservations(JNIEnv* env, jobject jcaller, bool should);
96
80 private: 97 private:
81 // Initializes |context_| on the Network thread. 98 // Initializes |context_| on the Network thread.
82 void InitializeOnNetworkThread(scoped_ptr<URLRequestContextConfig> config, 99 void InitializeOnNetworkThread(scoped_ptr<URLRequestContextConfig> config,
83 const base::android::ScopedJavaGlobalRef< 100 const base::android::ScopedJavaGlobalRef<
84 jobject>& jcronet_url_request_context); 101 jobject>& jcronet_url_request_context);
85 102
86 // Runs a task that might depend on the context being initialized. 103 // Runs a task that might depend on the context being initialized.
87 // This method should only be run on the network thread. 104 // This method should only be run on the network thread.
88 void RunTaskAfterContextInitOnNetworkThread( 105 void RunTaskAfterContextInitOnNetworkThread(
89 const base::Closure& task_to_run_after_context_init); 106 const base::Closure& task_to_run_after_context_init);
90 107
91 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() const; 108 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() const;
92 109
93 void StartNetLogToFileOnNetworkThread(const std::string& file_name, 110 void StartNetLogToFileOnNetworkThread(const std::string& file_name,
94 bool log_all); 111 bool log_all);
95 112
96 void StopNetLogOnNetworkThread(); 113 void StopNetLogOnNetworkThread();
97 114
98 // Gets the file thread. Create one if there is none. 115 // Gets the file thread. Create one if there is none.
99 base::Thread* GetFileThread(); 116 base::Thread* GetFileThread();
100 117
118 // Instantiate and configure the network quality estimator. For default
119 // behavior, parameters should be set to false; otherwise the estimator
120 // can be configured to observe requests to localhost, as well as to use
121 // observe smaller responses when estimating throughput.
122 void EnableNetworkQualityEstimatorOnNetworkThread(
123 bool use_local_host_requests,
124 bool use_smaller_responses);
125
126 void ProvideRTTObservationsOnNetworkThread(bool should);
127 void ProvideThroughputObservationsOnNetworkThread(bool should);
128
129 // net::NetworkQualityEstimator::RTTObserver implementation.
130 void OnRTTObservation(
131 int32_t rtt_ms,
132 const base::TimeTicks& timestamp,
133 net::NetworkQualityEstimator::ObservationSource source) override;
134
135 // net::NetworkQualityEstimator::ThroughputObserver implementation.
136 void OnThroughputObservation(
137 int32_t throughput_kbps,
138 const base::TimeTicks& timestamp,
139 net::NetworkQualityEstimator::ObservationSource source) override;
140
101 // Network thread is owned by |this|, but is destroyed from java thread. 141 // Network thread is owned by |this|, but is destroyed from java thread.
102 base::Thread* network_thread_; 142 base::Thread* network_thread_;
103 143
104 // File thread should be destroyed last. 144 // File thread should be destroyed last.
105 scoped_ptr<base::Thread> file_thread_; 145 scoped_ptr<base::Thread> file_thread_;
106 146
107 // |write_to_file_observer_| and |context_| should only be accessed on 147 // |write_to_file_observer_| and |context_| should only be accessed on
108 // network thread. 148 // network thread.
109 scoped_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_; 149 scoped_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_;
110 150
(...skipping 11 matching lines...) Expand all
122 scoped_ptr<net::SdchOwner> sdch_owner_; 162 scoped_ptr<net::SdchOwner> sdch_owner_;
123 163
124 // Context config is only valid until context is initialized. 164 // Context config is only valid until context is initialized.
125 scoped_ptr<URLRequestContextConfig> context_config_; 165 scoped_ptr<URLRequestContextConfig> context_config_;
126 166
127 // A queue of tasks that need to be run after context has been initialized. 167 // A queue of tasks that need to be run after context has been initialized.
128 std::queue<base::Closure> tasks_waiting_for_context_; 168 std::queue<base::Closure> tasks_waiting_for_context_;
129 bool is_context_initialized_; 169 bool is_context_initialized_;
130 int default_load_flags_; 170 int default_load_flags_;
131 171
172 // A network quality estimator.
173 scoped_ptr<net::NetworkQualityEstimator> network_quality_estimator_;
174
175 // Java object that owns this CronetURLRequestContextAdapter.
176 base::android::ScopedJavaGlobalRef<jobject> jcronet_url_request_context_;
177
132 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 178 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
133 scoped_ptr<CronetDataReductionProxy> data_reduction_proxy_; 179 scoped_ptr<CronetDataReductionProxy> data_reduction_proxy_;
134 #endif 180 #endif
135 181
136 DISALLOW_COPY_AND_ASSIGN(CronetURLRequestContextAdapter); 182 DISALLOW_COPY_AND_ASSIGN(CronetURLRequestContextAdapter);
137 }; 183 };
138 184
139 } // namespace cronet 185 } // namespace cronet
140 186
141 #endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_ 187 #endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698