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

Side by Side Diff: ash/system/chromeos/network/network_connect.cc

Issue 21046008: Convert all connect code to use NetworkHandler instead of NetworkLibrary (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Feedback Round 1 Created 7 years, 4 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "ash/system/chromeos/network/network_connect.h" 5 #include "ash/system/chromeos/network/network_connect.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/system/chromeos/network/network_observer.h" 8 #include "ash/system/chromeos/network/network_observer.h"
9 #include "ash/system/chromeos/network/network_state_notifier.h" 9 #include "ash/system/chromeos/network/network_state_notifier.h"
10 #include "ash/system/tray/system_tray_delegate.h" 10 #include "ash/system/tray/system_tray_delegate.h"
11 #include "ash/system/tray/system_tray_notifier.h" 11 #include "ash/system/tray/system_tray_notifier.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chromeos/network/device_state.h"
17 #include "chromeos/network/network_configuration_handler.h"
16 #include "chromeos/network/network_connection_handler.h" 18 #include "chromeos/network/network_connection_handler.h"
19 #include "chromeos/network/network_event_log.h"
20 #include "chromeos/network/network_profile_handler.h"
17 #include "chromeos/network/network_state.h" 21 #include "chromeos/network/network_state.h"
18 #include "chromeos/network/network_state_handler.h" 22 #include "chromeos/network/network_state_handler.h"
19 #include "grit/ash_strings.h" 23 #include "grit/ash_strings.h"
20 #include "third_party/cros_system_api/dbus/service_constants.h" 24 #include "third_party/cros_system_api/dbus/service_constants.h"
21 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
22 26
27 using chromeos::DeviceState;
28 using chromeos::NetworkConfigurationHandler;
23 using chromeos::NetworkConnectionHandler; 29 using chromeos::NetworkConnectionHandler;
24 using chromeos::NetworkHandler; 30 using chromeos::NetworkHandler;
31 using chromeos::NetworkProfile;
32 using chromeos::NetworkProfileHandler;
25 using chromeos::NetworkState; 33 using chromeos::NetworkState;
26 34
27 namespace ash { 35 namespace ash {
28 36
29 namespace { 37 namespace {
30 38
39 bool IsDirectActivatedCarrier(const std::string& carrier) {
pneubeck (no reviews) 2013/08/06 15:45:19 nit: maybe it's worth explaining what "DirectActiv
stevenjb 2013/08/06 20:23:55 Done.
40 if (carrier == shill::kCarrierSprint)
41 return true;
42 return false;
43 }
44
31 void OnConnectFailed(const std::string& service_path, 45 void OnConnectFailed(const std::string& service_path,
46 gfx::NativeWindow owning_window,
32 const std::string& error_name, 47 const std::string& error_name,
33 scoped_ptr<base::DictionaryValue> error_data) { 48 scoped_ptr<base::DictionaryValue> error_data) {
34 VLOG(1) << "Connect Failed for " << service_path << ": " << error_name; 49 NET_LOG_ERROR("Connect Failed: " + error_name, service_path);
35 if (error_name == NetworkConnectionHandler::kErrorPassphraseRequired) { 50 if (error_name == NetworkConnectionHandler::kErrorPassphraseRequired) {
36 // TODO(stevenjb): Possibly add inline UI to handle passphrase entry here. 51 // TODO(stevenjb): Possibly add inline UI to handle passphrase entry here.
37 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( 52 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork(
38 service_path); 53 service_path);
39 return; 54 return;
40 } 55 }
56 if (error_name == NetworkConnectionHandler::kErrorCertificateRequired) {
57 ash::Shell::GetInstance()->system_tray_delegate()->EnrollOrConfigureNetwork(
pneubeck (no reviews) 2013/08/06 15:45:19 make this conditional on owning_window!=NULL and l
stevenjb 2013/08/06 20:23:55 It's not conditional on owning_window != NULL. The
58 service_path, owning_window);
59 return;
60 }
41 if (error_name == NetworkConnectionHandler::kErrorActivationRequired || 61 if (error_name == NetworkConnectionHandler::kErrorActivationRequired ||
pneubeck (no reviews) 2013/08/06 15:45:19 kErrorActivationRequired should lead to network_co
stevenjb 2013/08/06 20:23:55 Yes... that looks sound. Done.
42 error_name == NetworkConnectionHandler::kErrorCertificateRequired ||
43 error_name == NetworkConnectionHandler::kErrorConfigurationRequired || 62 error_name == NetworkConnectionHandler::kErrorConfigurationRequired ||
44 error_name == NetworkConnectionHandler::kErrorAuthenticationRequired) { 63 error_name == NetworkConnectionHandler::kErrorAuthenticationRequired) {
45 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( 64 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork(
46 service_path); 65 service_path);
47 return; 66 return;
48 } 67 }
49 if (error_name == NetworkConnectionHandler::kErrorConnected || 68 if (error_name == NetworkConnectionHandler::kErrorConnected ||
pneubeck (no reviews) 2013/08/06 15:45:19 merge all IFs with the same statement.
stevenjb 2013/08/06 20:23:55 I merged PassphraseRequired with Config/AuthReq an
50 error_name == NetworkConnectionHandler::kErrorConnecting) { 69 error_name == NetworkConnectionHandler::kErrorConnecting) {
51 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( 70 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings(
52 service_path); 71 service_path);
53 return; 72 return;
54 } 73 }
55 // Shill does not always provide a helpful error. In this case, show the 74 // Shill does not always provide a helpful error. In this case, show the
56 // configuration UI and a notification. See crbug.com/217033 for an example. 75 // configuration UI and a notification. See crbug.com/217033 for an example.
57 if (error_name == NetworkConnectionHandler::kErrorConnectFailed) { 76 if (error_name == NetworkConnectionHandler::kErrorConnectFailed) {
58 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( 77 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork(
59 service_path); 78 service_path);
60 } 79 }
61 ash::Shell::GetInstance()->system_tray_notifier()->network_state_notifier()-> 80 ash::Shell::GetInstance()->system_tray_notifier()->network_state_notifier()->
62 ShowNetworkConnectError(error_name, service_path); 81 ShowNetworkConnectError(error_name, service_path);
63 } 82 }
64 83
65 void OnConnectSucceeded(const std::string& service_path) { 84 void OnConnectSucceeded(const std::string& service_path) {
66 VLOG(1) << "Connect Succeeded for " << service_path; 85 NET_LOG_USER("Connect Succeeded", service_path);
67 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage( 86 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage(
68 NetworkObserver::ERROR_CONNECT_FAILED); 87 NetworkObserver::ERROR_CONNECT_FAILED);
69 } 88 }
70 89
90 // If |check_error_state| is true, error state for the network is checked,
91 // otherwise any current error state is ignored (e.g. for recently configured
92 // networks or repeat connect attempts).
93 void CallConnectToNetwork(const std::string& service_path,
94 bool check_error_state,
95 gfx::NativeWindow owning_window) {
96 NET_LOG_USER("ConnectToNetwork", service_path);
97
98 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
pneubeck (no reviews) 2013/08/06 15:45:19 if you did the change proposed above, this could b
stevenjb 2013/08/06 20:23:55 Actually, removing this will trigger a similar log
99 GetNetworkState(service_path);
100 if (!network) {
101 NET_LOG_USER("ConnectToNetwork: Not Found", service_path);
102 return;
103 }
104 if (network->type() == flimflam::kTypeCellular &&
105 (network->activation_state() != flimflam::kActivationStateActivated ||
106 network->cellular_out_of_credits())) {
107 network_connect::ActivateCellular(service_path);
108 return;
109 }
110
111 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage(
112 NetworkObserver::ERROR_CONNECT_FAILED);
113 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork(
114 service_path,
115 base::Bind(&OnConnectSucceeded, service_path),
116 base::Bind(&OnConnectFailed, service_path, owning_window),
117 check_error_state);
118 }
119
120 void OnActivateFailed(const std::string& service_path,
121 const std::string& error_name,
122 scoped_ptr<base::DictionaryValue> error_data) {
123 NET_LOG_ERROR("Unable to activate network", service_path);
124 }
125
126 void OnActivateSucceeded(const std::string& service_path) {
127 NET_LOG_USER("Activation Succeeded", service_path);
128 }
129
130 void OnConfigureFailed(const std::string& error_name,
131 scoped_ptr<base::DictionaryValue> error_data) {
132 NET_LOG_ERROR("Unable to configure network", "");
133 }
134
135 void OnConfigureSucceeded(const std::string& service_path) {
136 NET_LOG_USER("Configure Succeeded", service_path);
137 // After configuring a network, ignore any (possibly stale) error state.
138 const bool check_error_state = false;
139 CallConnectToNetwork(service_path, check_error_state, NULL);
140 }
141
142 void SetPropertiesFailed(const std::string& desc,
143 const std::string& service_path,
144 const std::string& config_error_name,
145 scoped_ptr<base::DictionaryValue> error_data) {
146 NET_LOG_ERROR(desc + ": Failed: " + config_error_name, service_path);
147 }
148
149 void SetPropertiesToClear(base::DictionaryValue* properties_to_set,
150 std::vector<std::string>* properties_to_clear) {
151 // Move empty string properties to properties_to_clear.
152 for (base::DictionaryValue::Iterator iter(*properties_to_set);
153 !iter.IsAtEnd(); iter.Advance()) {
154 if (iter.value().GetType() == base::Value::TYPE_STRING) {
pneubeck (no reviews) 2013/08/06 15:45:19 how about: std::string value_str; if (iter.value(
stevenjb 2013/08/06 20:23:55 Done.
155 std::string value_str;
156 iter.value().GetAsString(&value_str);
157 if (value_str.empty())
158 properties_to_clear->push_back(iter.key());
159 }
160 }
161 // Remove cleared properties from properties_to_set.
162 for (std::vector<std::string>::iterator iter = properties_to_clear->begin();
163 iter != properties_to_clear->end(); ++iter) {
164 properties_to_set->RemoveWithoutPathExpansion(*iter, NULL);
165 }
166 }
167
168 void ClearPropertiesAndConnect(
169 const std::string& service_path,
170 const std::vector<std::string>& properties_to_clear) {
171 NET_LOG_USER("ClearPropertiesAndConnect", service_path);
172 // After configuring a network, ignore any (possibly stale) error state.
173 const bool check_error_state = false;
174 if (properties_to_clear.empty()) {
175 CallConnectToNetwork(service_path, check_error_state, NULL);
pneubeck (no reviews) 2013/08/06 15:45:19 either document that parent=NULL is a valid argume
stevenjb 2013/08/06 20:23:55 Done.
176 } else {
177 NetworkHandler::Get()->network_configuration_handler()->ClearProperties(
pneubeck (no reviews) 2013/08/06 15:45:19 NetworkConfigurationHandler::ClearProperties could
stevenjb 2013/08/06 20:23:55 Done.
178 service_path,
179 properties_to_clear,
180 base::Bind(&CallConnectToNetwork,
181 service_path, check_error_state,
182 static_cast<gfx::NativeWindow>(NULL)),
183 base::Bind(&SetPropertiesFailed, "ClearProperties", service_path));
184 }
185 }
186
71 } // namespace 187 } // namespace
72 188
73 namespace network_connect { 189 namespace network_connect {
74 190
75 void ConnectToNetwork(const std::string& service_path) { 191 void ConnectToNetwork(const std::string& service_path,
76 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> 192 gfx::NativeWindow owning_window) {
77 GetNetworkState(service_path); 193 const bool check_error_state = true;
78 if (!network) 194 CallConnectToNetwork(service_path, check_error_state, owning_window);
195 }
196
197 void ActivateCellular(const std::string& service_path) {
198 NET_LOG_USER("ActivateCellular", service_path);
199 const DeviceState* cellular_device =
200 NetworkHandler::Get()->network_state_handler()->
201 GetDeviceStateByType(flimflam::kTypeCellular);
202 if (!cellular_device) {
203 NET_LOG_ERROR("ActivateCellular with no Device", service_path);
79 return; 204 return;
80 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage( 205 }
81 NetworkObserver::ERROR_CONNECT_FAILED); 206 if (!IsDirectActivatedCarrier(cellular_device->carrier())) {
82 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork( 207 // For non direct activation, show the mobile setup dialog which can be
208 // used to activate the network.
209 ash::Shell::GetInstance()->system_tray_delegate()->ShowMobileSetup(
210 service_path);
211 return;
212 }
213 const NetworkState* cellular =
214 NetworkHandler::Get()->network_state_handler()->
215 FirstNetworkByType(flimflam::kTypeCellular);
216 if (!cellular) {
pneubeck (no reviews) 2013/08/06 15:45:19 what if cellular->path() != service_path ? why not
stevenjb 2013/08/06 20:23:55 Yeah, this was converted a little too literally. D
217 NET_LOG_ERROR("ActivateCellular with no Service", service_path);
218 return;
219 }
220 if (cellular->activation_state() == flimflam::kActivationStateActivated) {
221 NET_LOG_ERROR("ActivateCellular for activated service", service_path);
222 return;
223 }
224
225 NetworkHandler::Get()->network_connection_handler()->ActivateNetwork(
83 service_path, 226 service_path,
84 base::Bind(&OnConnectSucceeded, service_path), 227 "", // carrier
85 base::Bind(&OnConnectFailed, service_path), 228 base::Bind(&OnActivateSucceeded, service_path),
86 true /* check_error_state */); 229 base::Bind(&OnActivateFailed, service_path));
230 }
231
232 void ConfigureNetworkAndConnect(const std::string& service_path,
233 const base::DictionaryValue& properties) {
234 NET_LOG_USER("ConfigureNetworkAndConnect", service_path);
235 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy());
236 std::vector<std::string> properties_to_clear;
237 SetPropertiesToClear(properties_to_set.get(), &properties_to_clear);
238 if (properties_to_set->empty()) {
239 ClearPropertiesAndConnect(service_path,
240 properties_to_clear);
241 } else {
242 NetworkHandler::Get()->network_configuration_handler()->SetProperties(
pneubeck (no reviews) 2013/08/06 15:45:19 NetworkConfigurationHandler::SetProperties could e
stevenjb 2013/08/06 20:23:55 Done.
243 service_path,
244 *properties_to_set,
245 base::Bind(&ClearPropertiesAndConnect,
246 service_path,
247 properties_to_clear),
248 base::Bind(&SetPropertiesFailed, "SetProperties", service_path));
249 }
250 }
251
252 void CreateConfigurationAndConnect(base::DictionaryValue* properties,
253 bool shared) {
pneubeck (no reviews) 2013/08/06 15:45:19 |shared| is not used.
stevenjb 2013/08/06 20:23:55 Oops. Fixed this on the calling side, removed 'sha
254 NET_LOG_USER("CreateConfigurationAndConnect", "");
255 const NetworkProfile* profile =
pneubeck (no reviews) 2013/08/06 15:45:19 enclose this in a 'if (!shared)' log error if Get
stevenjb 2013/08/06 20:23:55 Done.
256 NetworkHandler::Get()->network_profile_handler()->
257 GetDefaultUserProfile();
258 if (profile) {
259 properties->SetStringWithoutPathExpansion(
260 flimflam::kProfileProperty, profile->path);
pneubeck (no reviews) 2013/08/06 15:45:19 set a 'std::string profile_path' in the if clauses
stevenjb 2013/08/06 20:23:55 Done.
261 } else {
262 properties->SetStringWithoutPathExpansion(
263 flimflam::kProfileProperty,
264 NetworkProfileHandler::kSharedProfilePath);
265 }
266 NetworkHandler::Get()->network_configuration_handler()->CreateConfiguration(
267 *properties,
268 base::Bind(&OnConfigureSucceeded),
269 base::Bind(&OnConfigureFailed));
87 } 270 }
88 271
89 string16 ErrorString(const std::string& error) { 272 string16 ErrorString(const std::string& error) {
90 if (error.empty()) 273 if (error.empty())
91 return string16(); 274 return string16();
92 if (error == flimflam::kErrorOutOfRange) 275 if (error == flimflam::kErrorOutOfRange)
93 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OUT_OF_RANGE); 276 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OUT_OF_RANGE);
94 if (error == flimflam::kErrorPinMissing) 277 if (error == flimflam::kErrorPinMissing)
95 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_PIN_MISSING); 278 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_PIN_MISSING);
96 if (error == flimflam::kErrorDhcpFailed) 279 if (error == flimflam::kErrorDhcpFailed)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if (StringToLowerASCII(error) == 333 if (StringToLowerASCII(error) ==
151 StringToLowerASCII(std::string(flimflam::kUnknownString))) { 334 StringToLowerASCII(std::string(flimflam::kUnknownString))) {
152 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); 335 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN);
153 } 336 }
154 return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR, 337 return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR,
155 UTF8ToUTF16(error)); 338 UTF8ToUTF16(error));
156 } 339 }
157 340
158 } // network_connect 341 } // network_connect
159 } // ash 342 } // ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698