| 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; |
| 9 import android.os.Looper; |
| 8 import android.os.Process; | 10 import android.os.Process; |
| 9 import android.util.Log; | 11 import android.util.Log; |
| 10 | 12 |
| 11 import org.chromium.base.CalledByNative; | 13 import org.chromium.base.CalledByNative; |
| 12 import org.chromium.base.JNINamespace; | 14 import org.chromium.base.JNINamespace; |
| 13 | 15 |
| 14 /** | 16 /** |
| 15 * Provides context for the native HTTP operations. | 17 * Provides context for the native HTTP operations. |
| 16 */ | 18 */ |
| 17 @JNINamespace("cronet") | 19 @JNINamespace("cronet") |
| 18 public class ChromiumUrlRequestContext { | 20 public class ChromiumUrlRequestContext { |
| 19 private static final int LOG_NONE = 3; // LOG(FATAL), no VLOG. | 21 private static final int LOG_NONE = 3; // LOG(FATAL), no VLOG. |
| 20 private static final int LOG_DEBUG = -1; // LOG(FATAL...INFO), VLOG(1) | 22 private static final int LOG_DEBUG = -1; // LOG(FATAL...INFO), VLOG(1) |
| 21 private static final int LOG_VERBOSE = -2; // LOG(FATAL...INFO), VLOG(2) | 23 private static final int LOG_VERBOSE = -2; // LOG(FATAL...INFO), VLOG(2) |
| 22 static final String LOG_TAG = "ChromiumNetwork"; | 24 static final String LOG_TAG = "ChromiumNetwork"; |
| 23 | 25 |
| 24 /** | 26 /** |
| 25 * Native adapter object, owned by ChromiumUrlRequestContext. | 27 * Native adapter object, owned by ChromiumUrlRequestContext. |
| 26 */ | 28 */ |
| 27 private long mChromiumUrlRequestContextAdapter; | 29 private long mChromiumUrlRequestContextAdapter; |
| 28 | 30 |
| 29 /** | 31 /** |
| 30 * Constructor. | 32 * Constructor. |
| 31 * | |
| 32 */ | 33 */ |
| 33 protected ChromiumUrlRequestContext(Context context, String userAgent, | 34 protected ChromiumUrlRequestContext(Context context, String userAgent, |
| 34 String config) { | 35 String config) { |
| 35 mChromiumUrlRequestContextAdapter = nativeCreateRequestContextAdapter( | 36 mChromiumUrlRequestContextAdapter = nativeCreateRequestContextAdapter( |
| 36 context, userAgent, getLoggingLevel(), config); | 37 context, userAgent, getLoggingLevel(), config); |
| 37 if (mChromiumUrlRequestContextAdapter == 0) { | 38 if (mChromiumUrlRequestContextAdapter == 0) { |
| 38 throw new NullPointerException("Context Adapter creation failed"); | 39 throw new NullPointerException("Context Adapter creation failed"); |
| 39 } | 40 } |
| 41 // Post a task to UI thread to init native Chromium URLRequestContext. |
| 42 // TODO(xunjieli): This constructor is not supposed to be invoked on |
| 43 // the main thread. Consider making the following code into a blocking |
| 44 // API to handle the case where we are already on main thread. |
| 45 Runnable task = new Runnable() { |
| 46 public void run() { |
| 47 nativeInitRequestContextOnMainThread( |
| 48 mChromiumUrlRequestContextAdapter); |
| 49 } |
| 50 }; |
| 51 new Handler(Looper.getMainLooper()).post(task); |
| 40 } | 52 } |
| 41 | 53 |
| 42 /** | 54 /** |
| 43 * Returns the version of this network stack formatted as N.N.N.N/X where | 55 * Returns the version of this network stack formatted as N.N.N.N/X where |
| 44 * N.N.N.N is the version of Chromium and X is the revision number. | 56 * N.N.N.N is the version of Chromium and X is the revision number. |
| 45 */ | 57 */ |
| 46 public static String getVersion() { | 58 public static String getVersion() { |
| 47 return Version.getVersion(); | 59 return Version.getVersion(); |
| 48 } | 60 } |
| 49 | 61 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 long chromiumUrlRequestContextAdapter); | 134 long chromiumUrlRequestContextAdapter); |
| 123 | 135 |
| 124 private native void nativeInitializeStatistics(); | 136 private native void nativeInitializeStatistics(); |
| 125 | 137 |
| 126 private native String nativeGetStatisticsJSON(String filter); | 138 private native String nativeGetStatisticsJSON(String filter); |
| 127 | 139 |
| 128 private native void nativeStartNetLogToFile( | 140 private native void nativeStartNetLogToFile( |
| 129 long chromiumUrlRequestContextAdapter, String fileName); | 141 long chromiumUrlRequestContextAdapter, String fileName); |
| 130 | 142 |
| 131 private native void nativeStopNetLog(long chromiumUrlRequestContextAdapter); | 143 private native void nativeStopNetLog(long chromiumUrlRequestContextAdapter); |
| 144 |
| 145 private native void nativeInitRequestContextOnMainThread( |
| 146 long chromiumUrlRequestContextAdapter); |
| 132 } | 147 } |
| OLD | NEW |