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

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

Issue 11628008: Provide NetworkChangeNotifierAndroid with the actual initial connection type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make NCNA fetch the connection type through NCNDA 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 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 //////////////////////////////////////////////////////////////////////////////// 5 ////////////////////////////////////////////////////////////////////////////////
6 // Threading considerations: 6 // Threading considerations:
7 // 7 //
8 // This class is designed to meet various threading guarantees starting from the 8 // This class is designed to meet various threading guarantees starting from the
9 // ones imposed by NetworkChangeNotifier: 9 // ones imposed by NetworkChangeNotifier:
10 // - The notifier can be constructed on any thread. 10 // - The notifier can be constructed on any thread.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 #include "net/android/network_change_notifier_android.h" 60 #include "net/android/network_change_notifier_android.h"
61 61
62 namespace net { 62 namespace net {
63 63
64 NetworkChangeNotifierAndroid::~NetworkChangeNotifierAndroid() { 64 NetworkChangeNotifierAndroid::~NetworkChangeNotifierAndroid() {
65 delegate_->RemoveObserver(this); 65 delegate_->RemoveObserver(this);
66 } 66 }
67 67
68 NetworkChangeNotifier::ConnectionType 68 NetworkChangeNotifier::ConnectionType
69 NetworkChangeNotifierAndroid::GetCurrentConnectionType() const { 69 NetworkChangeNotifierAndroid::GetCurrentConnectionType() const {
70 base::AutoLock auto_lock(connection_type_lock_); 70 return delegate_->GetCurrentConnectionType();
71 return connection_type_;
72 } 71 }
73 72
74 void NetworkChangeNotifierAndroid::OnConnectionTypeChanged( 73 void NetworkChangeNotifierAndroid::OnConnectionTypeChanged(
75 ConnectionType new_connection_type) { 74 ConnectionType new_connection_type) {
76 SetConnectionType(new_connection_type);
77 NetworkChangeNotifier::NotifyObserversOfIPAddressChange(); 75 NetworkChangeNotifier::NotifyObserversOfIPAddressChange();
78 NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange(); 76 NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange();
79 } 77 }
80 78
81 // static 79 // static
82 bool NetworkChangeNotifierAndroid::Register(JNIEnv* env) { 80 bool NetworkChangeNotifierAndroid::Register(JNIEnv* env) {
83 return NetworkChangeNotifierDelegateAndroid::Register(env); 81 return NetworkChangeNotifierDelegateAndroid::Register(env);
84 } 82 }
85 83
86 NetworkChangeNotifierAndroid::NetworkChangeNotifierAndroid( 84 NetworkChangeNotifierAndroid::NetworkChangeNotifierAndroid(
87 NetworkChangeNotifierDelegateAndroid* delegate) 85 NetworkChangeNotifierDelegateAndroid* delegate)
88 : NetworkChangeNotifier(NetworkChangeCalculatorParamsAndroid()), 86 : NetworkChangeNotifier(NetworkChangeCalculatorParamsAndroid()),
89 delegate_(delegate) { 87 delegate_(delegate) {
90 SetConnectionType(NetworkChangeNotifier::CONNECTION_UNKNOWN);
91 delegate_->AddObserver(this); 88 delegate_->AddObserver(this);
92 } 89 }
93 90
94 // static 91 // static
95 NetworkChangeNotifier::NetworkChangeCalculatorParams 92 NetworkChangeNotifier::NetworkChangeCalculatorParams
96 NetworkChangeNotifierAndroid::NetworkChangeCalculatorParamsAndroid() { 93 NetworkChangeNotifierAndroid::NetworkChangeCalculatorParamsAndroid() {
97 NetworkChangeCalculatorParams params; 94 NetworkChangeCalculatorParams params;
98 // IPAddressChanged is produced immediately prior to ConnectionTypeChanged 95 // IPAddressChanged is produced immediately prior to ConnectionTypeChanged
99 // so delay IPAddressChanged so they get merged with the following 96 // so delay IPAddressChanged so they get merged with the following
100 // ConnectionTypeChanged signal. 97 // ConnectionTypeChanged signal.
101 params.ip_address_offline_delay_ = base::TimeDelta::FromSeconds(1); 98 params.ip_address_offline_delay_ = base::TimeDelta::FromSeconds(1);
102 params.ip_address_online_delay_ = base::TimeDelta::FromSeconds(1); 99 params.ip_address_online_delay_ = base::TimeDelta::FromSeconds(1);
103 params.connection_type_offline_delay_ = base::TimeDelta::FromSeconds(0); 100 params.connection_type_offline_delay_ = base::TimeDelta::FromSeconds(0);
104 params.connection_type_online_delay_ = base::TimeDelta::FromSeconds(0); 101 params.connection_type_online_delay_ = base::TimeDelta::FromSeconds(0);
105 return params; 102 return params;
106 } 103 }
107 104
108 void NetworkChangeNotifierAndroid::SetConnectionType(
109 ConnectionType new_connection_type) {
110 base::AutoLock auto_lock(connection_type_lock_);
111 connection_type_ = new_connection_type;
112 }
113
114 } // namespace net 105 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698