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