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

Side by Side Diff: net/android/network_change_notifier_android.h

Issue 10905264: Fix race condition in NetworkChangeNotifier on Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Ryan's comments 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_ 5 #ifndef NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_
6 #define NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_ 6 #define NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_
7 7
8 #include "base/android/scoped_java_ref.h" 8 #include "base/android/scoped_java_ref.h"
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/synchronization/lock.h"
11 #include "net/base/network_change_notifier.h" 12 #include "net/base/network_change_notifier.h"
12 13
13 namespace net { 14 namespace net {
14 namespace android { 15 namespace android {
15 16
16 class NetworkChangeNotifier : public net::NetworkChangeNotifier { 17 class NetworkChangeNotifier : public net::NetworkChangeNotifier {
17 public: 18 public:
18 NetworkChangeNotifier();
19 virtual ~NetworkChangeNotifier(); 19 virtual ~NetworkChangeNotifier();
20 20
21 void NotifyObservers(JNIEnv* env, jobject obj); 21 // Called from Java on the UI thread.
22 void NotifyObservers(JNIEnv* env, jobject obj, int new_connection_type);
23 jint GetConnectionType(JNIEnv* env, jobject obj);
22 24
23 static bool Register(JNIEnv* env); 25 static bool Register(JNIEnv* env);
24 26
25 private: 27 private:
28 friend class NetworkChangeNotifierFactory;
29
30 NetworkChangeNotifier();
31
26 void CreateJavaObject(JNIEnv* env); 32 void CreateJavaObject(JNIEnv* env);
27 33
34 void SetConnectionType(int connection_type);
35
28 // NetworkChangeNotifier: 36 // NetworkChangeNotifier:
29 virtual net::NetworkChangeNotifier::ConnectionType 37 virtual net::NetworkChangeNotifier::ConnectionType
30 GetCurrentConnectionType() const OVERRIDE; 38 GetCurrentConnectionType() const OVERRIDE;
31 39
32 base::android::ScopedJavaGlobalRef<jobject> java_network_change_notifier_; 40 base::android::ScopedJavaGlobalRef<jobject> java_network_change_notifier_;
41 // TODO(pliard): Use an atomic integer for the connection type without the
42 // lock once a non-subtle atomic integer is available under base/. That might
43 // never happen though.
szym 2012/09/19 18:46:55 Add relevant reference to crbug.com/
Philippe 2012/09/19 20:57:56 Done.
44 mutable base::Lock lock_; // Protects the state below.
45 // Wrote from the UI thread, read from any thread.
szym 2012/09/19 18:46:55 nit: "Written"
Philippe 2012/09/19 20:57:56 Oops :)
46 int connection_type_;
33 47
34 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); 48 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier);
35 }; 49 };
36 50
37 } // namespace android 51 } // namespace android
38 } // namespace net 52 } // namespace net
39 53
40 #endif // NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_ 54 #endif // NET_ANDROID_NETWORK_CHANGE_NOTIFIER_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698