Index: ash/system/network/tray_network.cc |
diff --git a/ash/system/network/tray_network.cc b/ash/system/network/tray_network.cc |
index 297ee10c5b06384d15be1713580919ff3a95c195..5ed4ab90676deb826d5aae37fba88a4cc3bea349 100644 |
--- a/ash/system/network/tray_network.cc |
+++ b/ash/system/network/tray_network.cc |
@@ -13,6 +13,7 @@ |
#include "ash/system/network/network_icon_animation_observer.h" |
#include "ash/system/network/network_state_list_detailed_view.h" |
#include "ash/system/network/tray_network_state_observer.h" |
+#include "ash/system/system_notifier.h" |
#include "ash/system/tray/system_tray.h" |
#include "ash/system/tray/system_tray_delegate.h" |
#include "ash/system/tray/system_tray_notifier.h" |
@@ -28,6 +29,8 @@ |
#include "third_party/cros_system_api/dbus/service_constants.h" |
#include "ui/accessibility/ax_node_data.h" |
#include "ui/base/l10n/l10n_util.h" |
+#include "ui/message_center/message_center.h" |
+#include "ui/message_center/notification.h" |
#include "ui/views/controls/image_view.h" |
#include "ui/views/controls/link.h" |
#include "ui/views/controls/link_listener.h" |
@@ -38,18 +41,39 @@ using chromeos::NetworkHandler; |
using chromeos::NetworkState; |
using chromeos::NetworkStateHandler; |
using chromeos::NetworkTypePattern; |
+using message_center::Notification; |
namespace ash { |
namespace tray { |
namespace { |
+constexpr char kWifiToggleNotificationId[] = "wifi-toggle"; |
+ |
// Returns the connected, non-virtual (aka VPN), network. |
const NetworkState* GetConnectedNetwork() { |
NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
return handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); |
} |
+std::unique_ptr<Notification> CreateNotification() { |
+ bool wifi_enabled = |
+ NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled( |
+ NetworkTypePattern::WiFi()); |
+ const int string_id = wifi_enabled |
+ ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED |
+ : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; |
+ std::unique_ptr<Notification> notification(new Notification( |
+ message_center::NOTIFICATION_TYPE_SIMPLE, kWifiToggleNotificationId, |
+ base::string16(), l10n_util::GetStringUTF16(string_id), |
+ gfx::Image(network_icon::GetBasicImageForWiFiNetwork(wifi_enabled)), |
+ base::string16() /* display_source */, GURL(), |
+ message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, |
+ system_notifier::kNotifierWifiToggle), |
+ message_center::RichNotificationData(), nullptr)); |
+ return notification; |
+} |
+ |
} // namespace |
class NetworkTrayView : public TrayItemView, |
@@ -173,64 +197,10 @@ class NetworkDefaultView : public TrayItemMore, |
DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); |
}; |
-class NetworkWifiDetailedView : public NetworkDetailedView { |
tdanderson
2017/04/18 23:33:32
From what I can tell, once this CL lands you shoul
tetsui2
2017/04/20 01:54:54
Sure, I would do the follow-on CL then.
tdanderson
2017/04/21 15:25:01
Thanks!
|
- public: |
- explicit NetworkWifiDetailedView(SystemTrayItem* owner) |
- : NetworkDetailedView(owner) {} |
- |
- ~NetworkWifiDetailedView() override {} |
- |
- // NetworkDetailedView: |
- void Init() override { |
- constexpr int kVerticalPadding = 10; |
- auto* box_layout = new views::BoxLayout( |
- views::BoxLayout::kHorizontal, kTrayPopupPaddingHorizontal, |
- kVerticalPadding, kTrayPopupPaddingBetweenItems); |
- SetLayoutManager(box_layout); |
- |
- image_view_ = new views::ImageView; |
- AddChildView(image_view_); |
- |
- label_view_ = new views::Label(); |
- label_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
- AddChildView(label_view_); |
- box_layout->SetFlexForView(label_view_, 1); |
- |
- Update(); |
- } |
- |
- NetworkDetailedView::DetailedViewType GetViewType() const override { |
- return NetworkDetailedView::WIFI_VIEW; |
- } |
- |
- void Update() override { |
- bool wifi_enabled = |
- NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled( |
- NetworkTypePattern::WiFi()); |
- image_view_->SetImage( |
- network_icon::GetBasicImageForWiFiNetwork(wifi_enabled)); |
- |
- const int string_id = wifi_enabled |
- ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED |
- : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; |
- label_view_->SetText(l10n_util::GetStringUTF16(string_id)); |
- } |
- |
- private: |
- views::ImageView* image_view_ = nullptr; |
- views::Label* label_view_ = nullptr; |
- |
- DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); |
-}; |
- |
} // namespace tray |
TrayNetwork::TrayNetwork(SystemTray* system_tray) |
- : SystemTrayItem(system_tray, UMA_NETWORK), |
- tray_(NULL), |
- default_(NULL), |
- detailed_(NULL), |
- request_wifi_view_(false) { |
+ : SystemTrayItem(system_tray, UMA_NETWORK), tray_(NULL), default_(NULL) { |
network_state_observer_.reset(new TrayNetworkStateObserver(this)); |
SystemTrayNotifier* notifier = Shell::Get()->system_tray_notifier(); |
notifier->AddNetworkObserver(this); |
@@ -261,23 +231,6 @@ views::View* TrayNetwork::CreateDefaultView(LoginStatus status) { |
return default_; |
} |
-views::View* TrayNetwork::CreateDetailedView(LoginStatus status) { |
- CHECK(detailed_ == NULL); |
- ShellPort::Get()->RecordUserMetricsAction( |
- UMA_STATUS_AREA_DETAILED_NETWORK_VIEW); |
- if (!chromeos::NetworkHandler::IsInitialized()) |
- return NULL; |
- if (request_wifi_view_) { |
- detailed_ = new tray::NetworkWifiDetailedView(this); |
- request_wifi_view_ = false; |
- } else { |
- detailed_ = new tray::NetworkStateListDetailedView( |
tdanderson
2017/04/18 23:33:32
I don't think you want to kill off CreateDetailedV
tetsui2
2017/04/20 01:54:55
Done.
|
- this, tray::NetworkStateListDetailedView::LIST_TYPE_NETWORK, status); |
- } |
- detailed_->Init(); |
- return detailed_; |
-} |
- |
void TrayNetwork::DestroyTrayView() { |
tray_ = NULL; |
} |
@@ -286,17 +239,14 @@ void TrayNetwork::DestroyDefaultView() { |
default_ = NULL; |
} |
-void TrayNetwork::DestroyDetailedView() { |
- detailed_ = NULL; |
-} |
- |
void TrayNetwork::RequestToggleWifi() { |
// This will always be triggered by a user action (e.g. keyboard shortcut) |
- if (!detailed_ || |
- detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { |
- request_wifi_view_ = true; |
- ShowDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); |
- } |
+ message_center::MessageCenter* message_center = |
+ message_center::MessageCenter::Get(); |
+ if (message_center->FindVisibleNotificationById( |
+ tray::kWifiToggleNotificationId)) |
+ message_center->RemoveNotification(tray::kWifiToggleNotificationId, false); |
+ message_center->AddNotification(tray::CreateNotification()); |
NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
bool enabled = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()); |
ShellPort::Get()->RecordUserMetricsAction( |
@@ -314,8 +264,6 @@ void TrayNetwork::NetworkStateChanged() { |
tray_->UpdateNetworkStateHandlerIcon(); |
if (default_) |
default_->Update(); |
- if (detailed_) |
- detailed_->Update(); |
} |
} // namespace ash |