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

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: Move userAgent into config, introduce ExtendedResponseInfo. 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 {
mmenke 2014/10/02 15:24:09 Think we should be consistent here, use Factory fo
mef 2014/10/02 22:07:43 I agree, but I'm thorn. 'Context' matches //net, b
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 /**
31 * Constructor.
32 *
33 */
mmenke 2014/10/02 15:24:09 nit: Fix indent. Also, does this comment really
mef 2014/10/02 22:07:43 Done.
34 public CronetUrlRequestContext(Context context,
35 HttpUrlRequestFactoryConfig config) {
36 mUrlRequestContextAdapter = nativeCreateRequestContextAdapter(
37 context, getLoggingLevel(), config.toString());
38 if (mUrlRequestContextAdapter == 0)
39 throw new NullPointerException("Context Adapter creation failed");
40 }
41
42 @Override
43 public UrlRequest createRequest(String url, UrlRequestListener listener,
44 Executor executor) {
45 return new CronetUrlRequest(this, url,
46 UrlRequest.REQUEST_PRIORITY_MEDIUM, listener, executor);
47 }
48
49 @Override
50 public boolean isEnabled() {
51 return Build.VERSION.SDK_INT >= 14;
52 }
53
54 @Override
55 public String getName() {
56 return "Cronet/" + Version.getVersion();
57 }
58
59 long getCronetUrlRequestContextAdapter() {
60 return mUrlRequestContextAdapter;
61 }
62
63 /**
64 * @return loggingLevel see {@link #LOG_NONE}, {@link #LOG_DEBUG} and
65 * {@link #LOG_VERBOSE}.
66 */
67 private int getLoggingLevel() {
68 int loggingLevel;
69 if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
70 loggingLevel = LOG_VERBOSE;
71 } else if (Log.isLoggable(LOG_TAG, Log.DEBUG)) {
72 loggingLevel = LOG_DEBUG;
73 } else {
74 loggingLevel = LOG_NONE;
75 }
76 return loggingLevel;
77 }
78
79 @CalledByNative
80 private void initNetworkThread() {
81 mNetworkThread = Thread.currentThread();
82 Thread.currentThread().setName("ChromiumNet");
83 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
84 }
85
86 // Native methods are implemented in cronet_url_request_context.cc.
87 private native long nativeCreateRequestContextAdapter(Context context,
88 int loggingLevel, String config);
89
90 private native void nativeReleaseRequestContextAdapter(
91 long urlRequestContextAdapter);
92
93 private native void nativeInitializeStatistics();
94
95 private native String nativeGetStatisticsJSON(String filter);
96
97 private native void nativeStartNetLogToFile(
98 long urlRequestContextAdapter, String fileName);
99
100 private native void nativeStopNetLog(long urlRequestContextAdapter);
101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698