OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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.chrome.browser.preferences; |
| 6 |
| 7 import android.content.BroadcastReceiver; |
| 8 import android.content.Context; |
| 9 import android.content.Intent; |
| 10 import android.content.IntentFilter; |
| 11 import android.net.ConnectivityManager; |
| 12 |
| 13 import org.chromium.chrome.browser.precache.PrecacheLauncher; |
| 14 import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager
; |
| 15 |
| 16 /** |
| 17 * When there is a change in the network connection,this will update the sharedp
ref value whether |
| 18 * to allow prefetch or not. |
| 19 */ |
| 20 public class ConnectionChangeReceiver extends BroadcastReceiver { |
| 21 |
| 22 private boolean mIsRegistered; |
| 23 |
| 24 public void registerReceiver(Context context) { |
| 25 mIsRegistered = true; |
| 26 IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_
ACTION); |
| 27 context.registerReceiver(this, filter); |
| 28 } |
| 29 |
| 30 public void unregisterReceiver(Context context) { |
| 31 mIsRegistered = false; |
| 32 context.unregisterReceiver(this); |
| 33 } |
| 34 |
| 35 @Override |
| 36 public void onReceive(Context context, Intent intent) { |
| 37 // Only handle the action if we're currently registered. If we're not re
gistered as a |
| 38 // listener, then we might be paused and native may not be loaded which
would crash. |
| 39 if (mIsRegistered) { |
| 40 PrecacheLauncher.updatePrecachingEnabled( |
| 41 PrivacyPreferencesManager.getInstance(context), |
| 42 context.getApplicationContext()); |
| 43 } |
| 44 } |
| 45 } |
OLD | NEW |