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

Unified Diff: net/android/network_change_notifier_android.h

Issue 10979048: Fix potential threading issues in NetworkChangeNotifierAndroid. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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
Index: net/android/network_change_notifier_android.h
diff --git a/net/android/network_change_notifier_android.h b/net/android/network_change_notifier_android.h
index f5311ac9bc60abfd2f011c72797b83a9f111d0a3..2f413e4958df1fe4063b61f4def4610f31dbdffc 100644
--- a/net/android/network_change_notifier_android.h
+++ b/net/android/network_change_notifier_android.h
@@ -11,41 +11,54 @@
#include "base/synchronization/lock.h"
#include "net/base/network_change_notifier.h"
+namespace base {
+
+class TaskRunner;
+
+} // namespace base
+
namespace net {
class NetworkChangeNotifierAndroidTest;
class NetworkChangeNotifierAndroid : public NetworkChangeNotifier {
public:
- virtual ~NetworkChangeNotifierAndroid();
+ class Delegate {
+ public:
+ // Called from Java on the UI thread.
+ virtual void NotifyObserversOfConnectionTypeChange(
+ JNIEnv* env, jobject obj, jint new_connection_type) = 0;
- // Called from Java on the UI thread.
- void NotifyObserversOfConnectionTypeChange(
- JNIEnv* env, jobject obj, jint new_connection_type);
- jint GetConnectionType(JNIEnv* env, jobject obj);
+ virtual jint GetConnectionType(JNIEnv* env, jobject obj) const = 0;
+
+ protected:
+ virtual ~Delegate() {}
+ };
+
+ virtual ~NetworkChangeNotifierAndroid();
static bool Register(JNIEnv* env);
private:
+ class DelegateImpl;
+
+ friend class DelegateImpl;
friend class NetworkChangeNotifierAndroidTest;
friend class NetworkChangeNotifierFactoryAndroid;
- NetworkChangeNotifierAndroid();
+ NetworkChangeNotifierAndroid(base::TaskRunner* ui_task_runner);
- void SetConnectionType(int connection_type);
+ // Wrapper used to let |Delegate| call the protected
+ // NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange() method.
+ static void NotifyObservers();
void ForceConnectivityState(bool state);
// NetworkChangeNotifier:
virtual ConnectionType GetCurrentConnectionType() const OVERRIDE;
- base::android::ScopedJavaGlobalRef<jobject> java_network_change_notifier_;
- // TODO(pliard): http://crbug.com/150867. Use an atomic integer for the
- // connection type without the lock once a non-subtle atomic integer is
- // available under base/. That might never happen though.
- mutable base::Lock lock_; // Protects the state below.
- // Written from the UI thread, read from any thread.
- int connection_type_;
+ // The delegate deletes itself.
+ DelegateImpl* const delegate_;
DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierAndroid);
};
« no previous file with comments | « net/android/java/src/org/chromium/net/NetworkChangeNotifier.java ('k') | net/android/network_change_notifier_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698