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

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

Issue 2732813002: chromeos: Move files in //ash/common to //ash, part 1 (Closed)
Patch Set: rebase Created 3 years, 9 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
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/common/system/chromeos/network/tray_vpn.h"
6
7 #include "ash/common/session/session_state_delegate.h"
8 #include "ash/common/system/chromeos/network/network_icon.h"
9 #include "ash/common/system/chromeos/network/network_icon_animation.h"
10 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h"
11 #include "ash/common/system/chromeos/network/network_state_list_detailed_view.h"
12 #include "ash/common/system/chromeos/network/vpn_list.h"
13 #include "ash/common/system/tray/system_tray.h"
14 #include "ash/common/system/tray/system_tray_delegate.h"
15 #include "ash/common/system/tray/tray_constants.h"
16 #include "ash/common/system/tray/tray_item_more.h"
17 #include "ash/common/system/tray/tray_popup_item_style.h"
18 #include "ash/common/wm_shell.h"
19 #include "ash/resources/vector_icons/vector_icons.h"
20 #include "ash/strings/grit/ash_strings.h"
21 #include "chromeos/network/network_state.h"
22 #include "chromeos/network/network_state_handler.h"
23 #include "third_party/cros_system_api/dbus/service_constants.h"
24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/gfx/paint_vector_icon.h"
26
27 using chromeos::NetworkHandler;
28 using chromeos::NetworkState;
29 using chromeos::NetworkStateHandler;
30 using chromeos::NetworkTypePattern;
31
32 namespace ash {
33 namespace tray {
34
35 class VpnDefaultView : public TrayItemMore,
36 public network_icon::AnimationObserver {
37 public:
38 explicit VpnDefaultView(SystemTrayItem* owner) : TrayItemMore(owner) {}
39
40 ~VpnDefaultView() override {
41 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
42 }
43
44 static bool ShouldShow() {
45 // Show the VPN entry in the ash tray bubble if at least one third-party VPN
46 // provider is installed.
47 if (WmShell::Get()->vpn_list()->HaveThirdPartyVPNProviders())
48 return true;
49
50 // Also show the VPN entry if at least one VPN network is configured.
51 NetworkStateHandler* const handler =
52 NetworkHandler::Get()->network_state_handler();
53 if (handler->FirstNetworkByType(NetworkTypePattern::VPN()))
54 return true;
55 return false;
56 }
57
58 void Update() {
59 gfx::ImageSkia image;
60 base::string16 label;
61 bool animating = false;
62 GetNetworkStateHandlerImageAndLabel(&image, &label, &animating);
63 if (animating)
64 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
65 else
66 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
67 SetImage(image);
68 SetLabel(label);
69 SetAccessibleName(label);
70 }
71
72 // network_icon::AnimationObserver
73 void NetworkIconChanged() override { Update(); }
74
75 protected:
76 // TrayItemMore:
77 std::unique_ptr<TrayPopupItemStyle> HandleCreateStyle() const override {
78 std::unique_ptr<TrayPopupItemStyle> style =
79 TrayItemMore::HandleCreateStyle();
80 style->set_color_style(
81 !IsVpnEnabled()
82 ? TrayPopupItemStyle::ColorStyle::DISABLED
83 : IsVpnConnected() ? TrayPopupItemStyle::ColorStyle::ACTIVE
84 : TrayPopupItemStyle::ColorStyle::INACTIVE);
85 return style;
86 }
87
88 void UpdateStyle() override {
89 TrayItemMore::UpdateStyle();
90 Update();
91 }
92
93 private:
94 bool IsVpnEnabled() const {
95 NetworkStateHandler* handler =
96 NetworkHandler::Get()->network_state_handler();
97 return handler->FirstNetworkByType(NetworkTypePattern::VPN());
98 }
99
100 bool IsVpnConnected() const {
101 NetworkStateHandler* handler =
102 NetworkHandler::Get()->network_state_handler();
103 const NetworkState* vpn =
104 handler->FirstNetworkByType(NetworkTypePattern::VPN());
105 return IsVpnEnabled() &&
106 (vpn->IsConnectedState() || vpn->IsConnectingState());
107 }
108
109 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image,
110 base::string16* label,
111 bool* animating) {
112 NetworkStateHandler* handler =
113 NetworkHandler::Get()->network_state_handler();
114 const NetworkState* vpn =
115 handler->FirstNetworkByType(NetworkTypePattern::VPN());
116 *image = gfx::CreateVectorIcon(
117 kNetworkVpnIcon, TrayPopupItemStyle::GetIconColor(
118 vpn && vpn->IsConnectedState()
119 ? TrayPopupItemStyle::ColorStyle::ACTIVE
120 : TrayPopupItemStyle::ColorStyle::INACTIVE));
121 if (!IsVpnConnected()) {
122 if (label) {
123 *label =
124 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED);
125 }
126 *animating = false;
127 return;
128 }
129 *animating = vpn->IsConnectingState();
130 if (label) {
131 *label = network_icon::GetLabelForNetwork(
132 vpn, network_icon::ICON_TYPE_DEFAULT_VIEW);
133 }
134 }
135
136 DISALLOW_COPY_AND_ASSIGN(VpnDefaultView);
137 };
138
139 } // namespace tray
140
141 TrayVPN::TrayVPN(SystemTray* system_tray)
142 : SystemTrayItem(system_tray, UMA_VPN),
143 default_(nullptr),
144 detailed_(nullptr) {
145 network_state_observer_.reset(new TrayNetworkStateObserver(this));
146 }
147
148 TrayVPN::~TrayVPN() {}
149
150 views::View* TrayVPN::CreateTrayView(LoginStatus status) {
151 return NULL;
152 }
153
154 views::View* TrayVPN::CreateDefaultView(LoginStatus status) {
155 CHECK(default_ == NULL);
156 if (!chromeos::NetworkHandler::IsInitialized())
157 return NULL;
158 if (status == LoginStatus::NOT_LOGGED_IN)
159 return NULL;
160 if (!tray::VpnDefaultView::ShouldShow())
161 return NULL;
162
163 const bool is_in_secondary_login_screen =
164 WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen();
165
166 default_ = new tray::VpnDefaultView(this);
167 default_->SetEnabled(status != LoginStatus::LOCKED &&
168 !is_in_secondary_login_screen);
169
170 return default_;
171 }
172
173 views::View* TrayVPN::CreateDetailedView(LoginStatus status) {
174 CHECK(detailed_ == NULL);
175 if (!chromeos::NetworkHandler::IsInitialized())
176 return NULL;
177
178 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_DETAILED_VPN_VIEW);
179 detailed_ = new tray::NetworkStateListDetailedView(
180 this, tray::NetworkStateListDetailedView::LIST_TYPE_VPN, status);
181 detailed_->Init();
182 return detailed_;
183 }
184
185 void TrayVPN::DestroyTrayView() {}
186
187 void TrayVPN::DestroyDefaultView() {
188 default_ = NULL;
189 }
190
191 void TrayVPN::DestroyDetailedView() {
192 detailed_ = NULL;
193 }
194
195 void TrayVPN::UpdateAfterLoginStatusChange(LoginStatus status) {}
196
197 void TrayVPN::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {}
198
199 void TrayVPN::NetworkStateChanged() {
200 if (default_)
201 default_->Update();
202 if (detailed_)
203 detailed_->Update();
204 }
205
206 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/network/tray_vpn.h ('k') | ash/common/system/chromeos/network/vpn_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698