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

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