| 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; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 private final ConditionVariable mInitCompleted = new ConditionVariable(false
); | 36 private final ConditionVariable mInitCompleted = new ConditionVariable(false
); |
| 37 private final AtomicInteger mActiveRequestCount = new AtomicInteger(0); | 37 private final AtomicInteger mActiveRequestCount = new AtomicInteger(0); |
| 38 | 38 |
| 39 private long mUrlRequestContextAdapter = 0; | 39 private long mUrlRequestContextAdapter = 0; |
| 40 private Thread mNetworkThread; | 40 private Thread mNetworkThread; |
| 41 | 41 |
| 42 public CronetUrlRequestContext(Context context, | 42 public CronetUrlRequestContext(Context context, |
| 43 UrlRequestContextConfig config) { | 43 UrlRequestContextConfig config) { |
| 44 CronetLibraryLoader.ensureInitialized(context, config); | 44 CronetLibraryLoader.ensureInitialized(context, config); |
| 45 nativeSetMinLogLevel(getLoggingLevel()); | 45 nativeSetMinLogLevel(getLoggingLevel()); |
| 46 mUrlRequestContextAdapter = nativeCreateRequestContextAdapter( | 46 mUrlRequestContextAdapter = nativeCreateRequestContextAdapter(config.toS
tring()); |
| 47 context.getApplicationContext(), config.toString()); | |
| 48 if (mUrlRequestContextAdapter == 0) { | 47 if (mUrlRequestContextAdapter == 0) { |
| 49 throw new NullPointerException("Context Adapter creation failed."); | 48 throw new NullPointerException("Context Adapter creation failed."); |
| 50 } | 49 } |
| 51 | 50 |
| 52 // Init native Chromium URLRequestContext on main UI thread. | 51 // Init native Chromium URLRequestContext on main UI thread. |
| 53 Runnable task = new Runnable() { | 52 Runnable task = new Runnable() { |
| 54 @Override | 53 @Override |
| 55 public void run() { | 54 public void run() { |
| 56 synchronized (mLock) { | 55 synchronized (mLock) { |
| 57 // mUrlRequestContextAdapter is guaranteed to exist until | 56 // mUrlRequestContextAdapter is guaranteed to exist until |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 private void initNetworkThread() { | 187 private void initNetworkThread() { |
| 189 synchronized (mLock) { | 188 synchronized (mLock) { |
| 190 mNetworkThread = Thread.currentThread(); | 189 mNetworkThread = Thread.currentThread(); |
| 191 mInitCompleted.open(); | 190 mInitCompleted.open(); |
| 192 } | 191 } |
| 193 Thread.currentThread().setName("ChromiumNet"); | 192 Thread.currentThread().setName("ChromiumNet"); |
| 194 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); | 193 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| 195 } | 194 } |
| 196 | 195 |
| 197 // Native methods are implemented in cronet_url_request_context.cc. | 196 // Native methods are implemented in cronet_url_request_context.cc. |
| 198 private static native long nativeCreateRequestContextAdapter(Context appCont
ext, String config); | 197 private static native long nativeCreateRequestContextAdapter(String config); |
| 199 | 198 |
| 200 private static native int nativeSetMinLogLevel(int loggingLevel); | 199 private static native int nativeSetMinLogLevel(int loggingLevel); |
| 201 | 200 |
| 202 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 201 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 203 private native void nativeDestroy(long nativePtr); | 202 private native void nativeDestroy(long nativePtr); |
| 204 | 203 |
| 205 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 204 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 206 private native void nativeStartNetLogToFile(long nativePtr, | 205 private native void nativeStartNetLogToFile(long nativePtr, |
| 207 String fileName); | 206 String fileName); |
| 208 | 207 |
| 209 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 208 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 210 private native void nativeStopNetLog(long nativePtr); | 209 private native void nativeStopNetLog(long nativePtr); |
| 211 | 210 |
| 212 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 211 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 213 private native void nativeInitRequestContextOnMainThread(long nativePtr); | 212 private native void nativeInitRequestContextOnMainThread(long nativePtr); |
| 214 } | 213 } |
| OLD | NEW |