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.CalledByNative; | 13 import org.chromium.base.CalledByNative; |
14 import org.chromium.base.JNINamespace; | 14 import org.chromium.base.JNINamespace; |
15 import org.chromium.base.VisibleForTesting; | |
16 | 15 |
17 /** | 16 /** |
18 * Provides context for the native HTTP operations. | 17 * Provides context for the native HTTP operations. |
19 */ | 18 */ |
20 @JNINamespace("cronet") | 19 @JNINamespace("cronet") |
21 public class ChromiumUrlRequestContext { | 20 public class ChromiumUrlRequestContext { |
22 private static final int LOG_NONE = 3; // LOG(FATAL), no VLOG. | 21 private static final int LOG_NONE = 3; // LOG(FATAL), no VLOG. |
23 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) |
24 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) |
25 static final String LOG_TAG = "ChromiumNetwork"; | 24 static final String LOG_TAG = "ChromiumNetwork"; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 94 } |
96 | 95 |
97 /** | 96 /** |
98 * Stops NetLog logging and flushes file to disk. If a logging session is | 97 * Stops NetLog logging and flushes file to disk. If a logging session is |
99 * not in progress, this call is ignored. | 98 * not in progress, this call is ignored. |
100 */ | 99 */ |
101 public void stopNetLog() { | 100 public void stopNetLog() { |
102 nativeStopNetLog(mChromiumUrlRequestContextAdapter); | 101 nativeStopNetLog(mChromiumUrlRequestContextAdapter); |
103 } | 102 } |
104 | 103 |
105 /** | |
106 * Returns the native URLRequestContextAdapter pointer. | |
107 * Currently this method is only used in testing. | |
108 */ | |
109 @VisibleForTesting | |
110 long getUrlRequestContextAdapterForTesting() { | |
111 return mChromiumUrlRequestContextAdapter; | |
112 } | |
113 | |
114 @CalledByNative | 104 @CalledByNative |
115 private void initNetworkThread() { | 105 private void initNetworkThread() { |
116 Thread.currentThread().setName("ChromiumNet"); | 106 Thread.currentThread().setName("ChromiumNet"); |
117 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); | 107 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
118 } | 108 } |
119 | 109 |
120 @Override | 110 @Override |
121 protected void finalize() throws Throwable { | 111 protected void finalize() throws Throwable { |
122 nativeReleaseRequestContextAdapter(mChromiumUrlRequestContextAdapter); | 112 nativeReleaseRequestContextAdapter(mChromiumUrlRequestContextAdapter); |
123 super.finalize(); | 113 super.finalize(); |
124 } | 114 } |
125 | 115 |
126 protected long getChromiumUrlRequestContextAdapter() { | 116 protected long getUrlRequestContextAdapter() { |
127 return mChromiumUrlRequestContextAdapter; | 117 return mChromiumUrlRequestContextAdapter; |
128 } | 118 } |
129 | 119 |
130 /** | 120 /** |
131 * @return loggingLevel see {@link #LOG_NONE}, {@link #LOG_DEBUG} and | 121 * @return loggingLevel see {@link #LOG_NONE}, {@link #LOG_DEBUG} and |
132 * {@link #LOG_VERBOSE}. | 122 * {@link #LOG_VERBOSE}. |
133 */ | 123 */ |
134 private int getLoggingLevel() { | 124 private int getLoggingLevel() { |
135 int loggingLevel; | 125 int loggingLevel; |
136 if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { | 126 if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { |
(...skipping 20 matching lines...) Expand all Loading... |
157 | 147 |
158 private native void nativeStartNetLogToFile( | 148 private native void nativeStartNetLogToFile( |
159 long chromiumUrlRequestContextAdapter, String fileName, | 149 long chromiumUrlRequestContextAdapter, String fileName, |
160 boolean logAll); | 150 boolean logAll); |
161 | 151 |
162 private native void nativeStopNetLog(long chromiumUrlRequestContextAdapter); | 152 private native void nativeStopNetLog(long chromiumUrlRequestContextAdapter); |
163 | 153 |
164 private native void nativeInitRequestContextOnMainThread( | 154 private native void nativeInitRequestContextOnMainThread( |
165 long chromiumUrlRequestContextAdapter); | 155 long chromiumUrlRequestContextAdapter); |
166 } | 156 } |
OLD | NEW |