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.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; |
11 import android.os.Looper; | 11 import android.os.Looper; |
12 import android.os.Process; | 12 import android.os.Process; |
13 import android.util.Log; | 13 import android.util.Log; |
14 | 14 |
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 | 20 |
21 import java.util.concurrent.Executor; | 21 import java.util.concurrent.Executor; |
22 import java.util.concurrent.atomic.AtomicInteger; | 22 import java.util.concurrent.atomic.AtomicInteger; |
23 | 23 |
24 /** | 24 /** |
25 * UrlRequestContext using Chromium HTTP stack implementation. | 25 * CronetEngine using Chromium HTTP stack implementation. |
26 */ | 26 */ |
27 @JNINamespace("cronet") | 27 @JNINamespace("cronet") |
28 @UsedByReflection("UrlRequestContext.java") | 28 @UsedByReflection("CronetEngine.java") |
29 class CronetUrlRequestContext extends UrlRequestContext { | 29 class CronetUrlRequestContext extends CronetEngine { |
30 private static final int LOG_NONE = 3; // LOG(FATAL), no VLOG. | 30 private static final int LOG_NONE = 3; // LOG(FATAL), no VLOG. |
31 private static final int LOG_DEBUG = -1; // LOG(FATAL...INFO), VLOG(1) | 31 private static final int LOG_DEBUG = -1; // LOG(FATAL...INFO), VLOG(1) |
32 private static final int LOG_VERBOSE = -2; // LOG(FATAL...INFO), VLOG(2) | 32 private static final int LOG_VERBOSE = -2; // LOG(FATAL...INFO), VLOG(2) |
33 static final String LOG_TAG = "ChromiumNetwork"; | 33 static final String LOG_TAG = "ChromiumNetwork"; |
34 | 34 |
35 /** | 35 /** |
36 * Synchronize access to mUrlRequestContextAdapter and shutdown routine. | 36 * Synchronize access to mUrlRequestContextAdapter and shutdown routine. |
37 */ | 37 */ |
38 private final Object mLock = new Object(); | 38 private final Object mLock = new Object(); |
39 private final ConditionVariable mInitCompleted = new ConditionVariable(false
); | 39 private final ConditionVariable mInitCompleted = new ConditionVariable(false
); |
40 private final AtomicInteger mActiveRequestCount = new AtomicInteger(0); | 40 private final AtomicInteger mActiveRequestCount = new AtomicInteger(0); |
41 | 41 |
42 private long mUrlRequestContextAdapter = 0; | 42 private long mUrlRequestContextAdapter = 0; |
43 private Thread mNetworkThread; | 43 private Thread mNetworkThread; |
44 | 44 |
45 @UsedByReflection("UrlRequestContext.java") | 45 @UsedByReflection("CronetEngine.java") |
46 public CronetUrlRequestContext(Context context, | 46 public CronetUrlRequestContext(Context context, CronetEngine.Builder builder
) { |
47 UrlRequestContextConfig config) { | 47 CronetLibraryLoader.ensureInitialized(context, builder); |
48 CronetLibraryLoader.ensureInitialized(context, config); | |
49 nativeSetMinLogLevel(getLoggingLevel()); | 48 nativeSetMinLogLevel(getLoggingLevel()); |
50 mUrlRequestContextAdapter = nativeCreateRequestContextAdapter(config.toS
tring()); | 49 mUrlRequestContextAdapter = nativeCreateRequestContextAdapter(builder.to
String()); |
51 if (mUrlRequestContextAdapter == 0) { | 50 if (mUrlRequestContextAdapter == 0) { |
52 throw new NullPointerException("Context Adapter creation failed."); | 51 throw new NullPointerException("Context Adapter creation failed."); |
53 } | 52 } |
54 | 53 |
55 // Init native Chromium URLRequestContext on main UI thread. | 54 // Init native Chromium URLRequestContext on main UI thread. |
56 Runnable task = new Runnable() { | 55 Runnable task = new Runnable() { |
57 @Override | 56 @Override |
58 public void run() { | 57 public void run() { |
59 synchronized (mLock) { | 58 synchronized (mLock) { |
60 // mUrlRequestContextAdapter is guaranteed to exist until | 59 // mUrlRequestContextAdapter is guaranteed to exist until |
(...skipping 10 matching lines...) Expand all Loading... |
71 new Handler(Looper.getMainLooper()).post(task); | 70 new Handler(Looper.getMainLooper()).post(task); |
72 } | 71 } |
73 } | 72 } |
74 | 73 |
75 @Override | 74 @Override |
76 public UrlRequest createRequest(String url, UrlRequestListener listener, | 75 public UrlRequest createRequest(String url, UrlRequestListener listener, |
77 Executor executor) { | 76 Executor executor) { |
78 synchronized (mLock) { | 77 synchronized (mLock) { |
79 checkHaveAdapter(); | 78 checkHaveAdapter(); |
80 return new CronetUrlRequest(this, mUrlRequestContextAdapter, url, | 79 return new CronetUrlRequest(this, mUrlRequestContextAdapter, url, |
81 UrlRequest.REQUEST_PRIORITY_MEDIUM, listener, executor); | 80 UrlRequest.Builder.REQUEST_PRIORITY_MEDIUM, listener, execut
or); |
82 } | 81 } |
83 } | 82 } |
84 | 83 |
85 @Override | 84 @Override |
86 public UrlRequest createRequest(String url, UrlRequestListener listener, | 85 public UrlRequest createRequest(String url, UrlRequestListener listener, |
87 Executor executor, int priority) { | 86 Executor executor, int priority) { |
88 synchronized (mLock) { | 87 synchronized (mLock) { |
89 checkHaveAdapter(); | 88 checkHaveAdapter(); |
90 return new CronetUrlRequest(this, mUrlRequestContextAdapter, url, | 89 return new CronetUrlRequest(this, mUrlRequestContextAdapter, url, |
91 priority, listener, executor); | 90 priority, listener, executor); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 219 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
221 private native void nativeStartNetLogToFile(long nativePtr, | 220 private native void nativeStartNetLogToFile(long nativePtr, |
222 String fileName, boolean logAll); | 221 String fileName, boolean logAll); |
223 | 222 |
224 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 223 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
225 private native void nativeStopNetLog(long nativePtr); | 224 private native void nativeStopNetLog(long nativePtr); |
226 | 225 |
227 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 226 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
228 private native void nativeInitRequestContextOnMainThread(long nativePtr); | 227 private native void nativeInitRequestContextOnMainThread(long nativePtr); |
229 } | 228 } |
OLD | NEW |