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.impl; | 5 package org.chromium.net.impl; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.os.Build; | 8 import android.os.Build; |
9 import android.os.ConditionVariable; | 9 import android.os.ConditionVariable; |
10 import android.os.Handler; | 10 import android.os.Handler; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 static final String LOG_TAG = "ChromiumNetwork"; | 55 static final String LOG_TAG = "ChromiumNetwork"; |
56 | 56 |
57 /** | 57 /** |
58 * Synchronize access to mUrlRequestContextAdapter and shutdown routine. | 58 * Synchronize access to mUrlRequestContextAdapter and shutdown routine. |
59 */ | 59 */ |
60 private final Object mLock = new Object(); | 60 private final Object mLock = new Object(); |
61 private final ConditionVariable mInitCompleted = new ConditionVariable(false
); | 61 private final ConditionVariable mInitCompleted = new ConditionVariable(false
); |
62 private final AtomicInteger mActiveRequestCount = new AtomicInteger(0); | 62 private final AtomicInteger mActiveRequestCount = new AtomicInteger(0); |
63 | 63 |
64 private long mUrlRequestContextAdapter = 0; | 64 private long mUrlRequestContextAdapter = 0; |
65 private Thread mNetworkThread; | 65 private volatile Thread mNetworkThread; |
66 | 66 |
67 private boolean mNetworkQualityEstimatorEnabled; | 67 private boolean mNetworkQualityEstimatorEnabled; |
68 | 68 |
69 /** | 69 /** |
70 * Locks operations on network quality listeners, because listener | 70 * Locks operations on network quality listeners, because listener |
71 * addition and removal may occur on a different thread from notification. | 71 * addition and removal may occur on a different thread from notification. |
72 */ | 72 */ |
73 private final Object mNetworkQualityLock = new Object(); | 73 private final Object mNetworkQualityLock = new Object(); |
74 | 74 |
75 /** | 75 /** |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 for (Builder.Pkp pkp : builder.publicKeyPins()) { | 175 for (Builder.Pkp pkp : builder.publicKeyPins()) { |
176 nativeAddPkp(urlRequestContextConfig, pkp.mHost, pkp.mHashes, pkp.mI
ncludeSubdomains, | 176 nativeAddPkp(urlRequestContextConfig, pkp.mHost, pkp.mHashes, pkp.mI
ncludeSubdomains, |
177 pkp.mExpirationDate.getTime()); | 177 pkp.mExpirationDate.getTime()); |
178 } | 178 } |
179 return urlRequestContextConfig; | 179 return urlRequestContextConfig; |
180 } | 180 } |
181 | 181 |
182 @Override | 182 @Override |
183 public UrlRequest createRequest(String url, UrlRequest.Callback callback, Ex
ecutor executor, | 183 public UrlRequest createRequest(String url, UrlRequest.Callback callback, Ex
ecutor executor, |
184 int priority, Collection<Object> requestAnnotations, boolean disable
Cache, | 184 int priority, Collection<Object> requestAnnotations, boolean disable
Cache, |
185 boolean disableConnectionMigration) { | 185 boolean disableConnectionMigration, boolean allowDirectExecutor) { |
186 synchronized (mLock) { | 186 synchronized (mLock) { |
187 checkHaveAdapter(); | 187 checkHaveAdapter(); |
188 boolean metricsCollectionEnabled = false; | 188 boolean metricsCollectionEnabled = false; |
189 synchronized (mFinishedListenerLock) { | 189 synchronized (mFinishedListenerLock) { |
190 metricsCollectionEnabled = !mFinishedListenerList.isEmpty(); | 190 metricsCollectionEnabled = !mFinishedListenerList.isEmpty(); |
191 } | 191 } |
192 return new CronetUrlRequest(this, url, priority, callback, executor,
requestAnnotations, | 192 return new CronetUrlRequest(this, url, priority, callback, executor,
requestAnnotations, |
193 metricsCollectionEnabled, disableCache, disableConnectionMig
ration); | 193 metricsCollectionEnabled, disableCache, disableConnectionMig
ration, |
| 194 allowDirectExecutor); |
194 } | 195 } |
195 } | 196 } |
196 | 197 |
197 @Override | 198 @Override |
198 public BidirectionalStream createBidirectionalStream(String url, | 199 public BidirectionalStream createBidirectionalStream(String url, |
199 BidirectionalStream.Callback callback, Executor executor, String htt
pMethod, | 200 BidirectionalStream.Callback callback, Executor executor, String htt
pMethod, |
200 List<Map.Entry<String, String>> requestHeaders, | 201 List<Map.Entry<String, String>> requestHeaders, |
201 @BidirectionalStream.Builder.StreamPriority int priority, | 202 @BidirectionalStream.Builder.StreamPriority int priority, |
202 boolean delayRequestHeadersUntilFirstFlush) { | 203 boolean delayRequestHeadersUntilFirstFlush) { |
203 synchronized (mLock) { | 204 synchronized (mLock) { |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 loggingLevel = LOG_DEBUG; | 486 loggingLevel = LOG_DEBUG; |
486 } else { | 487 } else { |
487 loggingLevel = LOG_NONE; | 488 loggingLevel = LOG_NONE; |
488 } | 489 } |
489 return loggingLevel; | 490 return loggingLevel; |
490 } | 491 } |
491 | 492 |
492 @SuppressWarnings("unused") | 493 @SuppressWarnings("unused") |
493 @CalledByNative | 494 @CalledByNative |
494 private void initNetworkThread() { | 495 private void initNetworkThread() { |
495 synchronized (mLock) { | 496 mNetworkThread = Thread.currentThread(); |
496 mNetworkThread = Thread.currentThread(); | 497 mInitCompleted.open(); |
497 mInitCompleted.open(); | |
498 } | |
499 Thread.currentThread().setName("ChromiumNet"); | 498 Thread.currentThread().setName("ChromiumNet"); |
500 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); | 499 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
501 } | 500 } |
502 | 501 |
503 @SuppressWarnings("unused") | 502 @SuppressWarnings("unused") |
504 @CalledByNative | 503 @CalledByNative |
505 private void onEffectiveConnectionTypeChanged(int effectiveConnectionType) { | 504 private void onEffectiveConnectionTypeChanged(int effectiveConnectionType) { |
506 synchronized (mNetworkQualityLock) { | 505 synchronized (mNetworkQualityLock) { |
507 // Convert the enum returned by the network quality estimator to an
enum of type | 506 // Convert the enum returned by the network quality estimator to an
enum of type |
508 // EffectiveConnectionType. | 507 // EffectiveConnectionType. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 | 618 |
620 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 619 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
621 private native void nativeConfigureNetworkQualityEstimatorForTesting( | 620 private native void nativeConfigureNetworkQualityEstimatorForTesting( |
622 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp
onses); | 621 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp
onses); |
623 | 622 |
624 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 623 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
625 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); | 624 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); |
626 | 625 |
627 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 626 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
628 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); | 627 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); |
| 628 |
| 629 public boolean isNetworkThread(Thread thread) { |
| 630 return thread == mNetworkThread; |
| 631 } |
629 } | 632 } |
OLD | NEW |