active_network_icon.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright 2019 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_ACTIVE_NETWORK_ICON_H_
  5. #define ASH_SYSTEM_NETWORK_ACTIVE_NETWORK_ICON_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "ash/ash_export.h"
  10. #include "ash/system/network/network_icon.h"
  11. #include "ash/system/network/tray_network_state_observer.h"
  12. #include "base/time/time.h"
  13. #include "base/timer/timer.h"
  14. #include "chromeos/services/network_config/public/mojom/cros_network_config.mojom-forward.h"
  15. namespace gfx {
  16. class ImageSkia;
  17. } // namespace gfx
  18. namespace ash {
  19. class TrayNetworkStateModel;
  20. // Provides an interface to network_icon for the default network. This class
  21. // supports two interfaces:
  22. // * Single: A single icon is shown to represent the active network state.
  23. // * Dual: One or two icons are shown to represent the active network state:
  24. // ** Primary: The state of the primary active network. If Cellular, a
  25. // a technology badge is used to represent the network.
  26. // ** Cellular (enabled devices only): The state of the Cellular connection if
  27. // available regardless of whether it is the active network.
  28. // NOTE : GetSingleDefaultImage is partially tested in network_icon_unittest.cc,
  29. // and partially in active_network_icon_unittest.cc.
  30. // TODO(stevenjb): Move all test coverage to active_network_icon_unittest.cc and
  31. // test Dual icon methods.
  32. // This class is also responsible for periodically purging the icon cache.
  33. class ASH_EXPORT ActiveNetworkIcon : public TrayNetworkStateObserver {
  34. public:
  35. enum class Type {
  36. kSingle, // A single network icon in the tray.
  37. kPrimary, // Multiple network icons: primary (non mobile) icon.
  38. kCellular, // Multiple network icons: cellular icon.
  39. };
  40. explicit ActiveNetworkIcon(TrayNetworkStateModel* model);
  41. ActiveNetworkIcon(const ActiveNetworkIcon&) = delete;
  42. ActiveNetworkIcon& operator=(const ActiveNetworkIcon&) = delete;
  43. ~ActiveNetworkIcon() override;
  44. // Provides the a11y and tooltip strings for |type|. Output parameters can
  45. // be null.
  46. void GetConnectionStatusStrings(Type type,
  47. std::u16string* a11y_name,
  48. std::u16string* a11y_desc,
  49. std::u16string* tooltip);
  50. // Returns a network icon (which may be empty) and sets |animating| if
  51. // provided.
  52. gfx::ImageSkia GetImage(Type type,
  53. network_icon::IconType icon_type,
  54. bool* animating);
  55. void PurgeNetworkIconCache();
  56. private:
  57. gfx::ImageSkia GetSingleImage(network_icon::IconType icon_type,
  58. bool* animating);
  59. gfx::ImageSkia GetDualImagePrimary(network_icon::IconType icon_type,
  60. bool* animating);
  61. gfx::ImageSkia GetDualImageCellular(network_icon::IconType icon_type,
  62. bool* animating);
  63. gfx::ImageSkia GetDefaultImageImpl(
  64. const chromeos::network_config::mojom::NetworkStateProperties*
  65. default_network,
  66. network_icon::IconType icon_type,
  67. bool* animating);
  68. // Called when there is no default network., Provides an empty or disabled
  69. // wifi icon and sets |animating| if provided to false.
  70. gfx::ImageSkia GetDefaultImageForNoNetwork(network_icon::IconType icon_type,
  71. bool* animating);
  72. void SetCellularUninitializedMsg();
  73. // TrayNetworkStateObserver
  74. void ActiveNetworkStateChanged() override;
  75. void NetworkListChanged() override;
  76. void DeviceStateListChanged() override;
  77. const chromeos::network_config::mojom::NetworkStateProperties*
  78. GetNetworkForType(Type type);
  79. TrayNetworkStateModel* model_;
  80. int cellular_uninitialized_msg_ = 0;
  81. base::Time uninitialized_state_time_;
  82. base::OneShotTimer purge_timer_;
  83. base::WeakPtrFactory<ActiveNetworkIcon> weak_ptr_factory_{this};
  84. };
  85. } // namespace ash
  86. #endif // ASH_SYSTEM_NETWORK_ACTIVE_NETWORK_ICON_H_