| 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.CalledByNative; | 15 import org.chromium.base.CalledByNative; |
| 16 import org.chromium.base.JNINamespace; | 16 import org.chromium.base.JNINamespace; |
| 17 import org.chromium.base.NativeClassQualifiedName; |
| 17 | 18 |
| 18 import java.util.concurrent.Executor; | 19 import java.util.concurrent.Executor; |
| 19 import java.util.concurrent.atomic.AtomicInteger; | 20 import java.util.concurrent.atomic.AtomicInteger; |
| 20 | 21 |
| 21 /** | 22 /** |
| 22 * UrlRequest context using Chromium HTTP stack implementation. | 23 * UrlRequest context using Chromium HTTP stack implementation. |
| 23 */ | 24 */ |
| 24 @JNINamespace("cronet") | 25 @JNINamespace("cronet") |
| 25 public class CronetUrlRequestContext extends UrlRequestContext { | 26 public class CronetUrlRequestContext extends UrlRequestContext { |
| 26 private static final int LOG_NONE = 3; // LOG(FATAL), no VLOG. | 27 private static final int LOG_NONE = 3; // LOG(FATAL), no VLOG. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 106 } |
| 106 // Wait for init to complete on main and network thread (without lock, | 107 // Wait for init to complete on main and network thread (without lock, |
| 107 // so other thread could access it). | 108 // so other thread could access it). |
| 108 mInitCompleted.block(); | 109 mInitCompleted.block(); |
| 109 | 110 |
| 110 synchronized (mLock) { | 111 synchronized (mLock) { |
| 111 // It is possible that adapter is already destroyed on another threa
d. | 112 // It is possible that adapter is already destroyed on another threa
d. |
| 112 if (!haveRequestContextAdapter()) { | 113 if (!haveRequestContextAdapter()) { |
| 113 return; | 114 return; |
| 114 } | 115 } |
| 115 nativeDestroyRequestContextAdapter(mUrlRequestContextAdapter); | 116 nativeDestroy(mUrlRequestContextAdapter); |
| 116 mUrlRequestContextAdapter = 0; | 117 mUrlRequestContextAdapter = 0; |
| 117 } | 118 } |
| 118 } | 119 } |
| 119 | 120 |
| 120 @Override | 121 @Override |
| 121 public void startNetLogToFile(String fileName) { | 122 public void startNetLogToFile(String fileName) { |
| 122 synchronized (mLock) { | 123 synchronized (mLock) { |
| 123 checkHaveAdapter(); | 124 checkHaveAdapter(); |
| 124 nativeStartNetLogToFile(mUrlRequestContextAdapter, fileName); | 125 nativeStartNetLogToFile(mUrlRequestContextAdapter, fileName); |
| 125 } | 126 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 private void initNetworkThread() { | 188 private void initNetworkThread() { |
| 188 synchronized (mLock) { | 189 synchronized (mLock) { |
| 189 mNetworkThread = Thread.currentThread(); | 190 mNetworkThread = Thread.currentThread(); |
| 190 mInitCompleted.open(); | 191 mInitCompleted.open(); |
| 191 } | 192 } |
| 192 Thread.currentThread().setName("ChromiumNet"); | 193 Thread.currentThread().setName("ChromiumNet"); |
| 193 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); | 194 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| 194 } | 195 } |
| 195 | 196 |
| 196 // Native methods are implemented in cronet_url_request_context.cc. | 197 // Native methods are implemented in cronet_url_request_context.cc. |
| 197 private native long nativeCreateRequestContextAdapter(Context context, | 198 private static native long nativeCreateRequestContextAdapter( |
| 198 String config); | 199 Context context, String config); |
| 199 | 200 |
| 200 private native void nativeDestroyRequestContextAdapter( | 201 private static native int nativeSetMinLogLevel(int loggingLevel); |
| 201 long urlRequestContextAdapter); | |
| 202 | 202 |
| 203 private native void nativeStartNetLogToFile( | 203 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 204 long urlRequestContextAdapter, String fileName); | 204 private native void nativeDestroy(long nativePtr); |
| 205 | 205 |
| 206 private native void nativeStopNetLog(long urlRequestContextAdapter); | 206 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 207 private native void nativeStartNetLogToFile(long nativePtr, |
| 208 String fileName); |
| 207 | 209 |
| 208 private native int nativeSetMinLogLevel(int loggingLevel); | 210 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 211 private native void nativeStopNetLog(long nativePtr); |
| 209 | 212 |
| 210 private native void nativeInitRequestContextOnMainThread( | 213 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 211 long urlRequestContextAdapter); | 214 private native void nativeInitRequestContextOnMainThread(long nativePtr); |
| 212 } | 215 } |
| OLD | NEW |