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_ADAPTER_H_ | 5 #ifndef COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_ADAPTER_H_ |
6 #define COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_ADAPTER_H_ | 6 #define COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_ADAPTER_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/android/jni_android.h" | 13 #include "base/android/jni_android.h" |
14 #include "base/android/jni_array.h" | 14 #include "base/android/jni_array.h" |
15 #include "base/android/jni_string.h" | 15 #include "base/android/jni_string.h" |
16 #include "base/android/scoped_java_ref.h" | 16 #include "base/android/scoped_java_ref.h" |
17 #include "base/callback.h" | 17 #include "base/callback.h" |
18 #include "base/location.h" | 18 #include "base/location.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
| 21 #include "base/time/time.h" |
21 #include "net/base/request_priority.h" | 22 #include "net/base/request_priority.h" |
22 #include "net/url_request/url_request.h" | 23 #include "net/url_request/url_request.h" |
23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
24 | 25 |
25 namespace base { | 26 namespace base { |
26 class SingleThreadTaskRunner; | 27 class SingleThreadTaskRunner; |
27 } // namespace base | 28 } // namespace base |
28 | 29 |
29 namespace net { | 30 namespace net { |
30 class HttpRequestHeaders; | 31 class HttpRequestHeaders; |
(...skipping 22 matching lines...) Expand all Loading... |
53 // use cache, |jdisable_cache| has no effect. |jdisable_connection_migration| | 54 // use cache, |jdisable_cache| has no effect. |jdisable_connection_migration| |
54 // causes connection migration to be disabled for this request if true. If | 55 // causes connection migration to be disabled for this request if true. If |
55 // global connection migration flag is not enabled, | 56 // global connection migration flag is not enabled, |
56 // |jdisable_connection_migration| has no effect. | 57 // |jdisable_connection_migration| has no effect. |
57 CronetURLRequestAdapter(CronetURLRequestContextAdapter* context, | 58 CronetURLRequestAdapter(CronetURLRequestContextAdapter* context, |
58 JNIEnv* env, | 59 JNIEnv* env, |
59 jobject jurl_request, | 60 jobject jurl_request, |
60 const GURL& url, | 61 const GURL& url, |
61 net::RequestPriority priority, | 62 net::RequestPriority priority, |
62 jboolean jdisable_cache, | 63 jboolean jdisable_cache, |
63 jboolean jdisable_connection_migration); | 64 jboolean jdisable_connection_migration, |
| 65 jboolean jenable_metrics); |
64 ~CronetURLRequestAdapter() override; | 66 ~CronetURLRequestAdapter() override; |
65 | 67 |
66 // Methods called prior to Start are never called on network thread. | 68 // Methods called prior to Start are never called on network thread. |
67 | 69 |
68 // Sets the request method GET, POST etc. | 70 // Sets the request method GET, POST etc. |
69 jboolean SetHttpMethod(JNIEnv* env, | 71 jboolean SetHttpMethod(JNIEnv* env, |
70 const base::android::JavaParamRef<jobject>& jcaller, | 72 const base::android::JavaParamRef<jobject>& jcaller, |
71 const base::android::JavaParamRef<jstring>& jmethod); | 73 const base::android::JavaParamRef<jstring>& jmethod); |
72 | 74 |
73 // Adds a header to the request before it starts. | 75 // Adds a header to the request before it starts. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 // Gets response headers on network thread. | 132 // Gets response headers on network thread. |
131 base::android::ScopedJavaLocalRef<jobjectArray> GetResponseHeaders( | 133 base::android::ScopedJavaLocalRef<jobjectArray> GetResponseHeaders( |
132 JNIEnv* env); | 134 JNIEnv* env); |
133 void FollowDeferredRedirectOnNetworkThread(); | 135 void FollowDeferredRedirectOnNetworkThread(); |
134 void ReadDataOnNetworkThread( | 136 void ReadDataOnNetworkThread( |
135 scoped_refptr<IOBufferWithByteBuffer> read_buffer, | 137 scoped_refptr<IOBufferWithByteBuffer> read_buffer, |
136 int buffer_size); | 138 int buffer_size); |
137 void DestroyOnNetworkThread(bool send_on_canceled); | 139 void DestroyOnNetworkThread(bool send_on_canceled); |
138 | 140 |
139 // Report error and cancel request_adapter. | 141 // Report error and cancel request_adapter. |
140 void ReportError(net::URLRequest* request, int net_error) const; | 142 void ReportError(net::URLRequest* request, int net_error); |
| 143 // Reports metrics collected to the Java layer |
| 144 void MaybeReportMetrics(JNIEnv* env) const; |
141 | 145 |
142 CronetURLRequestContextAdapter* context_; | 146 CronetURLRequestContextAdapter* context_; |
143 | 147 |
144 // Java object that owns this CronetURLRequestContextAdapter. | 148 // Java object that owns this CronetURLRequestContextAdapter. |
145 base::android::ScopedJavaGlobalRef<jobject> owner_; | 149 base::android::ScopedJavaGlobalRef<jobject> owner_; |
146 | 150 |
147 const GURL initial_url_; | 151 const GURL initial_url_; |
148 const net::RequestPriority initial_priority_; | 152 const net::RequestPriority initial_priority_; |
149 std::string initial_method_; | 153 std::string initial_method_; |
150 int load_flags_; | 154 int load_flags_; |
151 net::HttpRequestHeaders initial_request_headers_; | 155 net::HttpRequestHeaders initial_request_headers_; |
152 std::unique_ptr<net::UploadDataStream> upload_; | 156 std::unique_ptr<net::UploadDataStream> upload_; |
153 | 157 |
154 scoped_refptr<IOBufferWithByteBuffer> read_buffer_; | 158 scoped_refptr<IOBufferWithByteBuffer> read_buffer_; |
155 std::unique_ptr<net::URLRequest> url_request_; | 159 std::unique_ptr<net::URLRequest> url_request_; |
156 | 160 |
| 161 // Whether detailed metrics should be collected and reported to Java for this |
| 162 // request. |
| 163 const bool enable_metrics_; |
| 164 |
157 DISALLOW_COPY_AND_ASSIGN(CronetURLRequestAdapter); | 165 DISALLOW_COPY_AND_ASSIGN(CronetURLRequestAdapter); |
158 }; | 166 }; |
159 | 167 |
160 } // namespace cronet | 168 } // namespace cronet |
161 | 169 |
162 #endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_ADAPTER_H_ | 170 #endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_ADAPTER_H_ |
OLD | NEW |