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

Side by Side Diff: components/cronet/android/java/src/org/chromium/net/impl/CronetUrlRequestContext.java

Issue 2876253002: [Cronet] Add ExperimentalCronetEngine.Builder.setThreadPriority() API (Closed)
Patch Set: shutdown CronetEngines in test Created 3 years, 7 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 package org.chromium.net.impl; 5 package org.chromium.net.impl;
6 6
7 import android.os.ConditionVariable; 7 import android.os.ConditionVariable;
8 import android.os.Process; 8 import android.os.Process;
9 9
10 import org.chromium.base.Log; 10 import org.chromium.base.Log;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 private long mUrlRequestContextAdapter = 0; 63 private long mUrlRequestContextAdapter = 0;
64 /** 64 /**
65 * This field is accessed without synchronization, but only for the purposes of reference 65 * This field is accessed without synchronization, but only for the purposes of reference
66 * equality comparison with other threads. If such a comparison is performed on the network 66 * equality comparison with other threads. If such a comparison is performed on the network
67 * thread, then there is a happens-before edge between the write of this fie ld and the 67 * thread, then there is a happens-before edge between the write of this fie ld and the
68 * subsequent read; if it's performed on another thread, then observing a va lue of null won't 68 * subsequent read; if it's performed on another thread, then observing a va lue of null won't
69 * change the result of the comparison. 69 * change the result of the comparison.
70 */ 70 */
71 private Thread mNetworkThread; 71 private Thread mNetworkThread;
72 72
73 private boolean mNetworkQualityEstimatorEnabled; 73 private final boolean mNetworkQualityEstimatorEnabled;
74 private final int mNetworkThreadPriority;
74 75
75 /** 76 /**
76 * Locks operations on network quality listeners, because listener 77 * Locks operations on network quality listeners, because listener
77 * addition and removal may occur on a different thread from notification. 78 * addition and removal may occur on a different thread from notification.
78 */ 79 */
79 private final Object mNetworkQualityLock = new Object(); 80 private final Object mNetworkQualityLock = new Object();
80 81
81 /** 82 /**
82 * Locks operations on the list of RequestFinishedInfo.Listeners, because op erations can happen 83 * Locks operations on the list of RequestFinishedInfo.Listeners, because op erations can happen
83 * on any thread. This should be used for fine-grained locking only. In part icular, don't call 84 * on any thread. This should be used for fine-grained locking only. In part icular, don't call
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 private volatile ConditionVariable mStopNetLogCompleted; 142 private volatile ConditionVariable mStopNetLogCompleted;
142 143
143 /** 144 /**
144 * True if a NetLog observer is active. 145 * True if a NetLog observer is active.
145 */ 146 */
146 @GuardedBy("mLock") 147 @GuardedBy("mLock")
147 private boolean mIsLogging; 148 private boolean mIsLogging;
148 149
149 @UsedByReflection("CronetEngine.java") 150 @UsedByReflection("CronetEngine.java")
150 public CronetUrlRequestContext(final CronetEngineBuilderImpl builder) { 151 public CronetUrlRequestContext(final CronetEngineBuilderImpl builder) {
152 mNetworkQualityEstimatorEnabled = builder.networkQualityEstimatorEnabled ();
153 mNetworkThreadPriority = builder.threadPriority(Process.THREAD_PRIORITY_ BACKGROUND);
151 CronetLibraryLoader.ensureInitialized(builder.getContext(), builder); 154 CronetLibraryLoader.ensureInitialized(builder.getContext(), builder);
152 nativeSetMinLogLevel(getLoggingLevel()); 155 nativeSetMinLogLevel(getLoggingLevel());
153 synchronized (mLock) { 156 synchronized (mLock) {
154 mUrlRequestContextAdapter = 157 mUrlRequestContextAdapter =
155 nativeCreateRequestContextAdapter(createNativeUrlRequestCont extConfig(builder)); 158 nativeCreateRequestContextAdapter(createNativeUrlRequestCont extConfig(builder));
156 if (mUrlRequestContextAdapter == 0) { 159 if (mUrlRequestContextAdapter == 0) {
157 throw new NullPointerException("Context Adapter creation failed. "); 160 throw new NullPointerException("Context Adapter creation failed. ");
158 } 161 }
159 mNetworkQualityEstimatorEnabled = builder.networkQualityEstimatorEna bled();
160 } 162 }
161 163
162 // Init native Chromium URLRequestContext on init thread. 164 // Init native Chromium URLRequestContext on init thread.
163 CronetLibraryLoader.postToInitThread(new Runnable() { 165 CronetLibraryLoader.postToInitThread(new Runnable() {
164 @Override 166 @Override
165 public void run() { 167 public void run() {
166 CronetLibraryLoader.ensureInitializedOnInitThread(builder.getCon text()); 168 CronetLibraryLoader.ensureInitializedOnInitThread(builder.getCon text());
167 synchronized (mLock) { 169 synchronized (mLock) {
168 // mUrlRequestContextAdapter is guaranteed to exist until 170 // mUrlRequestContextAdapter is guaranteed to exist until
169 // initialization on init and network threads completes and 171 // initialization on init and network threads completes and
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 "Internal Error: Illegal EffectiveConnectionType value " + type); 569 "Internal Error: Illegal EffectiveConnectionType value " + type);
568 } 570 }
569 } 571 }
570 572
571 @SuppressWarnings("unused") 573 @SuppressWarnings("unused")
572 @CalledByNative 574 @CalledByNative
573 private void initNetworkThread() { 575 private void initNetworkThread() {
574 mNetworkThread = Thread.currentThread(); 576 mNetworkThread = Thread.currentThread();
575 mInitCompleted.open(); 577 mInitCompleted.open();
576 Thread.currentThread().setName("ChromiumNet"); 578 Thread.currentThread().setName("ChromiumNet");
577 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); 579 Process.setThreadPriority(mNetworkThreadPriority);
578 } 580 }
579 581
580 @SuppressWarnings("unused") 582 @SuppressWarnings("unused")
581 @CalledByNative 583 @CalledByNative
582 private void onEffectiveConnectionTypeChanged(int effectiveConnectionType) { 584 private void onEffectiveConnectionTypeChanged(int effectiveConnectionType) {
583 synchronized (mNetworkQualityLock) { 585 synchronized (mNetworkQualityLock) {
584 // Convert the enum returned by the network quality estimator to an enum of type 586 // Convert the enum returned by the network quality estimator to an enum of type
585 // EffectiveConnectionType. 587 // EffectiveConnectionType.
586 mEffectiveConnectionType = effectiveConnectionType; 588 mEffectiveConnectionType = effectiveConnectionType;
587 } 589 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 714 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
713 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld); 715 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld);
714 716
715 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 717 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
716 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should); 718 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should);
717 719
718 public boolean isNetworkThread(Thread thread) { 720 public boolean isNetworkThread(Thread thread) {
719 return thread == mNetworkThread; 721 return thread == mNetworkThread;
720 } 722 }
721 } 723 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698