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

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 clm's comments, populate ResponseInfo. Created 6 years, 3 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.Process;
9 import android.util.Log;
10
11 import org.chromium.base.CalledByNative;
12 import org.chromium.base.JNINamespace;
13
14 import java.util.concurrent.Executor;
15
16 /**
17 * UrlRequest factory using Chromium HTTP stack implementation.
18 */
19 @JNINamespace("cronet")
20 public class CronetUrlRequestContext implements UrlRequestFactory {
21 private static final int LOG_NONE = 3; // LOG(FATAL), no VLOG.
22 private static final int LOG_DEBUG = -1; // LOG(FATAL...INFO), VLOG(1)
23 private static final int LOG_VERBOSE = -2; // LOG(FATAL...INFO), VLOG(2)
24 static final String LOG_TAG = "ChromiumNetwork";
25
26 private long mUrlRequestContextAdapter = 0;
27 private Thread mNetworkThread;
28
29 /**
30 * Constructor.
31 *
32 */
33 public CronetUrlRequestContext(Context context, String userAgent, String con fig) {
Charles 2014/09/23 22:33:13 silly 80 char limit violation
mef 2014/09/24 18:56:26 Done.
34 mUrlRequestContextAdapter = nativeCreateRequestContextAdapter(
35 context, userAgent, getLoggingLevel(), config);
36 if (mUrlRequestContextAdapter == 0)
37 throw new NullPointerException("Context Adapter creation failed");
38 }
39
40 @Override
41 public UrlRequest createRequest(String url, UrlRequestListener listener,
42 Executor executor) {
43 return new CronetUrlRequest(this, url,
44 UrlRequest.REQUEST_PRIORITY_MEDIUM, listener, executor);
45 }
46
47 long getCronetUrlRequestContextAdapter() {
48 return mUrlRequestContextAdapter;
49 }
50
51 /**
52 * @return loggingLevel see {@link #LOG_NONE}, {@link #LOG_DEBUG} and
53 * {@link #LOG_VERBOSE}.
54 */
55 private int getLoggingLevel() {
56 int loggingLevel;
57 if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
58 loggingLevel = LOG_VERBOSE;
59 } else if (Log.isLoggable(LOG_TAG, Log.DEBUG)) {
60 loggingLevel = LOG_DEBUG;
61 } else {
62 loggingLevel = LOG_NONE;
63 }
64 return loggingLevel;
65 }
66
67 @CalledByNative
68 private void initNetworkThread() {
69 mNetworkThread = Thread.currentThread();
70 Thread.currentThread().setName("ChromiumNet");
71 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
72 }
73
74 // Native methods are implemented in cronet_url_request_context.cc.
75 private native long nativeCreateRequestContextAdapter(Context context,
76 String userAgent, int loggingLevel, String config);
77
78 private native void nativeReleaseRequestContextAdapter(
79 long urlRequestContextAdapter);
80
81 private native void nativeInitializeStatistics();
82
83 private native String nativeGetStatisticsJSON(String filter);
84
85 private native void nativeStartNetLogToFile(
86 long urlRequestContextAdapter, String fileName);
87
88 private native void nativeStopNetLog(long urlRequestContextAdapter);
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698