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

Unified Diff: net/android/network_change_notifier_delegate_android.h

Issue 11628008: Provide NetworkChangeNotifierAndroid with the actual initial connection type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Ryan's comments Created 8 years 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_delegate_android.h
diff --git a/net/android/network_change_notifier_delegate_android.h b/net/android/network_change_notifier_delegate_android.h
index 9f5caa44167656ac279c519a50a69e46f4d0263f..c2d65b5e6e68d6e247116138b9e51e69f33c89ac 100644
--- a/net/android/network_change_notifier_delegate_android.h
+++ b/net/android/network_change_notifier_delegate_android.h
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/observer_list_threadsafe.h"
+#include "base/synchronization/lock.h"
#include "base/threading/thread_checker.h"
#include "net/base/network_change_notifier.h"
@@ -21,10 +22,7 @@ namespace net {
// unless otherwise stated (e.g. AddObserver()/RemoveObserver()).
class NET_EXPORT_PRIVATE NetworkChangeNotifierDelegateAndroid {
public:
- enum ConnectivityState {
- OFFLINE,
- ONLINE,
- };
+ typedef NetworkChangeNotifier::ConnectionType ConnectionType;
// Observer interface implemented by NetworkChangeNotifierAndroid which
// subscribes to network change notifications fired by the delegate (and
@@ -34,13 +32,15 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierDelegateAndroid {
virtual ~Observer() {}
// Updates the current connection type.
- virtual void OnConnectionTypeChanged(
- NetworkChangeNotifier::ConnectionType new_connection_type) = 0;
+ virtual void OnConnectionTypeChanged() = 0;
};
NetworkChangeNotifierDelegateAndroid();
~NetworkChangeNotifierDelegateAndroid();
+ // Can be called from any thread.
+ ConnectionType GetCurrentConnectionType() const;
+
Ryan Sleevi 2013/01/03 18:28:25 Pedantry, but I think it might be easier to group
Philippe 2013/01/04 10:13:01 Good point.
// Called from NetworkChangeNotifierAndroid.java on the JNI thread whenever
// the connection type changes. This updates the current connection type seen
// by this class and forwards the notification to the observers that
@@ -55,21 +55,23 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierDelegateAndroid {
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
- // Exposed for testing.
- void ForceConnectivityState(ConnectivityState state);
-
// Initializes JNI bindings.
static bool Register(JNIEnv* env);
private:
- friend class NetworkChangeNotifierDelegateAndroidTest;
+ friend class BaseNetworkChangeNotifierAndroidTest;
- typedef NetworkChangeNotifier::ConnectionType ConnectionType;
+ void SetCurrentConnectionType(ConnectionType connection_type);
+
+ // Methods calling the Java side exposed for testing.
+ void SetOnline();
+ void SetOffline();
base::ThreadChecker thread_checker_;
scoped_refptr<ObserverListThreadSafe<Observer> > observers_;
scoped_refptr<base::SingleThreadTaskRunner> jni_task_runner_;
base::android::ScopedJavaGlobalRef<jobject> java_network_change_notifier_;
+ mutable base::Lock connection_type_lock_; // Protects the state below.
ConnectionType connection_type_;
DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierDelegateAndroid);

Powered by Google App Engine
This is Rietveld 408576698