Commit 9fc65981 authored by Peter Wen's avatar Peter Wen Committed by Commit Bot

Android: Clean up NetworkChangeNotifier init

Also remove TODO in test since the test requires access to its custom
context class in other methods.

Bug: 646094
Cq-Include-Trybots: master.tryserver.chromium.android:android_cronet_tester
Change-Id: I36534c78d6cb8510f8837f52d8dbe26d9dae1b47
Reviewed-on: https://chromium-review.googlesource.com/517647Reviewed-by: default avatarAlok Priyadarshi <alokp@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarPaul Jensen <pauljensen@chromium.org>
Commit-Queue: Peter Wen <wnwen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#476428}
parent b7416d96
...@@ -221,7 +221,6 @@ public class DownloadManagerService ...@@ -221,7 +221,6 @@ public class DownloadManagerService
@VisibleForTesting @VisibleForTesting
protected DownloadManagerService(Context context, DownloadNotifier downloadNotifier, protected DownloadManagerService(Context context, DownloadNotifier downloadNotifier,
Handler handler, long updateDelayInMillis) { Handler handler, long updateDelayInMillis) {
// TODO(wnwen): Remove mContext since it is always the application context.
mContext = context; mContext = context;
mSharedPrefs = ContextUtils.getAppSharedPreferences(); mSharedPrefs = ContextUtils.getAppSharedPreferences();
// Clean up unused shared prefs. TODO(qinmin): remove this after M61. // Clean up unused shared prefs. TODO(qinmin): remove this after M61.
......
...@@ -50,7 +50,6 @@ public class InvalidationServiceTest { ...@@ -50,7 +50,6 @@ public class InvalidationServiceTest {
mAppContext = new IntentSavingContext(InstrumentationRegistry.getInstrumentation() mAppContext = new IntentSavingContext(InstrumentationRegistry.getInstrumentation()
.getTargetContext() .getTargetContext()
.getApplicationContext()); .getApplicationContext());
// TODO(wnwen): Remove mAppContext and just use application context.
// We don't want to use the system content resolver, so we override it. // We don't want to use the system content resolver, so we override it.
MockSyncContentResolverDelegate delegate = new MockSyncContentResolverDelegate(); MockSyncContentResolverDelegate delegate = new MockSyncContentResolverDelegate();
// Android master sync can safely always be on. // Android master sync can safely always be on.
......
...@@ -68,7 +68,7 @@ public class CastBrowserHelper { ...@@ -68,7 +68,7 @@ public class CastBrowserHelper {
Log.d(TAG, "Loading BrowserStartupController..."); Log.d(TAG, "Loading BrowserStartupController...");
BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER) BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
.startBrowserProcessesSync(false); .startBrowserProcessesSync(false);
NetworkChangeNotifier.init(context); NetworkChangeNotifier.init();
// Cast shell always expects to receive notifications to track network state. // Cast shell always expects to receive notifications to track network state.
NetworkChangeNotifier.registerToReceiveNotificationsAlways(); NetworkChangeNotifier.registerToReceiveNotificationsAlways();
sIsBrowserInitialized = true; sIsBrowserInitialized = true;
......
...@@ -43,7 +43,7 @@ public class CronetLibraryLoader { ...@@ -43,7 +43,7 @@ public class CronetLibraryLoader {
* any thread, the load and initialization is performed on init thread. * any thread, the load and initialization is performed on init thread.
*/ */
public static void ensureInitialized( public static void ensureInitialized(
final Context applicationContext, final CronetEngineBuilderImpl builder) { Context applicationContext, final CronetEngineBuilderImpl builder) {
synchronized (sLoadLock) { synchronized (sLoadLock) {
if (!sInitThreadInitDone) { if (!sInitThreadInitDone) {
ContextUtils.initApplicationContext(applicationContext); ContextUtils.initApplicationContext(applicationContext);
...@@ -53,7 +53,7 @@ public class CronetLibraryLoader { ...@@ -53,7 +53,7 @@ public class CronetLibraryLoader {
postToInitThread(new Runnable() { postToInitThread(new Runnable() {
@Override @Override
public void run() { public void run() {
ensureInitializedOnInitThread(applicationContext); ensureInitializedOnInitThread();
} }
}); });
} }
...@@ -89,12 +89,12 @@ public class CronetLibraryLoader { ...@@ -89,12 +89,12 @@ public class CronetLibraryLoader {
* the init thread. Ensures that the NetworkChangeNotifier is initialzied and the * the init thread. Ensures that the NetworkChangeNotifier is initialzied and the
* init thread native MessageLoop is initialized. * init thread native MessageLoop is initialized.
*/ */
static void ensureInitializedOnInitThread(Context context) { static void ensureInitializedOnInitThread() {
assert onInitThread(); assert onInitThread();
if (sInitThreadInitDone) { if (sInitThreadInitDone) {
return; return;
} }
NetworkChangeNotifier.init(context); NetworkChangeNotifier.init();
// Registers to always receive network notifications. Note // Registers to always receive network notifications. Note
// that this call is fine for Cronet because Cronet // that this call is fine for Cronet because Cronet
// embedders do not have API access to create network change // embedders do not have API access to create network change
......
...@@ -165,7 +165,7 @@ public class CronetUrlRequestContext extends CronetEngineBase { ...@@ -165,7 +165,7 @@ public class CronetUrlRequestContext extends CronetEngineBase {
CronetLibraryLoader.postToInitThread(new Runnable() { CronetLibraryLoader.postToInitThread(new Runnable() {
@Override @Override
public void run() { public void run() {
CronetLibraryLoader.ensureInitializedOnInitThread(builder.getContext()); CronetLibraryLoader.ensureInitializedOnInitThread();
synchronized (mLock) { synchronized (mLock) {
// mUrlRequestContextAdapter is guaranteed to exist until // mUrlRequestContextAdapter is guaranteed to exist until
// initialization on init and network threads completes and // initialization on init and network threads completes and
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package org.chromium.net; package org.chromium.net;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context;
import org.chromium.base.ObserverList; import org.chromium.base.ObserverList;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
...@@ -50,11 +49,6 @@ public class NetworkChangeNotifier { ...@@ -50,11 +49,6 @@ public class NetworkChangeNotifier {
mConnectionTypeObservers = new ObserverList<ConnectionTypeObserver>(); mConnectionTypeObservers = new ObserverList<ConnectionTypeObserver>();
} }
// TODO(wnwen): Remove after downstream no longer depends on this.
public static NetworkChangeNotifier init(Context context) {
return init();
}
/** /**
* Initializes the singleton once. * Initializes the singleton once.
*/ */
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package org.chromium.net; package org.chromium.net;
import android.os.Looper; import android.os.Looper;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import org.junit.Test; import org.junit.Test;
...@@ -27,7 +26,7 @@ public class NetworkChangeNotifierNoNativeTest { ...@@ -27,7 +26,7 @@ public class NetworkChangeNotifierNoNativeTest {
@MediumTest @MediumTest
public void testNoNativeDependence() { public void testNoNativeDependence() {
Looper.prepare(); Looper.prepare();
NetworkChangeNotifier.init(InstrumentationRegistry.getInstrumentation().getTargetContext()); NetworkChangeNotifier.init();
NetworkChangeNotifier.registerToReceiveNotificationsAlways(); NetworkChangeNotifier.registerToReceiveNotificationsAlways();
} }
} }
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment