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

Side by Side Diff: ash/system/chromeos/network/tray_vpn.cc

Issue 2109293002: mash: Convert system tray network item to wm common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tweak string Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « ash/system/chromeos/network/tray_vpn.h ('k') | ash/system/chromeos/network/vpn_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/system/chromeos/network/tray_vpn.h"
6
7 #include "ash/common/session/session_state_delegate.h"
8 #include "ash/common/system/tray/system_tray_delegate.h"
9 #include "ash/common/system/tray/tray_constants.h"
10 #include "ash/common/system/tray/tray_item_more.h"
11 #include "ash/common/system/tray/tray_popup_label_button.h"
12 #include "ash/common/wm_shell.h"
13 #include "ash/system/chromeos/network/network_state_list_detailed_view.h"
14 #include "ash/system/chromeos/network/vpn_delegate.h"
15 #include "ash/system/tray/system_tray.h"
16 #include "chromeos/network/network_state.h"
17 #include "chromeos/network/network_state_handler.h"
18 #include "grit/ash_strings.h"
19 #include "grit/ui_chromeos_strings.h"
20 #include "third_party/cros_system_api/dbus/service_constants.h"
21 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/chromeos/network/network_icon.h"
23 #include "ui/chromeos/network/network_icon_animation.h"
24 #include "ui/chromeos/network/network_icon_animation_observer.h"
25
26 using chromeos::NetworkHandler;
27 using chromeos::NetworkState;
28 using chromeos::NetworkStateHandler;
29 using chromeos::NetworkTypePattern;
30
31 namespace ash {
32 namespace tray {
33
34 class VpnDefaultView : public TrayItemMore,
35 public ui::network_icon::AnimationObserver {
36 public:
37 VpnDefaultView(SystemTrayItem* owner, bool show_more)
38 : TrayItemMore(owner, show_more) {
39 Update();
40 }
41
42 ~VpnDefaultView() override {
43 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
44 }
45
46 static bool ShouldShow() {
47 // Show the VPN entry in the ash tray bubble if at least one third-party VPN
48 // provider is installed.
49 if (WmShell::Get()
50 ->system_tray_delegate()
51 ->GetVPNDelegate()
52 ->HaveThirdPartyVPNProviders()) {
53 return true;
54 }
55
56 // Also show the VPN entry if at least one VPN network is configured.
57 NetworkStateHandler* const handler =
58 NetworkHandler::Get()->network_state_handler();
59 if (handler->FirstNetworkByType(NetworkTypePattern::VPN()))
60 return true;
61 return false;
62 }
63
64 void Update() {
65 gfx::ImageSkia image;
66 base::string16 label;
67 bool animating = false;
68 GetNetworkStateHandlerImageAndLabel(&image, &label, &animating);
69 if (animating)
70 ui::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
71 else
72 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(
73 this);
74 SetImage(&image);
75 SetLabel(label);
76 SetAccessibleName(label);
77 }
78
79 // ui::network_icon::AnimationObserver
80 void NetworkIconChanged() override { Update(); }
81
82 private:
83 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image,
84 base::string16* label,
85 bool* animating) {
86 NetworkStateHandler* handler =
87 NetworkHandler::Get()->network_state_handler();
88 const NetworkState* vpn =
89 handler->FirstNetworkByType(NetworkTypePattern::VPN());
90 if (!vpn || (!vpn->IsConnectedState() && !vpn->IsConnectingState())) {
91 *image = ui::network_icon::GetImageForDisconnectedNetwork(
92 ui::network_icon::ICON_TYPE_DEFAULT_VIEW, shill::kTypeVPN);
93 if (label) {
94 *label =
95 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED);
96 }
97 *animating = false;
98 return;
99 }
100 *animating = vpn->IsConnectingState();
101 *image = ui::network_icon::GetImageForNetwork(
102 vpn, ui::network_icon::ICON_TYPE_DEFAULT_VIEW);
103 if (label) {
104 *label = ui::network_icon::GetLabelForNetwork(
105 vpn, ui::network_icon::ICON_TYPE_DEFAULT_VIEW);
106 }
107 }
108
109 DISALLOW_COPY_AND_ASSIGN(VpnDefaultView);
110 };
111
112 } // namespace tray
113
114 TrayVPN::TrayVPN(SystemTray* system_tray)
115 : SystemTrayItem(system_tray), default_(NULL), detailed_(NULL) {
116 network_state_observer_.reset(new TrayNetworkStateObserver(this));
117 }
118
119 TrayVPN::~TrayVPN() {}
120
121 views::View* TrayVPN::CreateTrayView(LoginStatus status) {
122 return NULL;
123 }
124
125 views::View* TrayVPN::CreateDefaultView(LoginStatus status) {
126 CHECK(default_ == NULL);
127 if (!chromeos::NetworkHandler::IsInitialized())
128 return NULL;
129 if (status == LoginStatus::NOT_LOGGED_IN)
130 return NULL;
131 if (!tray::VpnDefaultView::ShouldShow())
132 return NULL;
133
134 const bool is_in_secondary_login_screen =
135 WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen();
136
137 default_ = new tray::VpnDefaultView(
138 this, status != LoginStatus::LOCKED && !is_in_secondary_login_screen);
139
140 return default_;
141 }
142
143 views::View* TrayVPN::CreateDetailedView(LoginStatus status) {
144 CHECK(detailed_ == NULL);
145 if (!chromeos::NetworkHandler::IsInitialized())
146 return NULL;
147
148 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_DETAILED_VPN_VIEW);
149 detailed_ = new tray::NetworkStateListDetailedView(
150 this, tray::NetworkStateListDetailedView::LIST_TYPE_VPN, status);
151 detailed_->Init();
152 return detailed_;
153 }
154
155 void TrayVPN::DestroyTrayView() {}
156
157 void TrayVPN::DestroyDefaultView() {
158 default_ = NULL;
159 }
160
161 void TrayVPN::DestroyDetailedView() {
162 detailed_ = NULL;
163 }
164
165 void TrayVPN::UpdateAfterLoginStatusChange(LoginStatus status) {}
166
167 void TrayVPN::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {}
168
169 void TrayVPN::NetworkStateChanged() {
170 if (default_)
171 default_->Update();
172 if (detailed_)
173 detailed_->Update();
174 }
175
176 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/network/tray_vpn.h ('k') | ash/system/chromeos/network/vpn_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698