Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: components/cronet/android/java/src/org/chromium/net/ChromiumUrlRequestContext.java

Issue 1849753002: [Cronet] Separate Cronet implementation and API by package name. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.net;
6
7 import android.content.Context;
8 import android.os.Handler;
9 import android.os.Looper;
10 import android.os.Process;
11 import android.util.Log;
12
13 import org.chromium.base.annotations.CalledByNative;
14 import org.chromium.base.annotations.JNINamespace;
15
16 /**
17 * Provides context for the native HTTP operations.
18 * @deprecated Use {@link CronetEngine} instead.
19 */
20 @JNINamespace("cronet")
21 @Deprecated
22 public class ChromiumUrlRequestContext {
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)
25 private static final int LOG_VERBOSE = -2; // LOG(FATAL...INFO), VLOG(2)
26 static final String LOG_TAG = "ChromiumNetwork";
27
28 /**
29 * Native adapter object, owned by ChromiumUrlRequestContext.
30 */
31 private long mChromiumUrlRequestContextAdapter;
32
33 /**
34 * Constructor.
35 */
36 protected ChromiumUrlRequestContext(
37 final Context context, String userAgent, CronetEngine.Builder config ) {
38 CronetLibraryLoader.ensureInitialized(context, config);
39 mChromiumUrlRequestContextAdapter = nativeCreateRequestContextAdapter(us erAgent,
40 getLoggingLevel(),
41 CronetUrlRequestContext.createNativeUrlRequestContextConfig(cont ext, config));
42 if (mChromiumUrlRequestContextAdapter == 0) {
43 throw new NullPointerException("Context Adapter creation failed");
44 }
45 // Post a task to UI thread to init native Chromium URLRequestContext.
46 // TODO(xunjieli): This constructor is not supposed to be invoked on
47 // the main thread. Consider making the following code into a blocking
48 // API to handle the case where we are already on main thread.
49 Runnable task = new Runnable() {
50 public void run() {
51 nativeInitRequestContextOnMainThread(
52 mChromiumUrlRequestContextAdapter);
53 }
54 };
55 new Handler(Looper.getMainLooper()).post(task);
56 }
57
58 /**
59 * Returns the version of this network stack formatted as N.N.N.N/X where
60 * N.N.N.N is the version of Chromium and X is the revision number.
61 */
62 public static String getVersion() {
63 return Version.getVersion();
64 }
65
66 /**
67 * Initializes statistics recorder.
68 */
69 public void initializeStatistics() {
70 nativeInitializeStatistics();
71 }
72
73 /**
74 * Gets current statistics recorded since |initializeStatistics| with
75 * |filter| as a substring as JSON text (an empty |filter| will include all
76 * registered histograms).
77 */
78 public String getStatisticsJSON(String filter) {
79 return nativeGetStatisticsJSON(filter);
80 }
81
82 /**
83 * Starts NetLog logging to a file. The NetLog capture mode is either
84 * NetLogCaptureMode::Default() or NetLogCaptureMode::IncludeSocketBytes().
85 * The IncludeSocketBytes() mode includes basic events, user cookies,
86 * credentials and all transferred bytes in the log.
87 * @param fileName The complete file path. It must not be empty. If file
88 * exists, it is truncated before starting. If actively logging,
89 * this method is ignored.
90 * @param logAll {@code true} to use the
91 * NetLogCaptureMode::IncludeSocketBytes() logging level. If
92 * false, NetLogCaptureMode::Default() is used instead.
93 */
94 public void startNetLogToFile(String fileName, boolean logAll) {
95 nativeStartNetLogToFile(mChromiumUrlRequestContextAdapter, fileName,
96 logAll);
97 }
98
99 /**
100 * Stops NetLog logging and flushes file to disk. If a logging session is
101 * not in progress, this call is ignored.
102 */
103 public void stopNetLog() {
104 nativeStopNetLog(mChromiumUrlRequestContextAdapter);
105 }
106
107 @CalledByNative
108 private void initNetworkThread() {
109 Thread.currentThread().setName("ChromiumNet");
110 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
111 }
112
113 @Override
114 protected void finalize() throws Throwable {
115 if (mChromiumUrlRequestContextAdapter != 0) {
116 nativeReleaseRequestContextAdapter(mChromiumUrlRequestContextAdapter );
117 }
118 super.finalize();
119 }
120
121 protected long getUrlRequestContextAdapter() {
122 return mChromiumUrlRequestContextAdapter;
123 }
124
125 /**
126 * @return loggingLevel see {@link #LOG_NONE}, {@link #LOG_DEBUG} and
127 * {@link #LOG_VERBOSE}.
128 */
129 private int getLoggingLevel() {
130 int loggingLevel;
131 if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
132 loggingLevel = LOG_VERBOSE;
133 } else if (Log.isLoggable(LOG_TAG, Log.DEBUG)) {
134 loggingLevel = LOG_DEBUG;
135 } else {
136 loggingLevel = LOG_NONE;
137 }
138 return loggingLevel;
139 }
140
141 // Returns an instance ChromiumUrlRequestContextAdapter to be stored in
142 // mChromiumUrlRequestContextAdapter.
143 private native long nativeCreateRequestContextAdapter(
144 String userAgent, int loggingLevel, long config);
145
146 private native void nativeReleaseRequestContextAdapter(
147 long chromiumUrlRequestContextAdapter);
148
149 private native void nativeInitializeStatistics();
150
151 private native String nativeGetStatisticsJSON(String filter);
152
153 private native void nativeStartNetLogToFile(
154 long chromiumUrlRequestContextAdapter, String fileName,
155 boolean logAll);
156
157 private native void nativeStopNetLog(long chromiumUrlRequestContextAdapter);
158
159 private native void nativeInitRequestContextOnMainThread(
160 long chromiumUrlRequestContextAdapter);
161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698