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