OLD | NEW |
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 #include "network_change_notifier_util.h" | 5 #include "network_change_notifier_util.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 bool ip_address_changed_; | 38 bool ip_address_changed_; |
39 | 39 |
40 DISALLOW_COPY_AND_ASSIGN(TestIPAddressObserver); | 40 DISALLOW_COPY_AND_ASSIGN(TestIPAddressObserver); |
41 }; | 41 }; |
42 | 42 |
43 } // namespace | 43 } // namespace |
44 | 44 |
45 // Adds a TestIPAddressObserver to the list of IPAddressObservers, and returns | 45 // Adds a TestIPAddressObserver to the list of IPAddressObservers, and returns |
46 // a boolean indicating whether the TestIPAddressObserver has received | 46 // a boolean indicating whether the TestIPAddressObserver has received |
47 // notification when network changes. | 47 // notification when network changes. |
48 static jboolean IsTestIPAddressObserverCalled(JNIEnv* jenv, jclass jcaller) { | 48 static jboolean IsTestIPAddressObserverCalled( |
| 49 JNIEnv* jenv, |
| 50 const JavaParamRef<jclass>& jcaller) { |
49 // This method is called on a Java thread with no MessageLoop, but we need | 51 // This method is called on a Java thread with no MessageLoop, but we need |
50 // one for the NetworkChangeNotifier to call the observer on. | 52 // one for the NetworkChangeNotifier to call the observer on. |
51 base::MessageLoop loop; | 53 base::MessageLoop loop; |
52 TestIPAddressObserver test_observer; | 54 TestIPAddressObserver test_observer; |
53 net::NetworkChangeNotifier::AddIPAddressObserver(&test_observer); | 55 net::NetworkChangeNotifier::AddIPAddressObserver(&test_observer); |
54 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 56 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
55 | 57 |
56 base::RunLoop().RunUntilIdle(); | 58 base::RunLoop().RunUntilIdle(); |
57 net::NetworkChangeNotifier::RemoveIPAddressObserver(&test_observer); | 59 net::NetworkChangeNotifier::RemoveIPAddressObserver(&test_observer); |
58 | 60 |
59 return test_observer.ip_address_changed(); | 61 return test_observer.ip_address_changed(); |
60 } | 62 } |
61 | 63 |
62 bool RegisterNetworkChangeNotifierUtil(JNIEnv* jenv) { | 64 bool RegisterNetworkChangeNotifierUtil(JNIEnv* jenv) { |
63 return RegisterNativesImpl(jenv); | 65 return RegisterNativesImpl(jenv); |
64 } | 66 } |
65 | 67 |
66 } // namespace cronet | 68 } // namespace cronet |
OLD | NEW |