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

Unified Diff: net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java

Issue 2363743002: Non-functional optimization to Android NetworkChangeNotifier startup part 2 (Closed)
Patch Set: rebase Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java
diff --git a/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java b/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java
index 7c2e8cb7b8ed8648e5f0389f3652172dfdaa650b..f3c743c8bfa16d99d9562ccf2d69303b233ec68a 100644
--- a/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java
+++ b/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java
@@ -562,6 +562,11 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver {
// observers anyhow as the state hasn't changed. This is simply an optimization to avoid
// useless work.
private boolean mIgnoreNextBroadcast;
+ // mSignal is set to false when it's not worth calculating if signals to Observers should
+ // be sent out because this class is being constructed and the internal state has just
+ // been updated to the current device state, so no signals are necessary. This is simply an
+ // optimization to avoid useless work.
+ private boolean mShouldSignalObserver;
/**
* Observer interface by which observer is notified of network changes.
@@ -640,8 +645,10 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver {
mMaxBandwidthConnectionType = mConnectionType;
mIntentFilter = new NetworkConnectivityIntentFilter();
mIgnoreNextBroadcast = false;
+ mShouldSignalObserver = false;
mRegistrationPolicy = policy;
mRegistrationPolicy.init(this);
+ mShouldSignalObserver = true;
}
/**
@@ -680,11 +687,14 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver {
* Registers a BroadcastReceiver in the given context.
*/
public void register() {
+ ThreadUtils.assertOnUiThread();
if (mRegistered) return;
- final NetworkState networkState = getCurrentNetworkState();
- connectionTypeChanged(networkState);
- maxBandwidthChanged(networkState);
+ if (mShouldSignalObserver) {
+ final NetworkState networkState = getCurrentNetworkState();
+ connectionTypeChanged(networkState);
+ maxBandwidthChanged(networkState);
+ }
// When registering for a sticky broadcast, like CONNECTIVITY_ACTION, if registerReceiver
// returns non-null, it means the broadcast was previously issued and onReceive() will be
// immediately called with this previous Intent. Since this initial callback doesn't
@@ -695,18 +705,21 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver {
if (mNetworkCallback != null) {
mNetworkCallback.initializeVpnInPlace();
mConnectivityManagerDelegate.registerNetworkCallback(mNetworkRequest, mNetworkCallback);
- // registerNetworkCallback() will rematch the NetworkRequest
- // against active networks, so a cached list of active networks
- // will be repopulated immediatly after this. However we need to
- // purge any cached networks as they may have been disconnected
- // while mNetworkCallback was unregistered.
- final Network[] networks = getAllNetworksFiltered(mConnectivityManagerDelegate, null);
- // Convert Networks to NetIDs.
- final long[] netIds = new long[networks.length];
- for (int i = 0; i < networks.length; i++) {
- netIds[i] = networkToNetId(networks[i]);
+ if (mShouldSignalObserver) {
+ // registerNetworkCallback() will rematch the NetworkRequest
+ // against active networks, so a cached list of active networks
+ // will be repopulated immediatly after this. However we need to
+ // purge any cached networks as they may have been disconnected
+ // while mNetworkCallback was unregistered.
+ final Network[] networks =
+ getAllNetworksFiltered(mConnectivityManagerDelegate, null);
+ // Convert Networks to NetIDs.
+ final long[] netIds = new long[networks.length];
+ for (int i = 0; i < networks.length; i++) {
+ netIds[i] = networkToNetId(networks[i]);
+ }
+ mObserver.purgeActiveNetworkList(netIds);
}
- mObserver.purgeActiveNetworkList(netIds);
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698