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

Side by Side Diff: ash/system/network/network_list.cc

Issue 2883283004: Merged Tether and cellular network types in System Tray. (Closed)
Patch Set: Merged Tether and cellular network types in System Tray. Created 3 years, 6 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
« no previous file with comments | « ash/system/network/network_list.h ('k') | chrome/browser/chromeos/tether/tether_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/network/network_list.h" 5 #include "ash/system/network/network_list.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/shell_port.h" 10 #include "ash/shell_port.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 views::ToggleButton* toggle_; 171 views::ToggleButton* toggle_;
172 172
173 // TrayPopupItemStyle used to configure labels and buttons. 173 // TrayPopupItemStyle used to configure labels and buttons.
174 std::unique_ptr<TrayPopupItemStyle> style_; 174 std::unique_ptr<TrayPopupItemStyle> style_;
175 175
176 DISALLOW_COPY_AND_ASSIGN(SectionHeaderRowView); 176 DISALLOW_COPY_AND_ASSIGN(SectionHeaderRowView);
177 }; 177 };
178 178
179 namespace { 179 namespace {
180 180
181 class CellularHeaderRowView : public NetworkListView::SectionHeaderRowView { 181 class MobileHeaderRowView : public NetworkListView::SectionHeaderRowView {
182 public: 182 public:
183 CellularHeaderRowView() 183 MobileHeaderRowView()
184 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_MOBILE) {} 184 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_MOBILE) {}
185 185
186 ~CellularHeaderRowView() override {} 186 ~MobileHeaderRowView() override {}
187 187
188 const char* GetClassName() const override { return "CellularHeaderRowView"; } 188 const char* GetClassName() const override { return "MobileHeaderRowView"; }
189 189
190 protected: 190 protected:
191 void OnToggleToggled(bool is_on) override { 191 void OnToggleToggled(bool is_on) override {
192 NetworkStateHandler* handler = 192 NetworkStateHandler* handler =
193 NetworkHandler::Get()->network_state_handler(); 193 NetworkHandler::Get()->network_state_handler();
194 handler->SetTechnologyEnabled(NetworkTypePattern::Cellular(), is_on, 194 // The Mobile network type contains both Cellular and Tether technologies,
195 chromeos::network_handler::ErrorCallback()); 195 // though one or both of these may be unavailable. When Cellular technology
196 // is available, the enabled value of Tether depends on the enabled value of
197 // Cellular, so the toggle should only explicitly change the enabled value
198 // of Cellular.
199 // However, if Cellular technology is not available but Tether technology is
200 // available, the toggle should explicitly change the enabled value of
201 // Tether.
202 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) {
203 handler->SetTechnologyEnabled(NetworkTypePattern::Cellular(), is_on,
204 chromeos::network_handler::ErrorCallback());
205 } else {
206 DCHECK(handler->IsTechnologyAvailable(NetworkTypePattern::Tether()));
207
208 handler->SetTechnologyEnabled(NetworkTypePattern::Tether(), is_on,
209 chromeos::network_handler::ErrorCallback());
210 }
196 } 211 }
197 212
198 private: 213 private:
199 DISALLOW_COPY_AND_ASSIGN(CellularHeaderRowView); 214 DISALLOW_COPY_AND_ASSIGN(MobileHeaderRowView);
200 }; 215 };
201 216
202 class TetherHeaderRowView : public NetworkListView::SectionHeaderRowView {
203 public:
204 TetherHeaderRowView()
205 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_TETHER) {}
206
207 ~TetherHeaderRowView() override {}
208
209 const char* GetClassName() const override { return "TetherHeaderRowView"; }
210
211 protected:
212 void OnToggleToggled(bool is_on) override {
213 // TODO (hansberry): Persist toggle to settings/preferences.
214 }
215
216 private:
217 DISALLOW_COPY_AND_ASSIGN(TetherHeaderRowView);
218 };
219 217
220 class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView { 218 class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView {
221 public: 219 public:
222 WifiHeaderRowView() 220 WifiHeaderRowView()
223 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI), 221 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI),
224 join_(nullptr) {} 222 join_(nullptr) {}
225 223
226 ~WifiHeaderRowView() override {} 224 ~WifiHeaderRowView() override {}
227 225
228 void SetIsOn(bool enabled) override { 226 void SetIsOn(bool enabled) override {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 }; 287 };
290 288
291 } // namespace 289 } // namespace
292 290
293 // NetworkListView: 291 // NetworkListView:
294 292
295 NetworkListView::NetworkListView(SystemTrayItem* owner, LoginStatus login) 293 NetworkListView::NetworkListView(SystemTrayItem* owner, LoginStatus login)
296 : NetworkStateListDetailedView(owner, LIST_TYPE_NETWORK, login), 294 : NetworkStateListDetailedView(owner, LIST_TYPE_NETWORK, login),
297 needs_relayout_(false), 295 needs_relayout_(false),
298 no_wifi_networks_view_(nullptr), 296 no_wifi_networks_view_(nullptr),
299 no_cellular_networks_view_(nullptr), 297 no_cellular_networks_view_(nullptr),
Kyle Horimoto 2017/06/05 17:49:30 These "cellular" views need to be renamed appropri
lesliewatkins 2017/06/05 19:41:42 Done.
300 cellular_header_view_(nullptr), 298 cellular_header_view_(nullptr),
301 tether_header_view_(nullptr),
302 wifi_header_view_(nullptr), 299 wifi_header_view_(nullptr),
303 cellular_separator_view_(nullptr), 300 cellular_separator_view_(nullptr),
304 tether_separator_view_(nullptr),
305 wifi_separator_view_(nullptr), 301 wifi_separator_view_(nullptr),
306 connection_warning_(nullptr) {} 302 connection_warning_(nullptr) {}
307 303
308 NetworkListView::~NetworkListView() { 304 NetworkListView::~NetworkListView() {
309 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 305 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
310 } 306 }
311 307
312 void NetworkListView::UpdateNetworkList() { 308 void NetworkListView::UpdateNetworkList() {
313 CHECK(scroll_content()); 309 CHECK(scroll_content());
314 310
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 return network1->connecting; 381 return network1->connecting;
386 return network1->guid.compare(network2->guid) < 0; 382 return network1->guid.compare(network2->guid) < 0;
387 } 383 }
388 384
389 private: 385 private:
390 static int GetOrder(const chromeos::NetworkState* network) { 386 static int GetOrder(const chromeos::NetworkState* network) {
391 if (!network) 387 if (!network)
392 return 999; 388 return 999;
393 if (network->Matches(NetworkTypePattern::Ethernet())) 389 if (network->Matches(NetworkTypePattern::Ethernet()))
394 return 0; 390 return 0;
395 if (network->Matches(NetworkTypePattern::Cellular())) 391 if (network->Matches(NetworkTypePattern::Cellular()))
Kyle Horimoto 2017/06/05 17:49:30 Should be Mobile, right?
lesliewatkins 2017/06/05 19:41:42 I'm not sure. As written, all it will do is priori
396 return 1; 392 return 1;
397 if (network->Matches(NetworkTypePattern::Mobile())) 393 if (network->Matches(NetworkTypePattern::Mobile()))
398 return 2; 394 return 2;
399 if (network->Matches(NetworkTypePattern::WiFi())) 395 if (network->Matches(NetworkTypePattern::WiFi()))
400 return 3; 396 return 3;
401 return 4; 397 return 4;
402 } 398 }
403 399
404 NetworkStateHandler* handler_; 400 NetworkStateHandler* handler_;
405 }; 401 };
(...skipping 18 matching lines...) Expand all
424 network, network_icon::ICON_TYPE_MENU_LIST); 420 network, network_icon::ICON_TYPE_MENU_LIST);
425 info->image = 421 info->image =
426 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); 422 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST);
427 info->disable = 423 info->disable =
428 (network->activation_state() == shill::kActivationStateActivating) || 424 (network->activation_state() == shill::kActivationStateActivating) ||
429 prohibited_by_policy; 425 prohibited_by_policy;
430 info->connected = network->IsConnectedState(); 426 info->connected = network->IsConnectedState();
431 info->connecting = network->IsConnectingState(); 427 info->connecting = network->IsConnectingState();
432 if (network->Matches(NetworkTypePattern::WiFi())) 428 if (network->Matches(NetworkTypePattern::WiFi()))
433 info->type = NetworkInfo::Type::WIFI; 429 info->type = NetworkInfo::Type::WIFI;
434 else if (network->Matches(NetworkTypePattern::Cellular())) 430 else if (network->Matches(NetworkTypePattern::Mobile()))
435 info->type = NetworkInfo::Type::CELLULAR; 431 info->type = NetworkInfo::Type::MOBILE;
436 else if (network->Matches(NetworkTypePattern::Tether()))
437 info->type = NetworkInfo::Type::TETHER;
438 if (prohibited_by_policy) { 432 if (prohibited_by_policy) {
439 info->tooltip = 433 info->tooltip =
440 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); 434 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED);
441 } 435 }
442 if (!animating && network->IsConnectingState()) 436 if (!animating && network->IsConnectingState())
443 animating = true; 437 animating = true;
444 } 438 }
445 if (animating) 439 if (animating)
446 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); 440 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
447 else 441 else
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 const bool using_proxy = NetworkHandler::Get()->ui_proxy_config_service() && 497 const bool using_proxy = NetworkHandler::Get()->ui_proxy_config_service() &&
504 NetworkHandler::Get() 498 NetworkHandler::Get()
505 ->ui_proxy_config_service() 499 ->ui_proxy_config_service()
506 ->HasDefaultNetworkProxyConfigured(); 500 ->HasDefaultNetworkProxyConfigured();
507 if (using_vpn || using_proxy) { 501 if (using_vpn || using_proxy) {
508 if (!connection_warning_) 502 if (!connection_warning_)
509 connection_warning_ = CreateConnectionWarning(); 503 connection_warning_ = CreateConnectionWarning();
510 PlaceViewAtIndex(connection_warning_, index++); 504 PlaceViewAtIndex(connection_warning_, index++);
511 } 505 }
512 506
513 // First add high-priority networks (not Wi-Fi nor cellular). 507 // First add high-priority networks (not Wi-Fi nor cellular).
Kyle Horimoto 2017/06/05 17:49:30 mobile Also, while you're here, change "not" to "
lesliewatkins 2017/06/05 19:41:42 Done.
514 std::unique_ptr<std::set<std::string>> new_guids = 508 std::unique_ptr<std::set<std::string>> new_guids =
515 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index); 509 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index);
516 index += new_guids->size(); 510 index += new_guids->size();
517 511
518 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { 512 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular()) ||
519 index = UpdateSectionHeaderRow( 513 handler->IsTechnologyAvailable(NetworkTypePattern::Tether())) {
520 NetworkTypePattern::Cellular(), 514 bool is_enabled =
521 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index, 515 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()) ||
522 &cellular_header_view_, &cellular_separator_view_); 516 handler->IsTechnologyEnabled(NetworkTypePattern::Tether());
517
518 index = UpdateSectionHeaderRow(NetworkTypePattern::Cellular(), is_enabled,
519 index, &cellular_header_view_,
520 &cellular_separator_view_);
523 } 521 }
524 522
525 // Cellular initializing. 523 // Cellular initializing.
Kyle Horimoto 2017/06/05 17:49:30 stevenjb@: Should this "initializing" section be c
526 int cellular_message_id = network_icon::GetCellularUninitializedMsg(); 524 int cellular_message_id = network_icon::GetCellularUninitializedMsg();
527 if (!cellular_message_id && 525 if (!cellular_message_id &&
528 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && 526 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) &&
529 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { 527 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) {
530 cellular_message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS; 528 cellular_message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS;
531 } 529 }
532 UpdateInfoLabel(cellular_message_id, index, &no_cellular_networks_view_); 530 UpdateInfoLabel(cellular_message_id, index, &no_cellular_networks_view_);
533 if (cellular_message_id) 531 if (cellular_message_id)
534 ++index; 532 ++index;
535 533
536 // Add cellular networks. 534 // Add cellular and Tether networks.
537 std::unique_ptr<std::set<std::string>> new_cellular_guids = 535 std::unique_ptr<std::set<std::string>> new_cellular_guids =
538 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); 536 UpdateNetworkChildren(NetworkInfo::Type::MOBILE, index);
539 index += new_cellular_guids->size(); 537 index += new_cellular_guids->size();
540 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); 538 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end());
541 539
542 // TODO (hansberry): Audit existing usage of NonVirtual and consider changing
543 // it to include Tether. See crbug.com/693647.
544 if (handler->IsTechnologyAvailable(NetworkTypePattern::Tether())) {
545 index = UpdateSectionHeaderRow(
546 NetworkTypePattern::Tether(),
547 handler->IsTechnologyEnabled(NetworkTypePattern::Tether()), index,
548 &tether_header_view_, &tether_separator_view_);
549
550 // TODO (hansberry): Should a message similar to
551 // IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS be shown if Tether technology is
552 // enabled but no networks are around?
553
554 // Add Tether networks.
555 std::unique_ptr<std::set<std::string>> new_tether_guids =
556 UpdateNetworkChildren(NetworkInfo::Type::TETHER, index);
557 index += new_tether_guids->size();
558 new_guids->insert(new_tether_guids->begin(), new_tether_guids->end());
559 }
560
561 index = UpdateSectionHeaderRow( 540 index = UpdateSectionHeaderRow(
562 NetworkTypePattern::WiFi(), 541 NetworkTypePattern::WiFi(),
563 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, 542 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index,
564 &wifi_header_view_, &wifi_separator_view_); 543 &wifi_header_view_, &wifi_separator_view_);
565 544
566 // "Wifi Enabled / Disabled". 545 // "Wifi Enabled / Disabled".
567 int wifi_message_id = 0; 546 int wifi_message_id = 0;
568 if (network_list_.empty()) { 547 if (network_list_.empty()) {
569 wifi_message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) 548 wifi_message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi())
570 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED 549 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 PlaceViewAtIndex(info_label, insertion_index); 665 PlaceViewAtIndex(info_label, insertion_index);
687 *info_label_ptr = info_label; 666 *info_label_ptr = info_label;
688 } 667 }
689 668
690 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, 669 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern,
691 bool enabled, 670 bool enabled,
692 int child_index, 671 int child_index,
693 SectionHeaderRowView** view, 672 SectionHeaderRowView** view,
694 views::Separator** separator_view) { 673 views::Separator** separator_view) {
695 if (!*view) { 674 if (!*view) {
696 if (pattern.Equals(NetworkTypePattern::Cellular())) 675 if (pattern.MatchesPattern(NetworkTypePattern::Mobile()))
697 *view = new CellularHeaderRowView(); 676 *view = new MobileHeaderRowView();
698 else if (pattern.Equals(NetworkTypePattern::Tether()))
699 *view = new TetherHeaderRowView();
700 else if (pattern.Equals(NetworkTypePattern::WiFi())) 677 else if (pattern.Equals(NetworkTypePattern::WiFi()))
701 *view = new WifiHeaderRowView(); 678 *view = new WifiHeaderRowView();
702 else 679 else
703 NOTREACHED(); 680 NOTREACHED();
704 (*view)->Init(enabled); 681 (*view)->Init(enabled);
705 } 682 }
706 // Show or hide a separator above the header. The separator should only be 683 // Show or hide a separator above the header. The separator should only be
707 // visible when the header row is not at the top of the list. 684 // visible when the header row is not at the top of the list.
708 if (child_index > 0) { 685 if (child_index > 0) {
709 if (!*separator_view) 686 if (!*separator_view)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets( 740 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets(
764 0, 0, 0, kTrayPopupLabelRightPadding))); 741 0, 0, 0, kTrayPopupLabelRightPadding)));
765 742
766 // Nothing to the right of the text. 743 // Nothing to the right of the text.
767 connection_warning->SetContainerVisible(TriView::Container::END, false); 744 connection_warning->SetContainerVisible(TriView::Container::END, false);
768 return connection_warning; 745 return connection_warning;
769 } 746 }
770 747
771 } // namespace tray 748 } // namespace tray
772 } // namespace ash 749 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/network/network_list.h ('k') | chrome/browser/chromeos/tether/tether_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698