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

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

Issue 586143002: Initial implementation of Cronet Async API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Matt's comments. Created 6 years, 2 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.Build;
9 import android.os.Process;
10 import android.util.Log;
11
12 import org.chromium.base.CalledByNative;
13 import org.chromium.base.JNINamespace;
14
15 import java.util.concurrent.Executor;
16
17 /**
18 * UrlRequest factory using Chromium HTTP stack implementation.
19 */
20 @JNINamespace("cronet")
21 public class CronetUrlRequestContext extends UrlRequestFactory {
22 private static final int LOG_NONE = 3; // LOG(FATAL), no VLOG.
23 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)
25 static final String LOG_TAG = "ChromiumNetwork";
26
27 private long mUrlRequestContextAdapter = 0;
28 private Thread mNetworkThread;
29
30 public CronetUrlRequestContext(Context context,
31 HttpUrlRequestFactoryConfig config) {
32 mUrlRequestContextAdapter = nativeCreateRequestContextAdapter(
33 context, getLoggingLevel(), config.toString());
34 if (mUrlRequestContextAdapter == 0)
xunjieli 2014/10/03 20:58:39 nit: brackets according to http://source.android.c
mef 2014/10/06 14:52:43 Done.
35 throw new NullPointerException("Context Adapter creation failed");
36 }
37
38 @Override
39 public UrlRequest createRequest(String url, UrlRequestListener listener,
40 Executor executor) {
41 return new CronetUrlRequest(this, url,
42 UrlRequest.REQUEST_PRIORITY_MEDIUM, listener, executor);
43 }
44
45 @Override
46 public boolean isEnabled() {
47 return Build.VERSION.SDK_INT >= 14;
48 }
49
50 @Override
51 public String getName() {
52 return "Cronet/" + Version.getVersion();
53 }
54
55 long getCronetUrlRequestContextAdapter() {
56 return mUrlRequestContextAdapter;
57 }
58
59 /**
60 * @return loggingLevel see {@link #LOG_NONE}, {@link #LOG_DEBUG} and
61 * {@link #LOG_VERBOSE}.
62 */
63 private int getLoggingLevel() {
64 int loggingLevel;
65 if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
66 loggingLevel = LOG_VERBOSE;
67 } else if (Log.isLoggable(LOG_TAG, Log.DEBUG)) {
68 loggingLevel = LOG_DEBUG;
69 } else {
70 loggingLevel = LOG_NONE;
71 }
72 return loggingLevel;
73 }
74
75 @CalledByNative
76 private void initNetworkThread() {
77 mNetworkThread = Thread.currentThread();
78 Thread.currentThread().setName("ChromiumNet");
79 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
80 }
81
82 // Native methods are implemented in cronet_url_request_context.cc.
83 private native long nativeCreateRequestContextAdapter(Context context,
84 int loggingLevel, String config);
85
86 private native void nativeReleaseRequestContextAdapter(
87 long urlRequestContextAdapter);
88
89 private native void nativeInitializeStatistics();
90
91 private native String nativeGetStatisticsJSON(String filter);
92
93 private native void nativeStartNetLogToFile(
94 long urlRequestContextAdapter, String fileName);
95
96 private native void nativeStopNetLog(long urlRequestContextAdapter);
97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698