network_state_list_detailed_view.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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
  3. // found in the LICENSE file.
  4. #ifndef ASH_SYSTEM_NETWORK_NETWORK_STATE_LIST_DETAILED_VIEW_H_
  5. #define ASH_SYSTEM_NETWORK_NETWORK_STATE_LIST_DETAILED_VIEW_H_
  6. #include <string>
  7. #include "ash/login_status.h"
  8. #include "ash/system/network/tray_network_state_observer.h"
  9. #include "ash/system/tray/tray_detailed_view.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "base/timer/timer.h"
  12. #include "chromeos/services/network_config/public/mojom/cros_network_config.mojom-forward.h"
  13. #include "chromeos/services/network_config/public/mojom/network_types.mojom-forward.h"
  14. namespace views {
  15. class Button;
  16. }
  17. namespace ash {
  18. class TrayNetworkStateModel;
  19. bool CanNetworkConnect(
  20. chromeos::network_config::mojom::ConnectionStateType connection_state,
  21. chromeos::network_config::mojom::NetworkType type,
  22. chromeos::network_config::mojom::ActivationStateType activation_state,
  23. bool is_connectable,
  24. std::string sim_eid);
  25. // Exported for tests.
  26. class ASH_EXPORT NetworkStateListDetailedView
  27. : public TrayDetailedView,
  28. public TrayNetworkStateObserver {
  29. public:
  30. NetworkStateListDetailedView(const NetworkStateListDetailedView&) = delete;
  31. NetworkStateListDetailedView& operator=(const NetworkStateListDetailedView&) =
  32. delete;
  33. ~NetworkStateListDetailedView() override;
  34. void Init();
  35. void ToggleInfoBubbleForTesting();
  36. // views::View:
  37. const char* GetClassName() const override;
  38. protected:
  39. enum ListType { LIST_TYPE_NETWORK, LIST_TYPE_VPN };
  40. NetworkStateListDetailedView(DetailedViewDelegate* delegate,
  41. ListType list_type,
  42. LoginStatus login);
  43. // Refreshes the network list.
  44. virtual void UpdateNetworkList() = 0;
  45. // Checks whether |view| represents a network in the list. If yes, sets
  46. // |guid| to the network's guid and returns |true|. Otherwise,
  47. // leaves |guid| unchanged and returns |false|.
  48. virtual bool IsNetworkEntry(views::View* view, std::string* guid) const = 0;
  49. // Called when the network model changes or when a network icon changes.
  50. void Update();
  51. TrayNetworkStateModel* model() { return model_; }
  52. private:
  53. class InfoBubble;
  54. // TrayNetworkStateObserver:
  55. void ActiveNetworkStateChanged() override;
  56. void NetworkListChanged() override;
  57. // TrayDetailedView:
  58. void HandleViewClicked(views::View* view) override;
  59. void CreateExtraTitleRowButtons() override;
  60. // Implementation of 'HandleViewClicked' once networks are received.
  61. void HandleViewClickedImpl(
  62. chromeos::network_config::mojom::NetworkStatePropertiesPtr network);
  63. // Launches the WebUI settings in a browser and closes the system menu.
  64. void ShowSettings();
  65. // Update info and settings buttons in header.
  66. void UpdateHeaderButtons();
  67. // Update scanning progress bar.
  68. void UpdateScanningBar();
  69. // Create and manage the network info bubble.
  70. void ToggleInfoBubble();
  71. bool ResetInfoBubble();
  72. void OnInfoBubbleDestroyed();
  73. views::View* CreateNetworkInfoView();
  74. // Scan and start timer to periodically request a network scan.
  75. void ScanAndStartTimer();
  76. // Request a network scan.
  77. void CallRequestScan();
  78. bool IsWifiEnabled();
  79. // Type of list (all networks or vpn)
  80. ListType list_type_;
  81. // Track login state.
  82. LoginStatus login_;
  83. TrayNetworkStateModel* model_;
  84. views::Button* info_button_;
  85. views::Button* settings_button_;
  86. // A small bubble for displaying network info.
  87. InfoBubble* info_bubble_;
  88. // Timer for starting and stopping network scans.
  89. base::RepeatingTimer network_scan_repeating_timer_;
  90. base::WeakPtrFactory<NetworkStateListDetailedView> weak_ptr_factory_{this};
  91. };
  92. } // namespace ash
  93. #endif // ASH_SYSTEM_NETWORK_NETWORK_STATE_LIST_DETAILED_VIEW_H_