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

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

Issue 1926683003: [Cronet] Avoid crashing when CronetEngines are created on multiple threads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address mef comments Created 4 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; 5 package org.chromium.net;
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 @GuardedBy("mNetworkQualityLock") 70 @GuardedBy("mNetworkQualityLock")
71 private final ObserverList<NetworkQualityThroughputListener> mThroughputList enerList = 71 private final ObserverList<NetworkQualityThroughputListener> mThroughputList enerList =
72 new ObserverList<NetworkQualityThroughputListener>(); 72 new ObserverList<NetworkQualityThroughputListener>();
73 73
74 @GuardedBy("mNetworkQualityLock") 74 @GuardedBy("mNetworkQualityLock")
75 private final ObserverList<RequestFinishedListener> mFinishedListenerList = 75 private final ObserverList<RequestFinishedListener> mFinishedListenerList =
76 new ObserverList<RequestFinishedListener>(); 76 new ObserverList<RequestFinishedListener>();
77 77
78 @UsedByReflection("CronetEngine.java") 78 @UsedByReflection("CronetEngine.java")
79 public CronetUrlRequestContext(CronetEngine.Builder builder) { 79 public CronetUrlRequestContext(final CronetEngine.Builder builder) {
80 CronetLibraryLoader.ensureInitialized(builder.getContext(), builder); 80 CronetLibraryLoader.ensureInitialized(builder.getContext(), builder);
81 nativeSetMinLogLevel(getLoggingLevel()); 81 nativeSetMinLogLevel(getLoggingLevel());
82 synchronized (mLock) { 82 synchronized (mLock) {
83 mUrlRequestContextAdapter = nativeCreateRequestContextAdapter( 83 mUrlRequestContextAdapter = nativeCreateRequestContextAdapter(
84 createNativeUrlRequestContextConfig(builder.getContext(), bu ilder)); 84 createNativeUrlRequestContextConfig(builder.getContext(), bu ilder));
85 if (mUrlRequestContextAdapter == 0) { 85 if (mUrlRequestContextAdapter == 0) {
86 throw new NullPointerException("Context Adapter creation failed. "); 86 throw new NullPointerException("Context Adapter creation failed. ");
87 } 87 }
88 } 88 }
89 89
90 // Init native Chromium URLRequestContext on main UI thread. 90 // Init native Chromium URLRequestContext on main UI thread.
91 Runnable task = new Runnable() { 91 Runnable task = new Runnable() {
92 @Override 92 @Override
93 public void run() { 93 public void run() {
94 CronetLibraryLoader.ensureInitializedOnMainThread(builder.getCon text());
94 synchronized (mLock) { 95 synchronized (mLock) {
95 // mUrlRequestContextAdapter is guaranteed to exist until 96 // mUrlRequestContextAdapter is guaranteed to exist until
96 // initialization on main and network threads completes and 97 // initialization on main and network threads completes and
97 // initNetworkThread is called back on network thread. 98 // initNetworkThread is called back on network thread.
98 nativeInitRequestContextOnMainThread(mUrlRequestContextAdapt er); 99 nativeInitRequestContextOnMainThread(mUrlRequestContextAdapt er);
99 } 100 }
100 } 101 }
101 }; 102 };
102 // Run task immediately or post it to the UI thread. 103 // Run task immediately or post it to the UI thread.
103 if (Looper.getMainLooper() == Looper.myLooper()) { 104 if (Looper.getMainLooper() == Looper.myLooper()) {
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 506 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
506 private native void nativeEnableNetworkQualityEstimator( 507 private native void nativeEnableNetworkQualityEstimator(
507 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp onses); 508 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp onses);
508 509
509 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 510 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
510 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld); 511 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld);
511 512
512 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 513 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
513 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should); 514 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should);
514 } 515 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698