| 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.Handler; | 8 import android.os.Handler; | 
| 9 import android.os.Looper; | 9 import android.os.Looper; | 
| 10 import android.os.Process; | 10 import android.os.Process; | 
| 11 import android.util.Log; | 11 import android.util.Log; | 
| 12 | 12 | 
| 13 import org.chromium.base.annotations.CalledByNative; | 13 import org.chromium.base.annotations.CalledByNative; | 
| 14 import org.chromium.base.annotations.JNINamespace; | 14 import org.chromium.base.annotations.JNINamespace; | 
| 15 | 15 | 
| 16 /** | 16 /** | 
| 17  * Provides context for the native HTTP operations. | 17  * Provides context for the native HTTP operations. | 
| 18  * @deprecated Use {@link CronetEngine} instead. | 18  * @deprecated Use {@link CronetEngine} instead. | 
| 19  */ | 19  */ | 
| 20 @JNINamespace("cronet") | 20 @JNINamespace("cronet") | 
| 21 @Deprecated | 21 @Deprecated | 
| 22 public class ChromiumUrlRequestContext { | 22 public class ChromiumUrlRequestContext { | 
| 23     private static final int LOG_NONE = 3;  // LOG(FATAL), no VLOG. | 23     private static final int LOG_NONE = 3;  // LOG(FATAL), no VLOG. | 
| 24     private static final int LOG_DEBUG = -1;  // LOG(FATAL...INFO), VLOG(1) | 24     private static final int LOG_DEBUG = -1;  // LOG(FATAL...INFO), VLOG(1) | 
| 25     private static final int LOG_VERBOSE = -2;  // LOG(FATAL...INFO), VLOG(2) | 25     private static final int LOG_VERBOSE = -2;  // LOG(FATAL...INFO), VLOG(2) | 
| 26     static final String LOG_TAG = "ChromiumNetwork"; | 26     static final String LOG_TAG = "ChromiumNetwork"; | 
| 27 | 27 | 
|  | 28     // For Testing. | 
|  | 29     private static long sNativeMockCertVerifier = 0; | 
|  | 30 | 
| 28     /** | 31     /** | 
| 29      * Native adapter object, owned by ChromiumUrlRequestContext. | 32      * Native adapter object, owned by ChromiumUrlRequestContext. | 
| 30      */ | 33      */ | 
| 31     private long mChromiumUrlRequestContextAdapter; | 34     private long mChromiumUrlRequestContextAdapter; | 
| 32 | 35 | 
| 33     /** | 36     /** | 
| 34      * Constructor. | 37      * Constructor. | 
| 35      */ | 38      */ | 
| 36     protected ChromiumUrlRequestContext( | 39     protected ChromiumUrlRequestContext( | 
| 37             final Context context, String userAgent, CronetEngine.Builder config
     ) { | 40             final Context context, String userAgent, CronetEngine.Builder config
     ) { | 
| 38         CronetLibraryLoader.ensureInitialized(context, config); | 41         CronetLibraryLoader.ensureInitialized(context, config); | 
| 39         mChromiumUrlRequestContextAdapter = | 42         mChromiumUrlRequestContextAdapter = | 
| 40                 nativeCreateRequestContextAdapter(userAgent, getLoggingLevel(), 
     config.toString()); | 43                 nativeCreateRequestContextAdapter(userAgent, getLoggingLevel(), 
     config.toString()); | 
| 41         if (mChromiumUrlRequestContextAdapter == 0) { | 44         if (mChromiumUrlRequestContextAdapter == 0) { | 
| 42             throw new NullPointerException("Context Adapter creation failed"); | 45             throw new NullPointerException("Context Adapter creation failed"); | 
| 43         } | 46         } | 
|  | 47 | 
|  | 48         if (sNativeMockCertVerifier != 0) { | 
|  | 49             nativeSetMockCertVerifierForTesting( | 
|  | 50                     mChromiumUrlRequestContextAdapter, sNativeMockCertVerifier); | 
|  | 51         } | 
|  | 52 | 
| 44         // Post a task to UI thread to init native Chromium URLRequestContext. | 53         // Post a task to UI thread to init native Chromium URLRequestContext. | 
| 45         // TODO(xunjieli): This constructor is not supposed to be invoked on | 54         // TODO(xunjieli): This constructor is not supposed to be invoked on | 
| 46         // the main thread. Consider making the following code into a blocking | 55         // the main thread. Consider making the following code into a blocking | 
| 47         // API to handle the case where we are already on main thread. | 56         // API to handle the case where we are already on main thread. | 
| 48         Runnable task = new Runnable() { | 57         Runnable task = new Runnable() { | 
| 49             public void run() { | 58             public void run() { | 
| 50                 nativeInitRequestContextOnMainThread( | 59                 nativeInitRequestContextOnMainThread( | 
| 51                         mChromiumUrlRequestContextAdapter); | 60                         mChromiumUrlRequestContextAdapter); | 
| 52             } | 61             } | 
| 53         }; | 62         }; | 
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 130         if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { | 139         if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { | 
| 131             loggingLevel = LOG_VERBOSE; | 140             loggingLevel = LOG_VERBOSE; | 
| 132         } else if (Log.isLoggable(LOG_TAG, Log.DEBUG)) { | 141         } else if (Log.isLoggable(LOG_TAG, Log.DEBUG)) { | 
| 133             loggingLevel = LOG_DEBUG; | 142             loggingLevel = LOG_DEBUG; | 
| 134         } else { | 143         } else { | 
| 135             loggingLevel = LOG_NONE; | 144             loggingLevel = LOG_NONE; | 
| 136         } | 145         } | 
| 137         return loggingLevel; | 146         return loggingLevel; | 
| 138     } | 147     } | 
| 139 | 148 | 
|  | 149     /** | 
|  | 150      * Sets a mock cert verifier for testing. | 
|  | 151      * @param nativeMockCertVerifier a pointer to the native net::MockCertVerifi
     er. | 
|  | 152      */ | 
|  | 153     static void setMockCertVerifierForTesting(long nativeMockCertVerifier) { | 
|  | 154         sNativeMockCertVerifier = nativeMockCertVerifier; | 
|  | 155     } | 
|  | 156 | 
| 140     // Returns an instance ChromiumUrlRequestContextAdapter to be stored in | 157     // Returns an instance ChromiumUrlRequestContextAdapter to be stored in | 
| 141     // mChromiumUrlRequestContextAdapter. | 158     // mChromiumUrlRequestContextAdapter. | 
| 142     private native long nativeCreateRequestContextAdapter( | 159     private native long nativeCreateRequestContextAdapter( | 
| 143             String userAgent, int loggingLevel, String config); | 160             String userAgent, int loggingLevel, String config); | 
| 144 | 161 | 
|  | 162     private native void nativeSetMockCertVerifierForTesting( | 
|  | 163             long chromiumUrlRequestContextAdapter, long mockCertVerifier); | 
|  | 164 | 
| 145     private native void nativeReleaseRequestContextAdapter( | 165     private native void nativeReleaseRequestContextAdapter( | 
| 146             long chromiumUrlRequestContextAdapter); | 166             long chromiumUrlRequestContextAdapter); | 
| 147 | 167 | 
| 148     private native void nativeInitializeStatistics(); | 168     private native void nativeInitializeStatistics(); | 
| 149 | 169 | 
| 150     private native String nativeGetStatisticsJSON(String filter); | 170     private native String nativeGetStatisticsJSON(String filter); | 
| 151 | 171 | 
| 152     private native void nativeStartNetLogToFile( | 172     private native void nativeStartNetLogToFile( | 
| 153             long chromiumUrlRequestContextAdapter, String fileName, | 173             long chromiumUrlRequestContextAdapter, String fileName, | 
| 154             boolean logAll); | 174             boolean logAll); | 
| 155 | 175 | 
| 156     private native void nativeStopNetLog(long chromiumUrlRequestContextAdapter); | 176     private native void nativeStopNetLog(long chromiumUrlRequestContextAdapter); | 
| 157 | 177 | 
| 158     private native void nativeInitRequestContextOnMainThread( | 178     private native void nativeInitRequestContextOnMainThread( | 
| 159             long chromiumUrlRequestContextAdapter); | 179             long chromiumUrlRequestContextAdapter); | 
| 160 } | 180 } | 
| OLD | NEW | 
|---|