| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/system/chromeos/network/tray_vpn.h" | 5 #include "ash/system/chromeos/network/tray_vpn.h" |
| 6 | 6 |
| 7 #include "ash/metrics/user_metrics_recorder.h" | 7 #include "ash/metrics/user_metrics_recorder.h" |
| 8 #include "ash/session/session_state_delegate.h" | 8 #include "ash/session/session_state_delegate.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" | 10 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" |
| 11 #include "ash/system/tray/system_tray.h" | 11 #include "ash/system/tray/system_tray.h" |
| 12 #include "ash/system/tray/system_tray_delegate.h" | 12 #include "ash/system/tray/system_tray_delegate.h" |
| 13 #include "ash/system/tray/tray_constants.h" | 13 #include "ash/system/tray/tray_constants.h" |
| 14 #include "ash/system/tray/tray_item_more.h" | 14 #include "ash/system/tray/tray_item_more.h" |
| 15 #include "ash/system/tray/tray_popup_label_button.h" | 15 #include "ash/system/tray/tray_popup_label_button.h" |
| 16 #include "chromeos/device_event_log.h" |
| 16 #include "chromeos/network/network_state.h" | 17 #include "chromeos/network/network_state.h" |
| 17 #include "chromeos/network/network_state_handler.h" | 18 #include "chromeos/network/network_state_handler.h" |
| 18 #include "grit/ash_strings.h" | 19 #include "grit/ash_strings.h" |
| 19 #include "grit/ui_chromeos_strings.h" | 20 #include "grit/ui_chromeos_strings.h" |
| 20 #include "third_party/cros_system_api/dbus/service_constants.h" | 21 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/chromeos/network/network_icon.h" | 23 #include "ui/chromeos/network/network_icon.h" |
| 23 #include "ui/chromeos/network/network_icon_animation.h" | 24 #include "ui/chromeos/network/network_icon_animation.h" |
| 24 | 25 |
| 25 using chromeos::NetworkHandler; | 26 using chromeos::NetworkHandler; |
| 26 using chromeos::NetworkState; | 27 using chromeos::NetworkState; |
| 27 using chromeos::NetworkStateHandler; | 28 using chromeos::NetworkStateHandler; |
| 28 using chromeos::NetworkTypePattern; | 29 using chromeos::NetworkTypePattern; |
| 29 | 30 |
| 30 namespace ash { | 31 namespace ash { |
| 31 namespace tray { | 32 namespace tray { |
| 32 | 33 |
| 33 class VpnDefaultView : public TrayItemMore, | 34 class VpnDefaultView : public TrayItemMore, |
| 34 public ui::network_icon::AnimationObserver { | 35 public ui::network_icon::AnimationObserver { |
| 35 public: | 36 public: |
| 36 VpnDefaultView(SystemTrayItem* owner, bool show_more) | 37 VpnDefaultView(SystemTrayItem* owner, bool show_more) |
| 37 : TrayItemMore(owner, show_more) { | 38 : TrayItemMore(owner, show_more) { |
| 38 Update(); | 39 Update(); |
| 39 } | 40 } |
| 40 | 41 |
| 41 virtual ~VpnDefaultView() { | 42 ~VpnDefaultView() override { |
| 42 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 43 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 43 } | 44 } |
| 44 | 45 |
| 45 static bool ShouldShow() { | 46 static bool ShouldShow() { |
| 46 // Do not show VPN line in uber tray bubble if VPN is not configured. | 47 // Do not show VPN line in uber tray bubble if VPN is not configured. |
| 47 NetworkStateHandler* handler = | 48 NetworkStateHandler* handler = |
| 48 NetworkHandler::Get()->network_state_handler(); | 49 NetworkHandler::Get()->network_state_handler(); |
| 49 const NetworkState* vpn = | 50 const NetworkState* vpn = |
| 50 handler->FirstNetworkByType(NetworkTypePattern::VPN()); | 51 handler->FirstNetworkByType(NetworkTypePattern::VPN()); |
| 51 return vpn != NULL; | 52 return vpn != NULL; |
| 52 } | 53 } |
| 53 | 54 |
| 54 void Update() { | 55 void Update() { |
| 55 gfx::ImageSkia image; | 56 gfx::ImageSkia image; |
| 56 base::string16 label; | 57 base::string16 label; |
| 57 bool animating = false; | 58 bool animating = false; |
| 58 GetNetworkStateHandlerImageAndLabel(&image, &label, &animating); | 59 GetNetworkStateHandlerImageAndLabel(&image, &label, &animating); |
| 59 if (animating) | 60 if (animating) |
| 60 ui::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 61 ui::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 61 else | 62 else |
| 62 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver( | 63 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver( |
| 63 this); | 64 this); |
| 64 SetImage(&image); | 65 SetImage(&image); |
| 65 SetLabel(label); | 66 SetLabel(label); |
| 66 SetAccessibleName(label); | 67 SetAccessibleName(label); |
| 67 } | 68 } |
| 68 | 69 |
| 69 // ui::network_icon::AnimationObserver | 70 // ui::network_icon::AnimationObserver |
| 70 virtual void NetworkIconChanged() override { | 71 void NetworkIconChanged() override { Update(); } |
| 71 Update(); | |
| 72 } | |
| 73 | 72 |
| 74 private: | 73 private: |
| 75 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, | 74 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, |
| 76 base::string16* label, | 75 base::string16* label, |
| 77 bool* animating) { | 76 bool* animating) { |
| 78 NetworkStateHandler* handler = | 77 NetworkStateHandler* handler = |
| 79 NetworkHandler::Get()->network_state_handler(); | 78 NetworkHandler::Get()->network_state_handler(); |
| 80 const NetworkState* vpn = | 79 const NetworkState* vpn = |
| 81 handler->FirstNetworkByType(NetworkTypePattern::VPN()); | 80 handler->FirstNetworkByType(NetworkTypePattern::VPN()); |
| 82 if (!vpn || (vpn->connection_state() == shill::kStateIdle)) { | 81 if (!vpn || (vpn->connection_state() == shill::kStateIdle)) { |
| 83 *image = ui::network_icon::GetImageForDisconnectedNetwork( | 82 *image = ui::network_icon::GetImageForDisconnectedNetwork( |
| 84 ui::network_icon::ICON_TYPE_DEFAULT_VIEW, shill::kTypeVPN); | 83 ui::network_icon::ICON_TYPE_DEFAULT_VIEW, shill::kTypeVPN); |
| 85 if (label) { | 84 if (label) { |
| 86 *label = l10n_util::GetStringUTF16( | 85 *label = |
| 87 IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED); | 86 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED); |
| 88 } | 87 } |
| 89 *animating = false; | 88 *animating = false; |
| 90 return; | 89 return; |
| 91 } | 90 } |
| 92 *animating = vpn->IsConnectingState(); | 91 *animating = vpn->IsConnectingState(); |
| 93 *image = ui::network_icon::GetImageForNetwork( | 92 *image = ui::network_icon::GetImageForNetwork( |
| 94 vpn, ui::network_icon::ICON_TYPE_DEFAULT_VIEW); | 93 vpn, ui::network_icon::ICON_TYPE_DEFAULT_VIEW); |
| 95 if (label) { | 94 if (label) { |
| 96 *label = ui::network_icon::GetLabelForNetwork( | 95 *label = ui::network_icon::GetLabelForNetwork( |
| 97 vpn, ui::network_icon::ICON_TYPE_DEFAULT_VIEW); | 96 vpn, ui::network_icon::ICON_TYPE_DEFAULT_VIEW); |
| 98 } | 97 } |
| 99 } | 98 } |
| 100 | 99 |
| 101 DISALLOW_COPY_AND_ASSIGN(VpnDefaultView); | 100 DISALLOW_COPY_AND_ASSIGN(VpnDefaultView); |
| 102 }; | 101 }; |
| 103 | 102 |
| 104 } // namespace tray | 103 } // namespace tray |
| 105 | 104 |
| 106 TrayVPN::TrayVPN(SystemTray* system_tray) | 105 TrayVPN::TrayVPN(SystemTray* system_tray) |
| 107 : SystemTrayItem(system_tray), | 106 : SystemTrayItem(system_tray), default_(NULL), detailed_(NULL) { |
| 108 default_(NULL), | |
| 109 detailed_(NULL) { | |
| 110 network_state_observer_.reset(new TrayNetworkStateObserver(this)); | 107 network_state_observer_.reset(new TrayNetworkStateObserver(this)); |
| 111 } | 108 } |
| 112 | 109 |
| 113 TrayVPN::~TrayVPN() { | 110 TrayVPN::~TrayVPN() { |
| 114 } | 111 } |
| 115 | 112 |
| 116 views::View* TrayVPN::CreateTrayView(user::LoginStatus status) { | 113 views::View* TrayVPN::CreateTrayView(user::LoginStatus status) { |
| 117 return NULL; | 114 return NULL; |
| 118 } | 115 } |
| 119 | 116 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 void TrayVPN::DestroyDetailedView() { | 156 void TrayVPN::DestroyDetailedView() { |
| 160 detailed_ = NULL; | 157 detailed_ = NULL; |
| 161 } | 158 } |
| 162 | 159 |
| 163 void TrayVPN::UpdateAfterLoginStatusChange(user::LoginStatus status) { | 160 void TrayVPN::UpdateAfterLoginStatusChange(user::LoginStatus status) { |
| 164 } | 161 } |
| 165 | 162 |
| 166 void TrayVPN::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 163 void TrayVPN::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 167 } | 164 } |
| 168 | 165 |
| 169 void TrayVPN::NetworkStateChanged(bool list_changed) { | 166 void TrayVPN::NetworkStateChanged() { |
| 170 if (default_) | 167 if (default_) |
| 171 default_->Update(); | 168 default_->Update(); |
| 172 if (detailed_) { | |
| 173 if (list_changed) | |
| 174 detailed_->NetworkListChanged(); | |
| 175 else | |
| 176 detailed_->ManagerChanged(); | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 void TrayVPN::NetworkServiceChanged(const chromeos::NetworkState* network) { | |
| 181 if (detailed_) | 169 if (detailed_) |
| 182 detailed_->NetworkServiceChanged(network); | 170 detailed_->Update(); |
| 183 } | 171 } |
| 184 | 172 |
| 185 } // namespace ash | 173 } // namespace ash |
| OLD | NEW |