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

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/network_state_informer.cc

Issue 14729017: Add NetworkHandler to own network handlers in src/chromeos/network (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix chromeos_unittests Created 7 years, 7 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 #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/chromeos/proxy_config_service_impl.h"
(...skipping 11 matching lines...) Expand all
22 } // namespace 22 } // namespace
23 23
24 namespace chromeos { 24 namespace chromeos {
25 25
26 NetworkStateInformer::NetworkStateInformer() 26 NetworkStateInformer::NetworkStateInformer()
27 : state_(OFFLINE), 27 : state_(OFFLINE),
28 delegate_(NULL) { 28 delegate_(NULL) {
29 } 29 }
30 30
31 NetworkStateInformer::~NetworkStateInformer() { 31 NetworkStateInformer::~NetworkStateInformer() {
32 NetworkStateHandler::Get()->RemoveObserver(this); 32 if (NetworkHandler::IsInitialized())
33 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this);
33 if (NetworkPortalDetector::IsEnabledInCommandLine() && 34 if (NetworkPortalDetector::IsEnabledInCommandLine() &&
34 NetworkPortalDetector::GetInstance()) { 35 NetworkPortalDetector::GetInstance()) {
35 NetworkPortalDetector::GetInstance()->RemoveObserver(this); 36 NetworkPortalDetector::GetInstance()->RemoveObserver(this);
36 } 37 }
37 } 38 }
38 39
39 void NetworkStateInformer::Init() { 40 void NetworkStateInformer::Init() {
40 UpdateState(); 41 UpdateState();
41 NetworkStateHandler::Get()->AddObserver(this); 42 NetworkHandler::Get()->network_state_handler()->AddObserver(this);
42 43
43 if (NetworkPortalDetector::IsEnabledInCommandLine() && 44 if (NetworkPortalDetector::IsEnabledInCommandLine() &&
44 NetworkPortalDetector::GetInstance()) { 45 NetworkPortalDetector::GetInstance()) {
45 NetworkPortalDetector::GetInstance()->AddAndFireObserver(this); 46 NetworkPortalDetector::GetInstance()->AddAndFireObserver(this);
46 } 47 }
47 48
48 registrar_.Add(this, 49 registrar_.Add(this,
49 chrome::NOTIFICATION_LOGIN_PROXY_CHANGED, 50 chrome::NOTIFICATION_LOGIN_PROXY_CHANGED,
50 content::NotificationService::AllSources()); 51 content::NotificationService::AllSources());
51 registrar_.Add(this, 52 registrar_.Add(this,
(...skipping 10 matching lines...) Expand all
62 observers_.AddObserver(observer); 63 observers_.AddObserver(observer);
63 } 64 }
64 65
65 void NetworkStateInformer::RemoveObserver( 66 void NetworkStateInformer::RemoveObserver(
66 NetworkStateInformerObserver* observer) { 67 NetworkStateInformerObserver* observer) {
67 observers_.RemoveObserver(observer); 68 observers_.RemoveObserver(observer);
68 } 69 }
69 70
70 void NetworkStateInformer::NetworkManagerChanged() { 71 void NetworkStateInformer::NetworkManagerChanged() {
71 const NetworkState* default_network = 72 const NetworkState* default_network =
72 NetworkStateHandler::Get()->DefaultNetwork(); 73 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
73 State new_state = OFFLINE; 74 State new_state = OFFLINE;
74 std::string new_network_service_path; 75 std::string new_network_service_path;
75 if (default_network) { 76 if (default_network) {
76 new_state = GetNetworkState(default_network); 77 new_state = GetNetworkState(default_network);
77 new_network_service_path = default_network->path(); 78 new_network_service_path = default_network->path();
78 } 79 }
79 if ((state_ != ONLINE && (new_state == ONLINE || new_state == CONNECTING)) || 80 if ((state_ != ONLINE && (new_state == ONLINE || new_state == CONNECTING)) ||
80 (state_ == ONLINE && (new_state == ONLINE || new_state == CONNECTING) && 81 (state_ == ONLINE && (new_state == ONLINE || new_state == CONNECTING) &&
81 new_network_service_path != last_online_service_path_) || 82 new_network_service_path != last_online_service_path_) ||
82 (new_state == CAPTIVE_PORTAL && 83 (new_state == CAPTIVE_PORTAL &&
(...skipping 18 matching lines...) Expand all
101 } 102 }
102 } 103 }
103 104
104 void NetworkStateInformer::DefaultNetworkChanged(const NetworkState* network) { 105 void NetworkStateInformer::DefaultNetworkChanged(const NetworkState* network) {
105 NetworkManagerChanged(); 106 NetworkManagerChanged();
106 } 107 }
107 108
108 void NetworkStateInformer::OnPortalDetectionCompleted( 109 void NetworkStateInformer::OnPortalDetectionCompleted(
109 const NetworkState* network, 110 const NetworkState* network,
110 const NetworkPortalDetector::CaptivePortalState& state) { 111 const NetworkPortalDetector::CaptivePortalState& state) {
111 if (NetworkStateHandler::IsInitialized() && 112 if (NetworkHandler::IsInitialized() &&
112 NetworkStateHandler::Get()->DefaultNetwork() == network) 113 NetworkHandler::Get()->network_state_handler()->DefaultNetwork() ==
114 network)
113 NetworkManagerChanged(); 115 NetworkManagerChanged();
114 } 116 }
115 117
116 void NetworkStateInformer::Observe( 118 void NetworkStateInformer::Observe(
117 int type, 119 int type,
118 const content::NotificationSource& source, 120 const content::NotificationSource& source,
119 const content::NotificationDetails& details) { 121 const content::NotificationDetails& details) {
120 if (type == chrome::NOTIFICATION_SESSION_STARTED) 122 if (type == chrome::NOTIFICATION_SESSION_STARTED)
121 registrar_.RemoveAll(); 123 registrar_.RemoveAll();
122 else if (type == chrome::NOTIFICATION_LOGIN_PROXY_CHANGED) 124 else if (type == chrome::NOTIFICATION_LOGIN_PROXY_CHANGED)
123 SendStateToObservers(ErrorScreenActor::ERROR_REASON_PROXY_CONFIG_CHANGED); 125 SendStateToObservers(ErrorScreenActor::ERROR_REASON_PROXY_CONFIG_CHANGED);
124 else 126 else
125 NOTREACHED() << "Unknown notification: " << type; 127 NOTREACHED() << "Unknown notification: " << type;
126 } 128 }
127 129
128 void NetworkStateInformer::OnPortalDetected() { 130 void NetworkStateInformer::OnPortalDetected() {
129 SendStateToObservers(ErrorScreenActor::ERROR_REASON_PORTAL_DETECTED); 131 SendStateToObservers(ErrorScreenActor::ERROR_REASON_PORTAL_DETECTED);
130 } 132 }
131 133
132 bool NetworkStateInformer::UpdateState() { 134 bool NetworkStateInformer::UpdateState() {
133 State new_state = OFFLINE; 135 State new_state = OFFLINE;
134 136
135 const NetworkState* default_network = 137 const NetworkState* default_network =
136 NetworkStateHandler::Get()->DefaultNetwork(); 138 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
137 if (default_network) { 139 if (default_network) {
138 new_state = GetNetworkState(default_network); 140 new_state = GetNetworkState(default_network);
139 last_network_service_path_ = default_network->path(); 141 last_network_service_path_ = default_network->path();
140 last_network_type_ = default_network->type(); 142 last_network_type_ = default_network->type();
141 } 143 }
142 144
143 bool updated = (new_state != state_) || 145 bool updated = (new_state != state_) ||
144 (new_state != OFFLINE && 146 (new_state != OFFLINE &&
145 last_network_service_path_ != last_connected_service_path_); 147 last_network_service_path_ != last_connected_service_path_);
146 state_ = new_state; 148 state_ = new_state;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 if (!ProxyConfigServiceImpl::ParseProxyConfig(network->proxy_config(), 223 if (!ProxyConfigServiceImpl::ParseProxyConfig(network->proxy_config(),
222 &proxy_config)) 224 &proxy_config))
223 return false; 225 return false;
224 bool configured = !proxy_config.proxy_rules().empty(); 226 bool configured = !proxy_config.proxy_rules().empty();
225 proxy_state_map_[network->guid()] = 227 proxy_state_map_[network->guid()] =
226 ProxyState(network->proxy_config(), configured); 228 ProxyState(network->proxy_config(), configured);
227 return configured; 229 return configured;
228 } 230 }
229 231
230 } // namespace chromeos 232 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/chromeos/about_network.cc ('k') | chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698