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

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

Issue 991923002: [cronet] Fix race to call InitApplicationContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove CreateRequestContextAdapter dead param Created 5 years, 9 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
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;
(...skipping 13 matching lines...) Expand all
24 static final String LOG_TAG = "ChromiumNetwork"; 24 static final String LOG_TAG = "ChromiumNetwork";
25 25
26 /** 26 /**
27 * Native adapter object, owned by ChromiumUrlRequestContext. 27 * Native adapter object, owned by ChromiumUrlRequestContext.
28 */ 28 */
29 private long mChromiumUrlRequestContextAdapter; 29 private long mChromiumUrlRequestContextAdapter;
30 30
31 /** 31 /**
32 * Constructor. 32 * Constructor.
33 */ 33 */
34 protected ChromiumUrlRequestContext(final Context context, String userAgent, 34 protected ChromiumUrlRequestContext(
35 String config) { 35 final Context context, String userAgent, UrlRequestContextConfig con fig) {
36 mChromiumUrlRequestContextAdapter = nativeCreateRequestContextAdapter( 36 CronetLibraryLoader.ensureInitialized(context, config);
37 context.getApplicationContext(), userAgent, getLoggingLevel(), c onfig); 37 mChromiumUrlRequestContextAdapter =
38 nativeCreateRequestContextAdapter(userAgent, getLoggingLevel(), config.toString());
38 if (mChromiumUrlRequestContextAdapter == 0) { 39 if (mChromiumUrlRequestContextAdapter == 0) {
39 throw new NullPointerException("Context Adapter creation failed"); 40 throw new NullPointerException("Context Adapter creation failed");
40 } 41 }
41 // Post a task to UI thread to init native Chromium URLRequestContext. 42 // Post a task to UI thread to init native Chromium URLRequestContext.
42 // TODO(xunjieli): This constructor is not supposed to be invoked on 43 // TODO(xunjieli): This constructor is not supposed to be invoked on
43 // the main thread. Consider making the following code into a blocking 44 // the main thread. Consider making the following code into a blocking
44 // API to handle the case where we are already on main thread. 45 // API to handle the case where we are already on main thread.
45 Runnable task = new Runnable() { 46 Runnable task = new Runnable() {
46 public void run() { 47 public void run() {
47 NetworkChangeNotifier.init(context);
48 // Registers to always receive network notifications. Note that
49 // this call is fine for Cronet because Cronet embedders do not
50 // have API access to create network change observers. Existing
51 // observers in the net stack do not perform expensive work.
52 NetworkChangeNotifier.registerToReceiveNotificationsAlways();
53 nativeInitRequestContextOnMainThread( 48 nativeInitRequestContextOnMainThread(
54 mChromiumUrlRequestContextAdapter); 49 mChromiumUrlRequestContextAdapter);
55 } 50 }
56 }; 51 };
57 new Handler(Looper.getMainLooper()).post(task); 52 new Handler(Looper.getMainLooper()).post(task);
58 } 53 }
59 54
60 /** 55 /**
61 * Returns the version of this network stack formatted as N.N.N.N/X where 56 * Returns the version of this network stack formatted as N.N.N.N/X where
62 * N.N.N.N is the version of Chromium and X is the revision number. 57 * N.N.N.N is the version of Chromium and X is the revision number.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 loggingLevel = LOG_DEBUG; 123 loggingLevel = LOG_DEBUG;
129 } else { 124 } else {
130 loggingLevel = LOG_NONE; 125 loggingLevel = LOG_NONE;
131 } 126 }
132 return loggingLevel; 127 return loggingLevel;
133 } 128 }
134 129
135 // Returns an instance ChromiumUrlRequestContextAdapter to be stored in 130 // Returns an instance ChromiumUrlRequestContextAdapter to be stored in
136 // mChromiumUrlRequestContextAdapter. 131 // mChromiumUrlRequestContextAdapter.
137 private native long nativeCreateRequestContextAdapter( 132 private native long nativeCreateRequestContextAdapter(
138 Context appContext, String userAgent, int loggingLevel, String confi g); 133 String userAgent, int loggingLevel, String config);
139 134
140 private native void nativeReleaseRequestContextAdapter( 135 private native void nativeReleaseRequestContextAdapter(
141 long chromiumUrlRequestContextAdapter); 136 long chromiumUrlRequestContextAdapter);
142 137
143 private native void nativeInitializeStatistics(); 138 private native void nativeInitializeStatistics();
144 139
145 private native String nativeGetStatisticsJSON(String filter); 140 private native String nativeGetStatisticsJSON(String filter);
146 141
147 private native void nativeStartNetLogToFile( 142 private native void nativeStartNetLogToFile(
148 long chromiumUrlRequestContextAdapter, String fileName); 143 long chromiumUrlRequestContextAdapter, String fileName);
149 144
150 private native void nativeStopNetLog(long chromiumUrlRequestContextAdapter); 145 private native void nativeStopNetLog(long chromiumUrlRequestContextAdapter);
151 146
152 private native void nativeInitRequestContextOnMainThread( 147 private native void nativeInitRequestContextOnMainThread(
153 long chromiumUrlRequestContextAdapter); 148 long chromiumUrlRequestContextAdapter);
154 } 149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698