Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Unified Diff: ash/system/network/tray_network.cc

Issue 2817423002: ash: Move "WiFi is turned on." buble to the notification center. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..6047f793e236b7ad8559e0cb4bdfa6fc9957ce9a 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"
@@ -38,6 +39,7 @@ using chromeos::NetworkHandler;
using chromeos::NetworkState;
using chromeos::NetworkStateHandler;
using chromeos::NetworkTypePattern;
+using message_center::Notification;
namespace ash {
namespace tray {
@@ -173,64 +175,34 @@ class NetworkDefaultView : public TrayItemMore,
DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView);
};
-class NetworkWifiDetailedView : public NetworkDetailedView {
- 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));
- }
+} // namespace tray
- private:
- views::ImageView* image_view_ = nullptr;
- views::Label* label_view_ = nullptr;
+namespace {
fukino 2017/04/17 08:43:40 Please merge this block with previous unnamed name
tetsui2 2017/04/18 01:11:33 Done.
- DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView);
-};
+const char kWifiToggleNotificationId[] = "wifi-toggle";
fukino 2017/04/17 08:43:40 nit: const => constexpr
tetsui2 2017/04/18 01:11:33 Done.
+
+std::unique_ptr<Notification> CreateNotification() {
fukino 2017/04/17 08:43:40 You should be able to use Notificatoin::CreateSyst
tetsui2 2017/04/18 01:11:33 It is not possible to use CreateSystemNotification
fukino 2017/04/18 01:22:40 Acknowledged.
+ 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 tray
+} // namespace
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 +233,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(
- this, tray::NetworkStateListDetailedView::LIST_TYPE_NETWORK, status);
- }
- detailed_->Init();
- return detailed_;
-}
-
void TrayNetwork::DestroyTrayView() {
tray_ = NULL;
}
@@ -286,17 +241,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(kWifiToggleNotificationId)) {
fukino 2017/04/17 08:43:40 nit: We usually omit {} for single-line statements
tetsui2 2017/04/18 01:11:33 Done.
+ message_center->RemoveNotification(kWifiToggleNotificationId, false);
}
+ message_center->AddNotification(CreateNotification());
NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
bool enabled = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi());
ShellPort::Get()->RecordUserMetricsAction(
@@ -314,8 +266,6 @@ void TrayNetwork::NetworkStateChanged() {
tray_->UpdateNetworkStateHandlerIcon();
if (default_)
default_->Update();
- if (detailed_)
- detailed_->Update();
}
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698