OLD | NEW |
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 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "chrome/browser/chromeos/proxy_config_service_impl.h" | 10 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
| 11 #include "chrome/browser/prefs/proxy_prefs.h" |
11 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
12 #include "chromeos/network/network_state.h" | 13 #include "chromeos/network/network_state.h" |
13 #include "chromeos/network/network_state_handler.h" | 14 #include "chromeos/network/network_state_handler.h" |
14 #include "net/proxy/proxy_config.h" | 15 #include "net/proxy/proxy_config.h" |
15 #include "third_party/cros_system_api/dbus/service_constants.h" | 16 #include "third_party/cros_system_api/dbus/service_constants.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // Timeout to smooth temporary network state transitions for flaky networks. | 20 // Timeout to smooth temporary network state transitions for flaky networks. |
20 const int kNetworkStateCheckDelaySec = 3; | 21 const int kNetworkStateCheckDelaySec = 3; |
21 | 22 |
22 } // namespace | 23 } // namespace |
23 | 24 |
24 namespace chromeos { | 25 namespace chromeos { |
25 | 26 |
26 NetworkStateInformer::NetworkStateInformer() | 27 NetworkStateInformer::NetworkStateInformer() |
27 : state_(OFFLINE) { | 28 : state_(OFFLINE), |
| 29 weak_ptr_factory_(this) { |
28 } | 30 } |
29 | 31 |
30 NetworkStateInformer::~NetworkStateInformer() { | 32 NetworkStateInformer::~NetworkStateInformer() { |
31 if (NetworkHandler::IsInitialized()) | 33 if (NetworkHandler::IsInitialized()) |
32 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this); | 34 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this); |
33 if (NetworkPortalDetector::IsEnabledInCommandLine() && | 35 if (NetworkPortalDetector::IsEnabledInCommandLine() && |
34 NetworkPortalDetector::GetInstance()) { | 36 NetworkPortalDetector::GetInstance()) { |
35 NetworkPortalDetector::GetInstance()->RemoveObserver(this); | 37 NetworkPortalDetector::GetInstance()->RemoveObserver(this); |
36 } | 38 } |
37 } | 39 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 last_online_service_path_ = new_network_service_path; | 84 last_online_service_path_ = new_network_service_path; |
83 // Transitions {OFFLINE, PORTAL} -> ONLINE and connections to | 85 // Transitions {OFFLINE, PORTAL} -> ONLINE and connections to |
84 // different network are processed without delay. | 86 // different network are processed without delay. |
85 // Transitions {OFFLINE, ONLINE} -> PORTAL in the same network are | 87 // Transitions {OFFLINE, ONLINE} -> PORTAL in the same network are |
86 // also processed without delay. | 88 // also processed without delay. |
87 UpdateStateAndNotify(); | 89 UpdateStateAndNotify(); |
88 } else { | 90 } else { |
89 check_state_.Cancel(); | 91 check_state_.Cancel(); |
90 check_state_.Reset( | 92 check_state_.Reset( |
91 base::Bind(&NetworkStateInformer::UpdateStateAndNotify, | 93 base::Bind(&NetworkStateInformer::UpdateStateAndNotify, |
92 base::Unretained(this))); | 94 weak_ptr_factory_.GetWeakPtr())); |
93 base::MessageLoop::current()->PostDelayedTask( | 95 base::MessageLoop::current()->PostDelayedTask( |
94 FROM_HERE, | 96 FROM_HERE, |
95 check_state_.callback(), | 97 check_state_.callback(), |
96 base::TimeDelta::FromSeconds(kNetworkStateCheckDelaySec)); | 98 base::TimeDelta::FromSeconds(kNetworkStateCheckDelaySec)); |
97 } | 99 } |
98 } | 100 } |
99 | 101 |
100 void NetworkStateInformer::DefaultNetworkChanged(const NetworkState* network) { | 102 void NetworkStateInformer::DefaultNetworkChanged(const NetworkState* network) { |
101 NetworkManagerChanged(); | 103 NetworkManagerChanged(); |
102 } | 104 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 return ONLINE; | 206 return ONLINE; |
205 if (network->connection_state() == flimflam::kStatePortal) | 207 if (network->connection_state() == flimflam::kStatePortal) |
206 return CAPTIVE_PORTAL; | 208 return CAPTIVE_PORTAL; |
207 } | 209 } |
208 return OFFLINE; | 210 return OFFLINE; |
209 } | 211 } |
210 | 212 |
211 bool NetworkStateInformer::IsProxyConfigured(const NetworkState* network) { | 213 bool NetworkStateInformer::IsProxyConfigured(const NetworkState* network) { |
212 DCHECK(network); | 214 DCHECK(network); |
213 | 215 |
214 ProxyStateMap::iterator it = proxy_state_map_.find(network->guid()); | 216 ProxyConfigDictionary proxy_dict(&network->proxy_config()); |
215 if (it != proxy_state_map_.end() && | 217 ProxyPrefs::ProxyMode mode; |
216 it->second.proxy_config == network->proxy_config()) { | 218 return proxy_dict.GetMode(&mode) && mode == ProxyPrefs::MODE_FIXED_SERVERS; |
217 return it->second.configured; | |
218 } | |
219 net::ProxyConfig proxy_config; | |
220 if (!ProxyConfigServiceImpl::ParseProxyConfig(network->proxy_config(), | |
221 &proxy_config)) | |
222 return false; | |
223 bool configured = !proxy_config.proxy_rules().empty(); | |
224 proxy_state_map_[network->guid()] = | |
225 ProxyState(network->proxy_config(), configured); | |
226 return configured; | |
227 } | 219 } |
228 | 220 |
229 } // namespace chromeos | 221 } // namespace chromeos |
OLD | NEW |