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

Side by Side Diff: chrome/browser/chromeos/options/vpn_config_view.cc

Issue 10050030: chromeos: Stop leaking combobox models in VPNConfigView dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix link issues Created 8 years, 8 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
« no previous file with comments | « chrome/browser/chromeos/options/vpn_config_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/vpn_config_view.h" 5 #include "chrome/browser/chromeos/options/vpn_config_view.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/chromeos/cros/cros_library.h" 10 #include "chrome/browser/chromeos/cros/cros_library.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 break; 47 break;
48 } 48 }
49 NOTREACHED(); 49 NOTREACHED();
50 return string16(); 50 return string16();
51 } 51 }
52 52
53 } // namespace 53 } // namespace
54 54
55 namespace chromeos { 55 namespace chromeos {
56 56
57 namespace internal {
58
57 class ProviderTypeComboboxModel : public ui::ComboboxModel { 59 class ProviderTypeComboboxModel : public ui::ComboboxModel {
58 public: 60 public:
59 ProviderTypeComboboxModel() {} 61 ProviderTypeComboboxModel();
60 virtual ~ProviderTypeComboboxModel() {} 62 virtual ~ProviderTypeComboboxModel();
61 63
62 // Overridden from ui::ComboboxModel: 64 // Overridden from ui::ComboboxModel:
63 virtual int GetItemCount() const OVERRIDE { 65 virtual int GetItemCount() const OVERRIDE;
64 return chromeos::PROVIDER_TYPE_MAX; 66 virtual string16 GetItemAt(int index) OVERRIDE;
65 }
66 virtual string16 GetItemAt(int index) OVERRIDE {
67 ProviderType type = static_cast<ProviderType>(index);
68 return ProviderTypeToString(type);
69 }
70 67
71 private: 68 private:
72 DISALLOW_COPY_AND_ASSIGN(ProviderTypeComboboxModel); 69 DISALLOW_COPY_AND_ASSIGN(ProviderTypeComboboxModel);
73 }; 70 };
74 71
75 class ServerCACertComboboxModel : public ui::ComboboxModel { 72 class VpnServerCACertComboboxModel : public ui::ComboboxModel {
76 public: 73 public:
77 explicit ServerCACertComboboxModel(CertLibrary* cert_library) 74 explicit VpnServerCACertComboboxModel(CertLibrary* cert_library);
78 : cert_library_(cert_library) { 75 virtual ~VpnServerCACertComboboxModel();
79 }
80 virtual ~ServerCACertComboboxModel() {}
81 76
82 // Overridden from ui::ComboboxModel: 77 // Overridden from ui::ComboboxModel:
83 virtual int GetItemCount() const OVERRIDE { 78 virtual int GetItemCount() const OVERRIDE;
84 if (cert_library_->CertificatesLoading()) 79 virtual string16 GetItemAt(int index) OVERRIDE;
85 return 1; // "Loading"
86 // "Default" + certs.
87 return cert_library_->GetCACertificates().Size() + 1;
88 }
89 virtual string16 GetItemAt(int index) OVERRIDE {
90 if (cert_library_->CertificatesLoading())
91 return l10n_util::GetStringUTF16(
92 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_LOADING);
93 if (index == 0)
94 return l10n_util::GetStringUTF16(
95 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA_DEFAULT);
96 int cert_index = index - 1;
97 return cert_library_->GetCACertificates().GetDisplayStringAt(cert_index);
98 }
99 80
100 private: 81 private:
101 CertLibrary* cert_library_; 82 CertLibrary* cert_library_;
102 83
103 DISALLOW_COPY_AND_ASSIGN(ServerCACertComboboxModel); 84 DISALLOW_COPY_AND_ASSIGN(VpnServerCACertComboboxModel);
104 }; 85 };
105 86
106 class UserCertComboboxModel : public ui::ComboboxModel { 87 class VpnUserCertComboboxModel : public ui::ComboboxModel {
107 public: 88 public:
108 explicit UserCertComboboxModel(CertLibrary* cert_library) 89 explicit VpnUserCertComboboxModel(CertLibrary* cert_library);
109 : cert_library_(cert_library) { 90 virtual ~VpnUserCertComboboxModel();
110 }
111 virtual ~UserCertComboboxModel() {}
112 91
113 // Overridden from ui::ComboboxModel: 92 // Overridden from ui::ComboboxModel:
114 virtual int GetItemCount() const OVERRIDE { 93 virtual int GetItemCount() const OVERRIDE;
115 if (cert_library_->CertificatesLoading()) 94 virtual string16 GetItemAt(int index) OVERRIDE;
116 return 1; // "Loading"
117 int num_certs = cert_library_->GetUserCertificates().Size();
118 if (num_certs == 0)
119 return 1; // "None installed"
120 return num_certs;
121 }
122 virtual string16 GetItemAt(int index) OVERRIDE {
123 if (cert_library_->CertificatesLoading()) {
124 return l10n_util::GetStringUTF16(
125 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_LOADING);
126 }
127 if (cert_library_->GetUserCertificates().Size() == 0) {
128 return l10n_util::GetStringUTF16(
129 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USER_CERT_NONE_INSTALLED);
130 }
131 return cert_library_->GetUserCertificates().GetDisplayStringAt(index);
132 }
133 95
134 private: 96 private:
135 CertLibrary* cert_library_; 97 CertLibrary* cert_library_;
136 DISALLOW_COPY_AND_ASSIGN(UserCertComboboxModel); 98
99 DISALLOW_COPY_AND_ASSIGN(VpnUserCertComboboxModel);
137 }; 100 };
138 101
102 // ProviderTypeComboboxModel ---------------------------------------------------
103
104 ProviderTypeComboboxModel::ProviderTypeComboboxModel() {
105 }
106
107 ProviderTypeComboboxModel::~ProviderTypeComboboxModel() {
108 }
109
110 int ProviderTypeComboboxModel::GetItemCount() const {
111 return PROVIDER_TYPE_MAX;
112 }
113
114 string16 ProviderTypeComboboxModel::GetItemAt(int index) {
115 ProviderType type = static_cast<ProviderType>(index);
116 return ProviderTypeToString(type);
117 }
118
119 // VpnServerCACertComboboxModel ------------------------------------------------
120
121 VpnServerCACertComboboxModel::VpnServerCACertComboboxModel(
122 CertLibrary* cert_library)
123 : cert_library_(cert_library) {
124 }
125
126 VpnServerCACertComboboxModel::~VpnServerCACertComboboxModel() {
127 }
128
129 int VpnServerCACertComboboxModel::GetItemCount() const {
130 if (cert_library_->CertificatesLoading())
131 return 1; // "Loading"
132 // "Default" + certs.
133 return cert_library_->GetCACertificates().Size() + 1;
134 }
135
136 string16 VpnServerCACertComboboxModel::GetItemAt(int index) {
137 if (cert_library_->CertificatesLoading())
138 return l10n_util::GetStringUTF16(
139 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_LOADING);
140 if (index == 0)
141 return l10n_util::GetStringUTF16(
142 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA_DEFAULT);
143 int cert_index = index - 1;
144 return cert_library_->GetCACertificates().GetDisplayStringAt(cert_index);
145 }
146
147 // VpnUserCertComboboxModel ----------------------------------------------------
148
149 VpnUserCertComboboxModel::VpnUserCertComboboxModel(
150 CertLibrary* cert_library)
151 : cert_library_(cert_library) {
152 }
153
154 VpnUserCertComboboxModel::~VpnUserCertComboboxModel() {
155 }
156
157 int VpnUserCertComboboxModel::GetItemCount() const {
158 if (cert_library_->CertificatesLoading())
159 return 1; // "Loading"
160 int num_certs = cert_library_->GetUserCertificates().Size();
161 if (num_certs == 0)
162 return 1; // "None installed"
163 return num_certs;
164 }
165
166 string16 VpnUserCertComboboxModel::GetItemAt(int index) {
167 if (cert_library_->CertificatesLoading()) {
168 return l10n_util::GetStringUTF16(
169 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_LOADING);
170 }
171 if (cert_library_->GetUserCertificates().Size() == 0) {
172 return l10n_util::GetStringUTF16(
173 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USER_CERT_NONE_INSTALLED);
174 }
175 return cert_library_->GetUserCertificates().GetDisplayStringAt(index);
176 }
177
178 } // namespace internal
179
139 VPNConfigView::VPNConfigView(NetworkConfigView* parent, VirtualNetwork* vpn) 180 VPNConfigView::VPNConfigView(NetworkConfigView* parent, VirtualNetwork* vpn)
140 : ChildNetworkConfigView(parent, vpn), 181 : ChildNetworkConfigView(parent, vpn),
141 cert_library_(NULL) { 182 cert_library_(NULL) {
142 Init(vpn); 183 Init(vpn);
143 } 184 }
144 185
145 VPNConfigView::VPNConfigView(NetworkConfigView* parent) 186 VPNConfigView::VPNConfigView(NetworkConfigView* parent)
146 : ChildNetworkConfigView(parent), 187 : ChildNetworkConfigView(parent),
147 cert_library_(NULL) { 188 cert_library_(NULL) {
148 Init(NULL); 189 Init(NULL);
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 ParseVPNUIProperty(&user_cert_ui_data_, vpn, onc::vpn::kClientCertRef); 437 ParseVPNUIProperty(&user_cert_ui_data_, vpn, onc::vpn::kClientCertRef);
397 ParseVPNUIProperty(&username_ui_data_, vpn, onc::vpn::kUsername); 438 ParseVPNUIProperty(&username_ui_data_, vpn, onc::vpn::kUsername);
398 ParseVPNUIProperty(&user_passphrase_ui_data_, vpn, onc::vpn::kPassword); 439 ParseVPNUIProperty(&user_passphrase_ui_data_, vpn, onc::vpn::kPassword);
399 ParseVPNUIProperty(&group_name_ui_data_, vpn, onc::vpn::kGroup); 440 ParseVPNUIProperty(&group_name_ui_data_, vpn, onc::vpn::kGroup);
400 } 441 }
401 442
402 views::GridLayout* layout = views::GridLayout::CreatePanel(this); 443 views::GridLayout* layout = views::GridLayout::CreatePanel(this);
403 SetLayoutManager(layout); 444 SetLayoutManager(layout);
404 445
405 // VPN may require certificates, so always set the library and observe. 446 // VPN may require certificates, so always set the library and observe.
406 cert_library_ = chromeos::CrosLibrary::Get()->GetCertLibrary(); 447 cert_library_ = CrosLibrary::Get()->GetCertLibrary();
407 448
408 // Setup a callback if certificates are yet to be loaded. 449 // Setup a callback if certificates are yet to be loaded.
409 if (!cert_library_->CertificatesLoaded()) 450 if (!cert_library_->CertificatesLoaded())
410 cert_library_->AddObserver(this); 451 cert_library_->AddObserver(this);
411 452
412 int column_view_set_id = 0; 453 int column_view_set_id = 0;
413 views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); 454 views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id);
414 // Label. 455 // Label.
415 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, 456 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,
416 views::GridLayout::USE_PREF, 0, 0); 457 views::GridLayout::USE_PREF, 0, 0);
417 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); 458 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing);
418 // Textfield, combobox. 459 // Textfield, combobox.
419 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, 460 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
420 views::GridLayout::USE_PREF, 0, 461 views::GridLayout::USE_PREF, 0,
421 ChildNetworkConfigView::kInputFieldMinWidth); 462 ChildNetworkConfigView::kInputFieldMinWidth);
422 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); 463 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing);
423 // Policy indicator. 464 // Policy indicator.
424 column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 0, 465 column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 0,
425 views::GridLayout::USE_PREF, 0, 0); 466 views::GridLayout::USE_PREF, 0, 0);
426 467
427 // Initialize members. 468 // Initialize members.
428 service_text_modified_ = false; 469 service_text_modified_ = false;
429 if (vpn) { 470 if (vpn) {
430 provider_type_ = vpn->provider_type(); 471 provider_type_ = vpn->provider_type();
431 // Sets enable_* based on the provider type which we use to control 472 // Sets enable_* based on the provider type which we use to control
432 // which controls to make visible. 473 // which controls to make visible.
433 UpdateControlsToEnable(); 474 UpdateControlsToEnable();
434 } else { 475 } else {
435 // Set the default provider type. 476 // Set the default provider type.
436 provider_type_ = chromeos::PROVIDER_TYPE_L2TP_IPSEC_PSK; 477 provider_type_ = PROVIDER_TYPE_L2TP_IPSEC_PSK;
437 // Provider Type is user selectable, so enable all controls during init. 478 // Provider Type is user selectable, so enable all controls during init.
438 enable_psk_passphrase_ = true; 479 enable_psk_passphrase_ = true;
439 enable_user_cert_ = true; 480 enable_user_cert_ = true;
440 enable_server_ca_cert_ = true; 481 enable_server_ca_cert_ = true;
441 enable_otp_ = true; 482 enable_otp_ = true;
442 enable_group_name_ = true; 483 enable_group_name_ = true;
443 } 484 }
444 485
445 // Server label and input. 486 // Server label and input.
446 // Only provide Server name when configuring a new VPN. 487 // Only provide Server name when configuring a new VPN.
(...skipping 24 matching lines...) Expand all
471 layout->AddView(service_text_); 512 layout->AddView(service_text_);
472 service_textfield_ = NULL; 513 service_textfield_ = NULL;
473 } 514 }
474 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 515 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
475 516
476 // Provider type label and select. 517 // Provider type label and select.
477 layout->StartRow(0, column_view_set_id); 518 layout->StartRow(0, column_view_set_id);
478 layout->AddView(new views::Label(l10n_util::GetStringUTF16( 519 layout->AddView(new views::Label(l10n_util::GetStringUTF16(
479 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PROVIDER_TYPE))); 520 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PROVIDER_TYPE)));
480 if (!vpn) { 521 if (!vpn) {
481 provider_type_combobox_ = 522 provider_type_combobox_model_.reset(
482 new views::Combobox(new ProviderTypeComboboxModel()); 523 new internal::ProviderTypeComboboxModel);
524 provider_type_combobox_ = new views::Combobox(
525 provider_type_combobox_model_.get());
483 provider_type_combobox_->set_listener(this); 526 provider_type_combobox_->set_listener(this);
484 layout->AddView(provider_type_combobox_); 527 layout->AddView(provider_type_combobox_);
485 provider_type_text_label_ = NULL; 528 provider_type_text_label_ = NULL;
486 } else { 529 } else {
487 provider_type_text_label_ = 530 provider_type_text_label_ =
488 new views::Label(ProviderTypeToString(provider_type_)); 531 new views::Label(ProviderTypeToString(provider_type_));
489 provider_type_text_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 532 provider_type_text_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
490 layout->AddView(provider_type_text_label_); 533 layout->AddView(provider_type_text_label_);
491 provider_type_combobox_ = NULL; 534 provider_type_combobox_ = NULL;
492 } 535 }
(...skipping 18 matching lines...) Expand all
511 } 554 }
512 555
513 // Server CA certificate 556 // Server CA certificate
514 // Only provide Server CA when configuring a new VPN. 557 // Only provide Server CA when configuring a new VPN.
515 if (!vpn) { 558 if (!vpn) {
516 layout->StartRow(0, column_view_set_id); 559 layout->StartRow(0, column_view_set_id);
517 server_ca_cert_label_ = 560 server_ca_cert_label_ =
518 new views::Label(l10n_util::GetStringUTF16( 561 new views::Label(l10n_util::GetStringUTF16(
519 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA)); 562 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA));
520 layout->AddView(server_ca_cert_label_); 563 layout->AddView(server_ca_cert_label_);
521 ServerCACertComboboxModel* server_ca_cert_model = 564 server_ca_cert_combobox_model_.reset(
522 new ServerCACertComboboxModel(cert_library_); 565 new internal::VpnServerCACertComboboxModel(cert_library_));
523 server_ca_cert_combobox_ = new views::Combobox(server_ca_cert_model); 566 server_ca_cert_combobox_ = new views::Combobox(
567 server_ca_cert_combobox_model_.get());
524 layout->AddView(server_ca_cert_combobox_); 568 layout->AddView(server_ca_cert_combobox_);
525 layout->AddView(new ControlledSettingIndicatorView(ca_cert_ui_data_)); 569 layout->AddView(new ControlledSettingIndicatorView(ca_cert_ui_data_));
526 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 570 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
527 } else { 571 } else {
528 server_ca_cert_label_ = NULL; 572 server_ca_cert_label_ = NULL;
529 server_ca_cert_combobox_ = NULL; 573 server_ca_cert_combobox_ = NULL;
530 } 574 }
531 575
532 // User certificate label and input. 576 // User certificate label and input.
533 if (enable_user_cert_) { 577 if (enable_user_cert_) {
534 layout->StartRow(0, column_view_set_id); 578 layout->StartRow(0, column_view_set_id);
535 user_cert_label_ = new views::Label(l10n_util::GetStringUTF16( 579 user_cert_label_ = new views::Label(l10n_util::GetStringUTF16(
536 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_CERT)); 580 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_CERT));
537 layout->AddView(user_cert_label_); 581 layout->AddView(user_cert_label_);
538 UserCertComboboxModel* user_cert_model = 582 user_cert_combobox_model_.reset(
539 new UserCertComboboxModel(cert_library_); 583 new internal::VpnUserCertComboboxModel(cert_library_));
540 user_cert_combobox_ = new views::Combobox(user_cert_model); 584 user_cert_combobox_ = new views::Combobox(user_cert_combobox_model_.get());
541 user_cert_combobox_->set_listener(this); 585 user_cert_combobox_->set_listener(this);
542 layout->AddView(user_cert_combobox_); 586 layout->AddView(user_cert_combobox_);
543 layout->AddView(new ControlledSettingIndicatorView(user_cert_ui_data_)); 587 layout->AddView(new ControlledSettingIndicatorView(user_cert_ui_data_));
544 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 588 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
545 } else { 589 } else {
546 user_cert_label_ = NULL; 590 user_cert_label_ = NULL;
547 user_cert_combobox_ = NULL; 591 user_cert_combobox_ = NULL;
548 } 592 }
549 593
550 // Username label and input. 594 // Username label and input.
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 std::string vpn_type; 863 std::string vpn_type;
820 if (!vpn_dict || !vpn_dict->GetString(onc::kType, &vpn_type)) 864 if (!vpn_dict || !vpn_dict->GetString(onc::kType, &vpn_type))
821 return; 865 return;
822 866
823 property_ui_data->ParseOncProperty( 867 property_ui_data->ParseOncProperty(
824 network->ui_data(), onc, 868 network->ui_data(), onc,
825 base::StringPrintf("%s.%s.%s", onc::kVPN, vpn_type.c_str(), key.c_str())); 869 base::StringPrintf("%s.%s.%s", onc::kVPN, vpn_type.c_str(), key.c_str()));
826 } 870 }
827 871
828 } // namespace chromeos 872 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/options/vpn_config_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698