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