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

Side by Side Diff: chrome/browser/chromeos/options/wimax_config_view.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) 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/chromeos/options/wimax_config_view.h" 5 #include "chrome/browser/chromeos/options/wimax_config_view.h"
6 6
7 #include "ash/system/chromeos/network/network_connect.h"
7 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
8 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chromeos/cros/network_library.h"
11 #include "chrome/browser/chromeos/enrollment_dialog_view.h" 11 #include "chrome/browser/chromeos/enrollment_dialog_view.h"
12 #include "chrome/browser/chromeos/login/startup_utils.h" 12 #include "chrome/browser/chromeos/login/startup_utils.h"
13 #include "chrome/browser/chromeos/options/network_connect.h"
13 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chromeos/login/login_state.h" 15 #include "chromeos/login/login_state.h"
16 #include "chromeos/network/network_configuration_handler.h"
17 #include "chromeos/network/network_event_log.h"
18 #include "chromeos/network/network_profile.h"
19 #include "chromeos/network/network_profile_handler.h"
20 #include "chromeos/network/network_state.h"
21 #include "chromeos/network/network_state_handler.h"
15 #include "chromeos/network/onc/onc_constants.h" 22 #include "chromeos/network/onc/onc_constants.h"
16 #include "grit/chromium_strings.h" 23 #include "grit/chromium_strings.h"
17 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
18 #include "grit/locale_settings.h" 25 #include "grit/locale_settings.h"
19 #include "grit/theme_resources.h" 26 #include "grit/theme_resources.h"
27 #include "third_party/cros_system_api/dbus/service_constants.h"
20 #include "ui/base/events/event.h" 28 #include "ui/base/events/event.h"
21 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/views/controls/button/checkbox.h" 31 #include "ui/views/controls/button/checkbox.h"
24 #include "ui/views/controls/button/image_button.h" 32 #include "ui/views/controls/button/image_button.h"
25 #include "ui/views/controls/label.h" 33 #include "ui/views/controls/label.h"
26 #include "ui/views/controls/textfield/textfield.h" 34 #include "ui/views/controls/textfield/textfield.h"
27 #include "ui/views/layout/grid_layout.h" 35 #include "ui/views/layout/grid_layout.h"
28 #include "ui/views/layout/layout_constants.h" 36 #include "ui/views/layout/layout_constants.h"
29 #include "ui/views/widget/widget.h" 37 #include "ui/views/widget/widget.h"
30 #include "ui/views/window/dialog_client_view.h" 38 #include "ui/views/window/dialog_client_view.h"
31 39
32 namespace chromeos { 40 namespace chromeos {
33 41
34 WimaxConfigView::WimaxConfigView(NetworkConfigView* parent, WimaxNetwork* wimax) 42 namespace {
35 : ChildNetworkConfigView(parent, wimax), 43
44 void ShillError(const std::string& function,
45 const std::string& error_name,
46 scoped_ptr<base::DictionaryValue> error_data) {
47 NET_LOG_ERROR("Shill Error from WimaxConfigView: " + error_name, function);
48 }
49
50 } // namespace
51
52 WimaxConfigView::WimaxConfigView(NetworkConfigView* parent,
53 const std::string& service_path)
54 : ChildNetworkConfigView(parent, service_path),
36 identity_label_(NULL), 55 identity_label_(NULL),
37 identity_textfield_(NULL), 56 identity_textfield_(NULL),
38 save_credentials_checkbox_(NULL), 57 save_credentials_checkbox_(NULL),
39 share_network_checkbox_(NULL), 58 share_network_checkbox_(NULL),
40 shared_network_label_(NULL), 59 shared_network_label_(NULL),
41 passphrase_label_(NULL), 60 passphrase_label_(NULL),
42 passphrase_textfield_(NULL), 61 passphrase_textfield_(NULL),
43 passphrase_visible_button_(NULL), 62 passphrase_visible_button_(NULL),
44 error_label_(NULL) { 63 error_label_(NULL) {
45 Init(wimax); 64 Init(service_path);
46 } 65 }
47 66
48 WimaxConfigView::~WimaxConfigView() { 67 WimaxConfigView::~WimaxConfigView() {
49 } 68 }
50 69
51 string16 WimaxConfigView::GetTitle() const { 70 string16 WimaxConfigView::GetTitle() const {
52 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_JOIN_WIMAX_NETWORKS); 71 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_JOIN_WIMAX_NETWORKS);
53 } 72 }
54 73
55 views::View* WimaxConfigView::GetInitiallyFocusedView() { 74 views::View* WimaxConfigView::GetInitiallyFocusedView() {
(...skipping 13 matching lines...) Expand all
69 // check if empty). 88 // check if empty).
70 // If the network requires a passphrase, make sure it is the right length. 89 // If the network requires a passphrase, make sure it is the right length.
71 return passphrase_textfield_ && !passphrase_textfield_->text().empty(); 90 return passphrase_textfield_ && !passphrase_textfield_->text().empty();
72 } 91 }
73 92
74 void WimaxConfigView::UpdateDialogButtons() { 93 void WimaxConfigView::UpdateDialogButtons() {
75 parent_->GetDialogClientView()->UpdateDialogButtons(); 94 parent_->GetDialogClientView()->UpdateDialogButtons();
76 } 95 }
77 96
78 void WimaxConfigView::UpdateErrorLabel() { 97 void WimaxConfigView::UpdateErrorLabel() {
79 std::string error_msg; 98 base::string16 error_msg;
80 if (!service_path_.empty()) { 99 if (!service_path_.empty()) {
81 NetworkLibrary* cros = NetworkLibrary::Get(); 100 const NetworkState* wimax = NetworkHandler::Get()->network_state_handler()->
82 const WimaxNetwork* wimax = cros->FindWimaxNetworkByPath(service_path_); 101 GetNetworkState(service_path_);
83 if (wimax && wimax->failed()) { 102 if (wimax && wimax->connection_state() == flimflam::kStateFailure)
84 bool passphrase_empty = wimax->eap_passphrase().empty(); 103 error_msg = ash::network_connect::ErrorString(wimax->error());
85 switch (wimax->error()) {
86 case ERROR_BAD_PASSPHRASE:
87 if (!passphrase_empty) {
88 error_msg = l10n_util::GetStringUTF8(
89 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_PASSPHRASE);
90 }
91 break;
92 case ERROR_BAD_WEPKEY:
93 if (!passphrase_empty) {
94 error_msg = l10n_util::GetStringUTF8(
95 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_WEPKEY);
96 }
97 break;
98 default:
99 error_msg = wimax->GetErrorString();
100 break;
101 }
102 }
103 } 104 }
104 if (!error_msg.empty()) { 105 if (!error_msg.empty()) {
105 error_label_->SetText(UTF8ToUTF16(error_msg)); 106 error_label_->SetText(error_msg);
106 error_label_->SetVisible(true); 107 error_label_->SetVisible(true);
107 } else { 108 } else {
108 error_label_->SetVisible(false); 109 error_label_->SetVisible(false);
109 } 110 }
110 } 111 }
111 112
112 void WimaxConfigView::ContentsChanged(views::Textfield* sender, 113 void WimaxConfigView::ContentsChanged(views::Textfield* sender,
113 const string16& new_contents) { 114 const string16& new_contents) {
114 UpdateDialogButtons(); 115 UpdateDialogButtons();
115 } 116 }
(...skipping 14 matching lines...) Expand all
130 passphrase_textfield_->SetObscured(!passphrase_textfield_->IsObscured()); 131 passphrase_textfield_->SetObscured(!passphrase_textfield_->IsObscured());
131 passphrase_visible_button_->SetToggled( 132 passphrase_visible_button_->SetToggled(
132 !passphrase_textfield_->IsObscured()); 133 !passphrase_textfield_->IsObscured());
133 } 134 }
134 } else { 135 } else {
135 NOTREACHED(); 136 NOTREACHED();
136 } 137 }
137 } 138 }
138 139
139 bool WimaxConfigView::Login() { 140 bool WimaxConfigView::Login() {
140 NetworkLibrary* cros = NetworkLibrary::Get(); 141 const NetworkState* wimax = NetworkHandler::Get()->network_state_handler()->
141 WimaxNetwork* wimax = cros->FindWimaxNetworkByPath(service_path_); 142 GetNetworkState(service_path_);
142 if (!wimax) { 143 if (!wimax) {
143 // Shill no longer knows about this wimax network (edge case). 144 // Shill no longer knows about this network (edge case).
144 // TODO(stevenjb): Add a notification (chromium-os13225). 145 // TODO(stevenjb): Add notification for this.
145 LOG(WARNING) << "Wimax network: " << service_path_ << " no longer exists."; 146 NET_LOG_ERROR("Network not found", service_path_);
146 return true; 147 return true; // Close dialog
147 } 148 }
148 wimax->SetEAPIdentity(GetEapIdentity()); 149 base::DictionaryValue properties;
149 wimax->SetEAPPassphrase(GetEapPassphrase()); 150 properties.SetStringWithoutPathExpansion(
150 wimax->SetSaveCredentials(GetSaveCredentials()); 151 flimflam::kEapIdentityProperty, GetEapIdentity());
151 bool share_default = (wimax->profile_type() != PROFILE_USER); 152 properties.SetStringWithoutPathExpansion(
152 bool share = GetShareNetwork(share_default); 153 flimflam::kEapPasswordProperty, GetEapPassphrase());
153 wimax->SetEnrollmentDelegate( 154 properties.SetBooleanWithoutPathExpansion(
154 CreateEnrollmentDelegate(GetWidget()->GetNativeWindow(), 155 flimflam::kSaveCredentialsProperty, GetSaveCredentials());
155 wimax->name(), 156 // If the 'Share' checkbox has been changed we need to set the Profile
156 ProfileManager::GetLastUsedProfile())); 157 // property of the network which will request that Shill move the network.
157 cros->ConnectToWimaxNetwork(wimax, share); 158 bool wimax_shared = !wimax->IsPrivate();
158 // Connection failures are responsible for updating the UI, including 159 bool share_network = GetShareNetwork(wimax_shared);
159 // reopening dialogs. 160 if (share_network != wimax_shared) {
161 std::string profile_path;
162 if (share_network) {
163 profile_path = NetworkProfileHandler::kSharedProfilePath;
164 } else {
165 const NetworkProfile* profile =
166 NetworkHandler::Get()->network_profile_handler()->
167 GetDefaultUserProfile();
168 if (profile)
169 profile_path = profile->path;
170 else
171 NET_LOG_ERROR("Unable to set user profile", service_path_);
172 }
173 if (!profile_path.empty()) {
174 properties.SetStringWithoutPathExpansion(
175 flimflam::kProfileProperty, profile_path);
176 }
177 }
178 ash::network_connect::ConfigureNetworkAndConnect(service_path_, properties);
160 return true; // dialog will be closed 179 return true; // dialog will be closed
161 } 180 }
162 181
163 std::string WimaxConfigView::GetEapIdentity() const { 182 std::string WimaxConfigView::GetEapIdentity() const {
164 DCHECK(identity_textfield_); 183 DCHECK(identity_textfield_);
165 return UTF16ToUTF8(identity_textfield_->text()); 184 return UTF16ToUTF8(identity_textfield_->text());
166 } 185 }
167 186
168 std::string WimaxConfigView::GetEapPassphrase() const { 187 std::string WimaxConfigView::GetEapPassphrase() const {
169 return passphrase_textfield_ ? UTF16ToUTF8(passphrase_textfield_->text()) : 188 return passphrase_textfield_ ? UTF16ToUTF8(passphrase_textfield_->text()) :
170 std::string(); 189 std::string();
171 } 190 }
172 191
173 bool WimaxConfigView::GetSaveCredentials() const { 192 bool WimaxConfigView::GetSaveCredentials() const {
174 return save_credentials_checkbox_ ? save_credentials_checkbox_->checked() : 193 return save_credentials_checkbox_ ? save_credentials_checkbox_->checked() :
175 false; 194 false;
176 } 195 }
177 196
178 bool WimaxConfigView::GetShareNetwork(bool share_default) const { 197 bool WimaxConfigView::GetShareNetwork(bool share_default) const {
179 return share_network_checkbox_ ? share_network_checkbox_->checked() : 198 return share_network_checkbox_ ? share_network_checkbox_->checked() :
180 share_default; 199 share_default;
181 } 200 }
182 201
183 void WimaxConfigView::Cancel() { 202 void WimaxConfigView::Cancel() {
184 } 203 }
185 204
186 void WimaxConfigView::Init(WimaxNetwork* wimax) { 205 void WimaxConfigView::Init(const std::string& service_path) {
187 DCHECK(wimax); 206 const NetworkState* wimax = NetworkHandler::Get()->network_state_handler()->
207 GetNetworkState(service_path);
208 DCHECK(wimax && wimax->type() == flimflam::kTypeWimax);
209
188 WifiConfigView::ParseWiFiEAPUIProperty( 210 WifiConfigView::ParseWiFiEAPUIProperty(
189 &save_credentials_ui_data_, wimax, onc::eap::kSaveCredentials); 211 &save_credentials_ui_data_, wimax, onc::eap::kSaveCredentials);
190 WifiConfigView::ParseWiFiEAPUIProperty( 212 WifiConfigView::ParseWiFiEAPUIProperty(
191 &identity_ui_data_, wimax, onc::eap::kIdentity); 213 &identity_ui_data_, wimax, onc::eap::kIdentity);
192 WifiConfigView::ParseWiFiUIProperty( 214 WifiConfigView::ParseWiFiUIProperty(
193 &passphrase_ui_data_, wimax, onc::wifi::kPassphrase); 215 &passphrase_ui_data_, wimax, onc::wifi::kPassphrase);
194 216
195 views::GridLayout* layout = views::GridLayout::CreatePanel(this); 217 views::GridLayout* layout = views::GridLayout::CreatePanel(this);
196 SetLayoutManager(layout); 218 SetLayoutManager(layout);
197 219
(...skipping 25 matching lines...) Expand all
223 // Identity 245 // Identity
224 layout->StartRow(0, column_view_set_id); 246 layout->StartRow(0, column_view_set_id);
225 string16 identity_label_text = l10n_util::GetStringUTF16( 247 string16 identity_label_text = l10n_util::GetStringUTF16(
226 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY); 248 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY);
227 identity_label_ = new views::Label(identity_label_text); 249 identity_label_ = new views::Label(identity_label_text);
228 layout->AddView(identity_label_); 250 layout->AddView(identity_label_);
229 identity_textfield_ = new views::Textfield( 251 identity_textfield_ = new views::Textfield(
230 views::Textfield::STYLE_DEFAULT); 252 views::Textfield::STYLE_DEFAULT);
231 identity_textfield_->SetAccessibleName(identity_label_text); 253 identity_textfield_->SetAccessibleName(identity_label_text);
232 identity_textfield_->SetController(this); 254 identity_textfield_->SetController(this);
233 const std::string& eap_identity = wimax->eap_identity();
234 identity_textfield_->SetText(UTF8ToUTF16(eap_identity));
235 identity_textfield_->SetEnabled(identity_ui_data_.IsEditable()); 255 identity_textfield_->SetEnabled(identity_ui_data_.IsEditable());
236 layout->AddView(identity_textfield_); 256 layout->AddView(identity_textfield_);
237 layout->AddView(new ControlledSettingIndicatorView(identity_ui_data_)); 257 layout->AddView(new ControlledSettingIndicatorView(identity_ui_data_));
238 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 258 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
239 259
240 // Passphrase input 260 // Passphrase input
241 layout->StartRow(0, column_view_set_id); 261 layout->StartRow(0, column_view_set_id);
242 string16 passphrase_label_text = l10n_util::GetStringUTF16( 262 string16 passphrase_label_text = l10n_util::GetStringUTF16(
243 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE); 263 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE);
244 passphrase_label_ = new views::Label(passphrase_label_text); 264 passphrase_label_ = new views::Label(passphrase_label_text);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // Checkboxes. 309 // Checkboxes.
290 310
291 if (LoginState::Get()->IsUserLoggedIn()) { 311 if (LoginState::Get()->IsUserLoggedIn()) {
292 // Save credentials 312 // Save credentials
293 layout->StartRow(0, column_view_set_id); 313 layout->StartRow(0, column_view_set_id);
294 save_credentials_checkbox_ = new views::Checkbox( 314 save_credentials_checkbox_ = new views::Checkbox(
295 l10n_util::GetStringUTF16( 315 l10n_util::GetStringUTF16(
296 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SAVE_CREDENTIALS)); 316 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SAVE_CREDENTIALS));
297 save_credentials_checkbox_->SetEnabled( 317 save_credentials_checkbox_->SetEnabled(
298 save_credentials_ui_data_.IsEditable()); 318 save_credentials_ui_data_.IsEditable());
299 save_credentials_checkbox_->SetChecked(wimax->save_credentials());
300 layout->SkipColumns(1); 319 layout->SkipColumns(1);
301 layout->AddView(save_credentials_checkbox_); 320 layout->AddView(save_credentials_checkbox_);
302 layout->AddView( 321 layout->AddView(
303 new ControlledSettingIndicatorView(save_credentials_ui_data_)); 322 new ControlledSettingIndicatorView(save_credentials_ui_data_));
304 323
305 // Share network 324 // Share network
306 if (wimax->profile_type() == PROFILE_NONE && wimax->passphrase_required()) { 325 if (!wimax->IsPrivate()) {
pneubeck (no reviews) 2013/08/06 15:45:19 is comment for WifiConfigView must be profile_pat
stevenjb 2013/08/06 20:23:55 Done.
307 layout->StartRow(0, column_view_set_id); 326 layout->StartRow(0, column_view_set_id);
308 share_network_checkbox_ = new views::Checkbox( 327 share_network_checkbox_ = new views::Checkbox(
309 l10n_util::GetStringUTF16( 328 l10n_util::GetStringUTF16(
310 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHARE_NETWORK)); 329 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHARE_NETWORK));
311 share_network_checkbox_->SetEnabled(true); 330 share_network_checkbox_->SetEnabled(true);
312 share_network_checkbox_->SetChecked(false); // Default to unshared. 331 share_network_checkbox_->SetChecked(true);
pneubeck (no reviews) 2013/08/06 15:45:19 why?
stevenjb 2013/08/06 20:23:55 Updated.
313 layout->SkipColumns(1); 332 layout->SkipColumns(1);
314 layout->AddView(share_network_checkbox_); 333 layout->AddView(share_network_checkbox_);
315 } 334 }
316 } 335 }
317 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 336 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
318 337
319 // Create an error label. 338 // Create an error label.
320 layout->StartRow(0, column_view_set_id); 339 layout->StartRow(0, column_view_set_id);
321 layout->SkipColumns(1); 340 layout->SkipColumns(1);
322 error_label_ = new views::Label(); 341 error_label_ = new views::Label();
323 error_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 342 error_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
324 error_label_->SetEnabledColor(SK_ColorRED); 343 error_label_->SetEnabledColor(SK_ColorRED);
325 layout->AddView(error_label_); 344 layout->AddView(error_label_);
326 345
327 UpdateErrorLabel(); 346 UpdateErrorLabel();
347
348 if (wimax) {
349 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
350 service_path,
351 base::Bind(&WimaxConfigView::InitFromProperties, AsWeakPtr()),
352 base::Bind(&ShillError, "GetProperties"));
353 }
354 }
355
356 void WimaxConfigView::InitFromProperties(
357 const std::string& service_path,
358 const base::DictionaryValue& properties) {
359 // EapIdentity
360 std::string eap_identity;
361 properties.GetStringWithoutPathExpansion(
362 flimflam::kEapIdentityProperty, &eap_identity);
363 identity_textfield_->SetText(UTF8ToUTF16(eap_identity));
364
365 // Save credentials
366 if (save_credentials_checkbox_) {
367 bool save_credentials = false;
368 properties.GetBooleanWithoutPathExpansion(
369 flimflam::kSaveCredentialsProperty, &save_credentials);
370 save_credentials_checkbox_->SetChecked(save_credentials);
371 }
328 } 372 }
329 373
330 void WimaxConfigView::InitFocus() { 374 void WimaxConfigView::InitFocus() {
331 views::View* view_to_focus = GetInitiallyFocusedView(); 375 views::View* view_to_focus = GetInitiallyFocusedView();
332 if (view_to_focus) 376 if (view_to_focus)
333 view_to_focus->RequestFocus(); 377 view_to_focus->RequestFocus();
334 } 378 }
335 379
336 } // namespace chromeos 380 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698