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.ConditionVariable; | |
9 import android.os.Process; | 8 import android.os.Process; |
10 import android.util.Log; | 9 import android.util.Log; |
11 | 10 |
12 import org.chromium.base.CalledByNative; | 11 import org.chromium.base.CalledByNative; |
13 import org.chromium.base.JNINamespace; | 12 import org.chromium.base.JNINamespace; |
14 | 13 |
15 /** | 14 /** |
16 * Provides context for the native HTTP operations. | 15 * Provides context for the native HTTP operations. |
17 */ | 16 */ |
18 @JNINamespace("cronet") | 17 @JNINamespace("cronet") |
19 public class ChromiumUrlRequestContext { | 18 public class ChromiumUrlRequestContext { |
20 private static final int LOG_NONE = 3; // LOG(FATAL), no VLOG. | 19 private static final int LOG_NONE = 3; // LOG(FATAL), no VLOG. |
21 private static final int LOG_DEBUG = -1; // LOG(FATAL...INFO), VLOG(1) | 20 private static final int LOG_DEBUG = -1; // LOG(FATAL...INFO), VLOG(1) |
22 private static final int LOG_VERBOSE = -2; // LOG(FATAL...INFO), VLOG(2) | 21 private static final int LOG_VERBOSE = -2; // LOG(FATAL...INFO), VLOG(2) |
23 static final String LOG_TAG = "ChromiumNetwork"; | 22 static final String LOG_TAG = "ChromiumNetwork"; |
24 | 23 |
25 /** | 24 /** |
26 * Native adapter object, owned by ChromiumUrlRequestContext. | 25 * Native adapter object, owned by ChromiumUrlRequestContext. |
27 */ | 26 */ |
28 private long mChromiumUrlRequestContextAdapter; | 27 private long mChromiumUrlRequestContextAdapter; |
29 | 28 |
30 private final ConditionVariable mStarted = new ConditionVariable(); | |
31 | |
32 /** | 29 /** |
33 * Constructor. | 30 * Constructor. |
34 * | 31 * |
35 */ | 32 */ |
36 protected ChromiumUrlRequestContext(Context context, String userAgent, | 33 protected ChromiumUrlRequestContext(Context context, String userAgent, |
37 String config) { | 34 String config) { |
38 mChromiumUrlRequestContextAdapter = nativeCreateRequestContextAdapter( | 35 mChromiumUrlRequestContextAdapter = nativeCreateRequestContextAdapter( |
39 context, userAgent, getLoggingLevel(), config); | 36 context, userAgent, getLoggingLevel(), config); |
40 if (mChromiumUrlRequestContextAdapter == 0) | 37 if (mChromiumUrlRequestContextAdapter == 0) { |
41 throw new NullPointerException("Context Adapter creation failed"); | 38 throw new NullPointerException("Context Adapter creation failed"); |
42 | 39 } |
43 // TODO(mef): Revisit the need of block here. | |
44 mStarted.block(2000); | |
45 } | 40 } |
46 | 41 |
47 /** | 42 /** |
48 * Returns the version of this network stack formatted as N.N.N.N/X where | 43 * Returns the version of this network stack formatted as N.N.N.N/X where |
49 * N.N.N.N is the version of Chromium and X is the revision number. | 44 * N.N.N.N is the version of Chromium and X is the revision number. |
50 */ | 45 */ |
51 public static String getVersion() { | 46 public static String getVersion() { |
52 return Version.getVersion(); | 47 return Version.getVersion(); |
53 } | 48 } |
54 | 49 |
(...skipping 28 matching lines...) Expand all Loading... |
83 * not in progress this call is ignored. | 78 * not in progress this call is ignored. |
84 */ | 79 */ |
85 public void stopNetLog() { | 80 public void stopNetLog() { |
86 nativeStopNetLog(mChromiumUrlRequestContextAdapter); | 81 nativeStopNetLog(mChromiumUrlRequestContextAdapter); |
87 } | 82 } |
88 | 83 |
89 @CalledByNative | 84 @CalledByNative |
90 private void initNetworkThread() { | 85 private void initNetworkThread() { |
91 Thread.currentThread().setName("ChromiumNet"); | 86 Thread.currentThread().setName("ChromiumNet"); |
92 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); | 87 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
93 mStarted.open(); | |
94 } | 88 } |
95 | 89 |
96 @Override | 90 @Override |
97 protected void finalize() throws Throwable { | 91 protected void finalize() throws Throwable { |
98 nativeReleaseRequestContextAdapter(mChromiumUrlRequestContextAdapter); | 92 nativeReleaseRequestContextAdapter(mChromiumUrlRequestContextAdapter); |
99 super.finalize(); | 93 super.finalize(); |
100 } | 94 } |
101 | 95 |
102 protected long getChromiumUrlRequestContextAdapter() { | 96 protected long getChromiumUrlRequestContextAdapter() { |
103 return mChromiumUrlRequestContextAdapter; | 97 return mChromiumUrlRequestContextAdapter; |
(...skipping 25 matching lines...) Expand all Loading... |
129 | 123 |
130 private native void nativeInitializeStatistics(); | 124 private native void nativeInitializeStatistics(); |
131 | 125 |
132 private native String nativeGetStatisticsJSON(String filter); | 126 private native String nativeGetStatisticsJSON(String filter); |
133 | 127 |
134 private native void nativeStartNetLogToFile( | 128 private native void nativeStartNetLogToFile( |
135 long chromiumUrlRequestContextAdapter, String fileName); | 129 long chromiumUrlRequestContextAdapter, String fileName); |
136 | 130 |
137 private native void nativeStopNetLog(long chromiumUrlRequestContextAdapter); | 131 private native void nativeStopNetLog(long chromiumUrlRequestContextAdapter); |
138 } | 132 } |
OLD | NEW |