| 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 #ifndef CONTENT_BROWSER_ANDROID_BACKGROUND_SYNC_NETWORK_OBSERVER_ANDROID_H_ | 5 #ifndef CONTENT_BROWSER_ANDROID_BACKGROUND_SYNC_NETWORK_OBSERVER_ANDROID_H_ |
| 6 #define CONTENT_BROWSER_ANDROID_BACKGROUND_SYNC_NETWORK_OBSERVER_ANDROID_H_ | 6 #define CONTENT_BROWSER_ANDROID_BACKGROUND_SYNC_NETWORK_OBSERVER_ANDROID_H_ |
| 7 | 7 |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 static scoped_refptr<BackgroundSyncNetworkObserverAndroid::Observer> Create( | 39 static scoped_refptr<BackgroundSyncNetworkObserverAndroid::Observer> Create( |
| 40 base::Callback<void(net::NetworkChangeNotifier::ConnectionType)> | 40 base::Callback<void(net::NetworkChangeNotifier::ConnectionType)> |
| 41 callback); | 41 callback); |
| 42 | 42 |
| 43 static bool RegisterNetworkObserver(JNIEnv* env); | 43 static bool RegisterNetworkObserver(JNIEnv* env); |
| 44 | 44 |
| 45 // Called from BackgroundSyncNetworkObserver.java over JNI whenever the | 45 // Called from BackgroundSyncNetworkObserver.java over JNI whenever the |
| 46 // connection type changes. This updates the current connection type seen by | 46 // connection type changes. This updates the current connection type seen by |
| 47 // this class and calls the |network_changed_callback| provided to the | 47 // this class and calls the |network_changed_callback| provided to the |
| 48 // constructor, on the IO thread, with the new connection type. | 48 // constructor, on the IO thread, with the new connection type. |
| 49 void NotifyConnectionTypeChanged(JNIEnv* env, | 49 void NotifyConnectionTypeChanged( |
| 50 jobject jcaller, | 50 JNIEnv* env, |
| 51 jint new_connection_type); | 51 const base::android::JavaParamRef<jobject>& jcaller, |
| 52 jint new_connection_type); |
| 52 | 53 |
| 53 private: | 54 private: |
| 54 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 55 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
| 55 friend class base::DeleteHelper< | 56 friend class base::DeleteHelper< |
| 56 BackgroundSyncNetworkObserverAndroid::Observer>; | 57 BackgroundSyncNetworkObserverAndroid::Observer>; |
| 57 | 58 |
| 58 Observer(base::Callback<void(net::NetworkChangeNotifier::ConnectionType)> | 59 Observer(base::Callback<void(net::NetworkChangeNotifier::ConnectionType)> |
| 59 callback); | 60 callback); |
| 60 void Init(); | 61 void Init(); |
| 61 ~Observer(); | 62 ~Observer(); |
| 62 | 63 |
| 63 // This callback is to be run on the IO thread whenever the connection type | 64 // This callback is to be run on the IO thread whenever the connection type |
| 64 // changes. | 65 // changes. |
| 65 base::Callback<void(net::NetworkChangeNotifier::ConnectionType)> callback_; | 66 base::Callback<void(net::NetworkChangeNotifier::ConnectionType)> callback_; |
| 66 base::android::ScopedJavaGlobalRef<jobject> j_observer_; | 67 base::android::ScopedJavaGlobalRef<jobject> j_observer_; |
| 67 | 68 |
| 68 DISALLOW_COPY_AND_ASSIGN(Observer); | 69 DISALLOW_COPY_AND_ASSIGN(Observer); |
| 69 }; | 70 }; |
| 70 | 71 |
| 71 private: | 72 private: |
| 72 // Accessed on UI Thread | 73 // Accessed on UI Thread |
| 73 scoped_refptr<Observer> observer_; | 74 scoped_refptr<Observer> observer_; |
| 74 | 75 |
| 75 base::WeakPtrFactory<BackgroundSyncNetworkObserverAndroid> weak_ptr_factory_; | 76 base::WeakPtrFactory<BackgroundSyncNetworkObserverAndroid> weak_ptr_factory_; |
| 76 }; | 77 }; |
| 77 | 78 |
| 78 } // namespace content | 79 } // namespace content |
| 79 | 80 |
| 80 #endif // CONTENT_BROWSER_ANDROID_BACKGROUND_SYNC_NETWORK_OBSERVER_ANDROID_H_ | 81 #endif // CONTENT_BROWSER_ANDROID_BACKGROUND_SYNC_NETWORK_OBSERVER_ANDROID_H_ |
| OLD | NEW |