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

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 2.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 // Returns true for carriers that can be activated through Shill instead of
40 // through a WebUI dialog.
41 bool IsDirectActivatedCarrier(const std::string& carrier) {
42 if (carrier == shill::kCarrierSprint)
43 return true;
44 return false;
45 }
46
31 void OnConnectFailed(const std::string& service_path, 47 void OnConnectFailed(const std::string& service_path,
48 gfx::NativeWindow owning_window,
32 const std::string& error_name, 49 const std::string& error_name,
33 scoped_ptr<base::DictionaryValue> error_data) { 50 scoped_ptr<base::DictionaryValue> error_data) {
34 VLOG(1) << "Connect Failed for " << service_path << ": " << error_name; 51 NET_LOG_ERROR("Connect Failed: " + error_name, service_path);
35 if (error_name == NetworkConnectionHandler::kErrorPassphraseRequired) { 52
36 // TODO(stevenjb): Possibly add inline UI to handle passphrase entry here. 53 if (error_name == NetworkConnectionHandler::kErrorPassphraseRequired ||
37 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork(
38 service_path);
39 return;
40 }
41 if (error_name == NetworkConnectionHandler::kErrorActivationRequired ||
42 error_name == NetworkConnectionHandler::kErrorCertificateRequired ||
43 error_name == NetworkConnectionHandler::kErrorConfigurationRequired || 54 error_name == NetworkConnectionHandler::kErrorConfigurationRequired ||
44 error_name == NetworkConnectionHandler::kErrorAuthenticationRequired) { 55 error_name == NetworkConnectionHandler::kErrorAuthenticationRequired) {
45 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( 56 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork(
46 service_path); 57 service_path);
47 return; 58 return;
48 } 59 }
60
61 if (error_name == NetworkConnectionHandler::kErrorCertificateRequired) {
62 ash::Shell::GetInstance()->system_tray_delegate()->EnrollOrConfigureNetwork(
63 service_path, owning_window);
64 return;
65 }
66
67 if (error_name == NetworkConnectionHandler::kErrorActivationRequired) {
68 network_connect::ActivateCellular(service_path);
69 return;
70 }
71
49 if (error_name == NetworkConnectionHandler::kErrorConnected || 72 if (error_name == NetworkConnectionHandler::kErrorConnected ||
50 error_name == NetworkConnectionHandler::kErrorConnecting) { 73 error_name == NetworkConnectionHandler::kErrorConnecting) {
51 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( 74 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings(
52 service_path); 75 service_path);
53 return; 76 return;
54 } 77 }
78
55 // Shill does not always provide a helpful error. In this case, show the 79 // 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. 80 // configuration UI and a notification. See crbug.com/217033 for an example.
57 if (error_name == NetworkConnectionHandler::kErrorConnectFailed) { 81 if (error_name == NetworkConnectionHandler::kErrorConnectFailed) {
58 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( 82 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork(
59 service_path); 83 service_path);
60 } 84 }
61 ash::Shell::GetInstance()->system_tray_notifier()->network_state_notifier()-> 85 ash::Shell::GetInstance()->system_tray_notifier()->network_state_notifier()->
62 ShowNetworkConnectError(error_name, service_path); 86 ShowNetworkConnectError(error_name, service_path);
63 } 87 }
64 88
65 void OnConnectSucceeded(const std::string& service_path) { 89 void OnConnectSucceeded(const std::string& service_path) {
66 VLOG(1) << "Connect Succeeded for " << service_path; 90 NET_LOG_USER("Connect Succeeded", service_path);
67 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage( 91 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage(
68 NetworkObserver::ERROR_CONNECT_FAILED); 92 NetworkObserver::ERROR_CONNECT_FAILED);
69 } 93 }
70 94
95 // If |check_error_state| is true, error state for the network is checked,
96 // otherwise any current error state is ignored (e.g. for recently configured
97 // networks or repeat connect attempts). |owning_window| will be used to parent
98 // any configuration UI on failure and may be NULL (in which case the default
99 // window will be used).
100 void CallConnectToNetwork(const std::string& service_path,
101 bool check_error_state,
102 gfx::NativeWindow owning_window) {
103 NET_LOG_USER("ConnectToNetwork", service_path);
104
105 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage(
106 NetworkObserver::ERROR_CONNECT_FAILED);
107
108 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork(
109 service_path,
110 base::Bind(&OnConnectSucceeded, service_path),
111 base::Bind(&OnConnectFailed, service_path, owning_window),
112 check_error_state);
113 }
114
115 void OnActivateFailed(const std::string& service_path,
116 const std::string& error_name,
117 scoped_ptr<base::DictionaryValue> error_data) {
118 NET_LOG_ERROR("Unable to activate network", service_path);
119 }
120
121 void OnActivateSucceeded(const std::string& service_path) {
122 NET_LOG_USER("Activation Succeeded", service_path);
123 }
124
125 void OnConfigureFailed(const std::string& error_name,
126 scoped_ptr<base::DictionaryValue> error_data) {
127 NET_LOG_ERROR("Unable to configure network", "");
128 }
129
130 void OnConfigureSucceeded(const std::string& service_path) {
131 NET_LOG_USER("Configure Succeeded", service_path);
132 // After configuring a network, ignore any (possibly stale) error state.
133 const bool check_error_state = false;
134 const gfx::NativeWindow owning_window = NULL;
135 CallConnectToNetwork(service_path, check_error_state, owning_window);
136 }
137
138 void SetPropertiesFailed(const std::string& desc,
139 const std::string& service_path,
140 const std::string& config_error_name,
141 scoped_ptr<base::DictionaryValue> error_data) {
142 NET_LOG_ERROR(desc + ": Failed: " + config_error_name, service_path);
143 }
144
145 void SetPropertiesToClear(base::DictionaryValue* properties_to_set,
146 std::vector<std::string>* properties_to_clear) {
147 // Move empty string properties to properties_to_clear.
148 for (base::DictionaryValue::Iterator iter(*properties_to_set);
149 !iter.IsAtEnd(); iter.Advance()) {
150 std::string value_str;
151 if (iter.value().GetAsString(&value_str) && value_str.empty())
152 properties_to_clear->push_back(iter.key());
153 }
154 // Remove cleared properties from properties_to_set.
155 for (std::vector<std::string>::iterator iter = properties_to_clear->begin();
156 iter != properties_to_clear->end(); ++iter) {
157 properties_to_set->RemoveWithoutPathExpansion(*iter, NULL);
158 }
159 }
160
161 void ClearPropertiesAndConnect(
162 const std::string& service_path,
163 const std::vector<std::string>& properties_to_clear) {
164 NET_LOG_USER("ClearPropertiesAndConnect", service_path);
165 // After configuring a network, ignore any (possibly stale) error state.
166 const bool check_error_state = false;
167 const gfx::NativeWindow owning_window = NULL;
168 NetworkHandler::Get()->network_configuration_handler()->ClearProperties(
169 service_path,
170 properties_to_clear,
171 base::Bind(&CallConnectToNetwork,
172 service_path, check_error_state,
173 owning_window),
174 base::Bind(&SetPropertiesFailed, "ClearProperties", service_path));
175 }
176
71 } // namespace 177 } // namespace
72 178
73 namespace network_connect { 179 namespace network_connect {
74 180
75 void ConnectToNetwork(const std::string& service_path) { 181 void ConnectToNetwork(const std::string& service_path,
76 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> 182 gfx::NativeWindow owning_window) {
183 const bool check_error_state = true;
184 CallConnectToNetwork(service_path, check_error_state, owning_window);
185 }
186
187 void ActivateCellular(const std::string& service_path) {
188 NET_LOG_USER("ActivateCellular", service_path);
189 const DeviceState* cellular_device =
190 NetworkHandler::Get()->network_state_handler()->
191 GetDeviceStateByType(flimflam::kTypeCellular);
192 if (!cellular_device) {
193 NET_LOG_ERROR("ActivateCellular with no Device", service_path);
194 return;
195 }
196 if (!IsDirectActivatedCarrier(cellular_device->carrier())) {
197 // For non direct activation, show the mobile setup dialog which can be
198 // used to activate the network.
199 ash::Shell::GetInstance()->system_tray_delegate()->ShowMobileSetup(
200 service_path);
201 return;
202 }
203 const NetworkState* cellular =
204 NetworkHandler::Get()->network_state_handler()->
77 GetNetworkState(service_path); 205 GetNetworkState(service_path);
78 if (!network) 206 if (!cellular || cellular->type() != flimflam::kTypeCellular) {
207 NET_LOG_ERROR("ActivateCellular with no Service", service_path);
79 return; 208 return;
80 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage( 209 }
81 NetworkObserver::ERROR_CONNECT_FAILED); 210 if (cellular->activation_state() == flimflam::kActivationStateActivated) {
82 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork( 211 NET_LOG_ERROR("ActivateCellular for activated service", service_path);
212 return;
213 }
214
215 NetworkHandler::Get()->network_connection_handler()->ActivateNetwork(
83 service_path, 216 service_path,
84 base::Bind(&OnConnectSucceeded, service_path), 217 "", // carrier
85 base::Bind(&OnConnectFailed, service_path), 218 base::Bind(&OnActivateSucceeded, service_path),
86 true /* check_error_state */); 219 base::Bind(&OnActivateFailed, service_path));
220 }
221
222 void ConfigureNetworkAndConnect(const std::string& service_path,
223 const base::DictionaryValue& properties) {
224 NET_LOG_USER("ConfigureNetworkAndConnect", service_path);
225 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy());
226 std::vector<std::string> properties_to_clear;
227 SetPropertiesToClear(properties_to_set.get(), &properties_to_clear);
228 NetworkHandler::Get()->network_configuration_handler()->SetProperties(
229 service_path,
230 *properties_to_set,
231 base::Bind(&ClearPropertiesAndConnect,
232 service_path,
233 properties_to_clear),
234 base::Bind(&SetPropertiesFailed, "SetProperties", service_path));
235 }
236
237 void CreateConfigurationAndConnect(base::DictionaryValue* properties,
238 bool shared) {
239 NET_LOG_USER("CreateConfigurationAndConnect", "");
240 std::string profile_path;
241 if (!shared) {
242 const NetworkProfile* profile =
243 NetworkHandler::Get()->network_profile_handler()->
244 GetDefaultUserProfile();
245 if (!profile) {
246 NET_LOG_ERROR("CreateConfiguration: No User Profile", "");
247 return;
248 }
249 profile_path = profile->path;
250 } else {
251 profile_path = NetworkProfileHandler::kSharedProfilePath;
252 }
253 properties->SetStringWithoutPathExpansion(
254 flimflam::kProfileProperty, profile_path);
255 NetworkHandler::Get()->network_configuration_handler()->CreateConfiguration(
256 *properties,
257 base::Bind(&OnConfigureSucceeded),
258 base::Bind(&OnConfigureFailed));
87 } 259 }
88 260
89 string16 ErrorString(const std::string& error) { 261 string16 ErrorString(const std::string& error) {
90 if (error.empty()) 262 if (error.empty())
91 return string16(); 263 return string16();
92 if (error == flimflam::kErrorOutOfRange) 264 if (error == flimflam::kErrorOutOfRange)
93 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OUT_OF_RANGE); 265 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OUT_OF_RANGE);
94 if (error == flimflam::kErrorPinMissing) 266 if (error == flimflam::kErrorPinMissing)
95 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_PIN_MISSING); 267 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_PIN_MISSING);
96 if (error == flimflam::kErrorDhcpFailed) 268 if (error == flimflam::kErrorDhcpFailed)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if (StringToLowerASCII(error) == 322 if (StringToLowerASCII(error) ==
151 StringToLowerASCII(std::string(flimflam::kUnknownString))) { 323 StringToLowerASCII(std::string(flimflam::kUnknownString))) {
152 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); 324 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN);
153 } 325 }
154 return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR, 326 return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR,
155 UTF8ToUTF16(error)); 327 UTF8ToUTF16(error));
156 } 328 }
157 329
158 } // network_connect 330 } // network_connect
159 } // ash 331 } // ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698