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 package org.chromium.net; | 5 package org.chromium.net; |
6 | 6 |
7 import android.os.Build; | 7 import android.os.Build; |
8 import android.os.ConditionVariable; | 8 import android.os.ConditionVariable; |
9 import android.os.Handler; | 9 import android.os.Handler; |
10 import android.os.Looper; | 10 import android.os.Looper; |
11 import android.os.Process; | 11 import android.os.Process; |
12 import android.util.Log; | 12 import android.util.Log; |
13 | 13 |
14 import org.chromium.base.ObserverList; | 14 import org.chromium.base.ObserverList; |
15 import org.chromium.base.VisibleForTesting; | 15 import org.chromium.base.VisibleForTesting; |
16 import org.chromium.base.annotations.CalledByNative; | 16 import org.chromium.base.annotations.CalledByNative; |
17 import org.chromium.base.annotations.JNINamespace; | 17 import org.chromium.base.annotations.JNINamespace; |
18 import org.chromium.base.annotations.NativeClassQualifiedName; | 18 import org.chromium.base.annotations.NativeClassQualifiedName; |
19 import org.chromium.base.annotations.UsedByReflection; | 19 import org.chromium.base.annotations.UsedByReflection; |
| 20 import org.chromium.net.urlconnection.CronetHttpURLConnection; |
| 21 import org.chromium.net.urlconnection.CronetURLStreamHandlerFactory; |
20 | 22 |
| 23 import java.net.Proxy; |
| 24 import java.net.URL; |
| 25 import java.net.URLConnection; |
| 26 import java.net.URLStreamHandlerFactory; |
21 import java.util.concurrent.Executor; | 27 import java.util.concurrent.Executor; |
22 import java.util.concurrent.RejectedExecutionException; | 28 import java.util.concurrent.RejectedExecutionException; |
23 import java.util.concurrent.atomic.AtomicInteger; | 29 import java.util.concurrent.atomic.AtomicInteger; |
24 | 30 |
25 import javax.annotation.concurrent.GuardedBy; | 31 import javax.annotation.concurrent.GuardedBy; |
26 | 32 |
27 /** | 33 /** |
28 * CronetEngine using Chromium HTTP stack implementation. | 34 * CronetEngine using Chromium HTTP stack implementation. |
29 */ | 35 */ |
30 @JNINamespace("cronet") | 36 @JNINamespace("cronet") |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 mThroughputListenerList.removeObserver(listener); | 253 mThroughputListenerList.removeObserver(listener); |
248 if (mThroughputListenerList.isEmpty()) { | 254 if (mThroughputListenerList.isEmpty()) { |
249 synchronized (mLock) { | 255 synchronized (mLock) { |
250 checkHaveAdapter(); | 256 checkHaveAdapter(); |
251 nativeProvideThroughputObservations(mUrlRequestContextAdapte
r, false); | 257 nativeProvideThroughputObservations(mUrlRequestContextAdapte
r, false); |
252 } | 258 } |
253 } | 259 } |
254 } | 260 } |
255 } | 261 } |
256 | 262 |
| 263 @Override |
| 264 public URLConnection openConnection(URL url) { |
| 265 return openConnection(url, Proxy.NO_PROXY); |
| 266 } |
| 267 |
| 268 @Override |
| 269 public URLConnection openConnection(URL url, Proxy proxy) { |
| 270 if (proxy.type() != Proxy.Type.DIRECT) { |
| 271 throw new UnsupportedOperationException(); |
| 272 } |
| 273 String protocol = url.getProtocol(); |
| 274 if ("http".equals(protocol) || "https".equals(protocol)) { |
| 275 return new CronetHttpURLConnection(url, this); |
| 276 } |
| 277 throw new UnsupportedOperationException("Unexpected protocol:" + protoco
l); |
| 278 } |
| 279 |
| 280 @Override |
| 281 public URLStreamHandlerFactory createURLStreamHandlerFactory() { |
| 282 return new CronetURLStreamHandlerFactory(this); |
| 283 } |
| 284 |
257 /** | 285 /** |
258 * Mark request as started to prevent shutdown when there are active | 286 * Mark request as started to prevent shutdown when there are active |
259 * requests. | 287 * requests. |
260 */ | 288 */ |
261 void onRequestStarted(UrlRequest urlRequest) { | 289 void onRequestStarted(UrlRequest urlRequest) { |
262 mActiveRequestCount.incrementAndGet(); | 290 mActiveRequestCount.incrementAndGet(); |
263 } | 291 } |
264 | 292 |
265 /** | 293 /** |
266 * Mark request as completed to allow shutdown when there are no active | 294 * Mark request as completed to allow shutdown when there are no active |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 406 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
379 private native void nativeEnableNetworkQualityEstimator( | 407 private native void nativeEnableNetworkQualityEstimator( |
380 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp
onses); | 408 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp
onses); |
381 | 409 |
382 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 410 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
383 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); | 411 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); |
384 | 412 |
385 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 413 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
386 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); | 414 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); |
387 } | 415 } |
OLD | NEW |