[go: nahoru, domu]

blob: 3d4468d061fd32ac77c4d86b3b42647f2d18a43d [file] [log] [blame]
Steven Bennetts71ac2652019-02-07 00:32:511// 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örriead587c32021-03-11 14:09:279#include <string>
Steven Bennetts71ac2652019-02-07 00:32:5110#include <vector>
11
12#include "ash/ash_export.h"
13#include "ash/system/network/network_icon.h"
James Cook811b4032019-08-23 16:02:2014#include "ash/system/network/tray_network_state_observer.h"
Steven Bennetts71ac2652019-02-07 00:32:5115#include "base/macros.h"
16#include "base/strings/string16.h"
Steven Bennetts2bed21e2019-02-08 18:56:3017#include "base/time/time.h"
Steven Bennetts8e06a6c2019-05-20 17:25:2218#include "base/timer/timer.h"
Steven Bennetts10531d52019-10-03 23:50:4019#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom-forward.h"
Steven Bennetts71ac2652019-02-07 00:32:5120
21namespace gfx {
22class ImageSkia;
23} // namespace gfx
24
25namespace ash {
26
James Cook811b4032019-08-23 16:02:2027class TrayNetworkStateModel;
28
Steven Bennetts64682d742019-05-21 19:16:0629// Provides an interface to network_icon for the default network. This class
30// supports two interfaces:
Steven Bennetts13c8f1902019-02-07 01:52:0131// * 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 Bennetts2b9e1e52019-05-20 23:06:4837// NOTE : GetSingleDefaultImage is partially tested in network_icon_unittest.cc,
38// and partially in active_network_icon_unittest.cc.
Steven Bennetts0876b3c2019-02-13 04:15:3839// TODO(stevenjb): Move all test coverage to active_network_icon_unittest.cc and
40// test Dual icon methods.
Steven Bennetts8e06a6c2019-05-20 17:25:2241// This class is also responsible for periodically purging the icon cache.
James Cook811b4032019-08-23 16:02:2042class ASH_EXPORT ActiveNetworkIcon : public TrayNetworkStateObserver {
Steven Bennetts71ac2652019-02-07 00:32:5143 public:
Steven Bennetts8df0b602019-05-21 16:27:5644 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 Rockot80738e42019-08-15 20:34:5750 explicit ActiveNetworkIcon(TrayNetworkStateModel* model);
Steven Bennetts71ac2652019-02-07 00:32:5151 ~ActiveNetworkIcon() override;
52
Steven Bennettsd48e82002019-05-22 19:48:5153 // Provides the a11y and tooltip strings for |type|. Output parameters can
54 // be null.
Steven Bennetts8df0b602019-05-21 16:27:5655 void GetConnectionStatusStrings(Type type,
Jan Wilken Dörrie85285b02021-03-11 23:38:4756 std::u16string* a11y_name,
57 std::u16string* a11y_desc,
58 std::u16string* tooltip);
Steven Bennetts13c8f1902019-02-07 01:52:0159
Steven Bennetts8df0b602019-05-21 16:27:5660 // 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 Bennetts13c8f1902019-02-07 01:52:0165
Ahmed Mehfoozfbdbb16c2021-01-22 22:42:1066 void PurgeNetworkIconCache();
67
Steven Bennetts71ac2652019-02-07 00:32:5168 private:
Steven Bennetts8df0b602019-05-21 16:27:5669 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 Bennetts13c8f1902019-02-07 01:52:0175 gfx::ImageSkia GetDefaultImageImpl(
Steven Bennettsa5f2c302019-05-21 17:52:5576 const chromeos::network_config::mojom::NetworkStateProperties*
77 default_network,
Steven Bennetts13c8f1902019-02-07 01:52:0178 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 Bennetts71ac2652019-02-07 00:32:5183 gfx::ImageSkia GetDefaultImageForNoNetwork(network_icon::IconType icon_type,
84 bool* animating);
85
Steven Bennetts2bed21e2019-02-08 18:56:3086 void SetCellularUninitializedMsg();
Steven Bennetts71ac2652019-02-07 00:32:5187
James Cook811b4032019-08-23 16:02:2088 // TrayNetworkStateObserver
Steven Bennetts64682d742019-05-21 19:16:0689 void ActiveNetworkStateChanged() override;
90 void NetworkListChanged() override;
Steven Bennetts71ac2652019-02-07 00:32:5191
Steven Bennettsd48e82002019-05-22 19:48:5192 const chromeos::network_config::mojom::NetworkStateProperties*
93 GetNetworkForType(Type type);
Steven Bennetts15a31e72019-04-26 18:10:0194
Steven Bennetts02abafd2019-05-22 14:47:0295 TrayNetworkStateModel* model_;
Steven Bennetts64682d742019-05-21 19:16:0696
Steven Bennetts71ac2652019-02-07 00:32:5197 int cellular_uninitialized_msg_ = 0;
Steven Bennetts2bed21e2019-02-08 18:56:3098 base::Time uninitialized_state_time_;
Steven Bennetts8e06a6c2019-05-20 17:25:2299 base::OneShotTimer purge_timer_;
Jeremy Roman47d432e2019-08-20 14:24:00100 base::WeakPtrFactory<ActiveNetworkIcon> weak_ptr_factory_{this};
Steven Bennetts71ac2652019-02-07 00:32:51101
102 DISALLOW_COPY_AND_ASSIGN(ActiveNetworkIcon);
103};
104
105} // namespace ash
106
107#endif // ASH_SYSTEM_NETWORK_ACTIVE_NETWORK_ICON_H_