OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/common/system/chromeos/network/vpn_list_view.h" | 5 #include "ash/common/system/chromeos/network/vpn_list_view.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // network_icon::AnimationObserver: | 156 // network_icon::AnimationObserver: |
157 void NetworkIconChanged() override; | 157 void NetworkIconChanged() override; |
158 | 158 |
159 private: | 159 private: |
160 void UpdateFromNetworkState(const chromeos::NetworkState* network); | 160 void UpdateFromNetworkState(const chromeos::NetworkState* network); |
161 void SetupConnectedItemMd(const base::string16& text, | 161 void SetupConnectedItemMd(const base::string16& text, |
162 const gfx::ImageSkia& image); | 162 const gfx::ImageSkia& image); |
163 void SetupConnectingItemMd(const base::string16& text, | 163 void SetupConnectingItemMd(const base::string16& text, |
164 const gfx::ImageSkia& image); | 164 const gfx::ImageSkia& image); |
165 | 165 |
166 const std::string service_path_; | 166 const std::string guid_; |
167 | 167 |
168 views::LabelButton* disconnect_button_ = nullptr; | 168 views::LabelButton* disconnect_button_ = nullptr; |
169 | 169 |
170 DISALLOW_COPY_AND_ASSIGN(VPNListNetworkEntry); | 170 DISALLOW_COPY_AND_ASSIGN(VPNListNetworkEntry); |
171 }; | 171 }; |
172 | 172 |
173 VPNListEntryBase::VPNListEntryBase(VPNListView* parent) | 173 VPNListEntryBase::VPNListEntryBase(VPNListView* parent) |
174 : HoverHighlightView(parent) { | 174 : HoverHighlightView(parent) { |
175 if (!UseMd()) | 175 if (!UseMd()) |
176 SetBorder(views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0)); | 176 SetBorder(views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0)); |
177 } | 177 } |
178 | 178 |
179 VPNListNetworkEntry::VPNListNetworkEntry(VPNListView* parent, | 179 VPNListNetworkEntry::VPNListNetworkEntry(VPNListView* parent, |
180 const chromeos::NetworkState* network) | 180 const chromeos::NetworkState* network) |
181 : VPNListEntryBase(parent), service_path_(network->path()) { | 181 : VPNListEntryBase(parent), guid_(network->guid()) { |
182 UpdateFromNetworkState(network); | 182 UpdateFromNetworkState(network); |
183 } | 183 } |
184 | 184 |
185 VPNListNetworkEntry::~VPNListNetworkEntry() { | 185 VPNListNetworkEntry::~VPNListNetworkEntry() { |
186 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 186 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
187 } | 187 } |
188 | 188 |
189 void VPNListNetworkEntry::NetworkIconChanged() { | 189 void VPNListNetworkEntry::NetworkIconChanged() { |
190 UpdateFromNetworkState( | 190 UpdateFromNetworkState(chromeos::NetworkHandler::Get() |
191 chromeos::NetworkHandler::Get()->network_state_handler()->GetNetworkState( | 191 ->network_state_handler() |
192 service_path_)); | 192 ->GetNetworkStateFromGuid(guid_)); |
193 } | 193 } |
194 | 194 |
195 void VPNListNetworkEntry::UpdateFromNetworkState( | 195 void VPNListNetworkEntry::UpdateFromNetworkState( |
196 const chromeos::NetworkState* network) { | 196 const chromeos::NetworkState* network) { |
197 if (network && network->IsConnectingState()) | 197 if (network && network->IsConnectingState()) |
198 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 198 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
199 else | 199 else |
200 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 200 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
201 | 201 |
202 if (!network) { | 202 if (!network) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 } | 260 } |
261 | 261 |
262 VPNListView::~VPNListView() { | 262 VPNListView::~VPNListView() { |
263 WmShell::Get()->vpn_list()->RemoveObserver(this); | 263 WmShell::Get()->vpn_list()->RemoveObserver(this); |
264 } | 264 } |
265 | 265 |
266 void VPNListView::Update() { | 266 void VPNListView::Update() { |
267 // Before updating the list, determine whether the user was hovering over one | 267 // Before updating the list, determine whether the user was hovering over one |
268 // of the VPN provider or network entries. | 268 // of the VPN provider or network entries. |
269 std::unique_ptr<VPNProvider> hovered_provider; | 269 std::unique_ptr<VPNProvider> hovered_provider; |
270 std::string hovered_network_service_path; | 270 std::string hovered_network_guid; |
271 for (const std::pair<const views::View* const, VPNProvider>& provider : | 271 for (const std::pair<const views::View* const, VPNProvider>& provider : |
272 provider_view_map_) { | 272 provider_view_map_) { |
273 if (static_cast<const HoverHighlightView*>(provider.first)->hover()) { | 273 if (static_cast<const HoverHighlightView*>(provider.first)->hover()) { |
274 hovered_provider.reset(new VPNProvider(provider.second)); | 274 hovered_provider.reset(new VPNProvider(provider.second)); |
275 break; | 275 break; |
276 } | 276 } |
277 } | 277 } |
278 if (!hovered_provider) { | 278 if (!hovered_provider) { |
279 for (const std::pair<const views::View*, std::string>& entry : | 279 for (const std::pair<const views::View*, std::string>& entry : |
280 network_view_service_path_map_) { | 280 network_view_guid_map_) { |
281 if (static_cast<const HoverHighlightView*>(entry.first)->hover()) { | 281 if (static_cast<const HoverHighlightView*>(entry.first)->hover()) { |
282 hovered_network_service_path = entry.second; | 282 hovered_network_guid = entry.second; |
283 break; | 283 break; |
284 } | 284 } |
285 } | 285 } |
286 } | 286 } |
287 | 287 |
288 // Clear the list. | 288 // Clear the list. |
289 container()->RemoveAllChildViews(true); | 289 container()->RemoveAllChildViews(true); |
290 provider_view_map_.clear(); | 290 provider_view_map_.clear(); |
291 network_view_service_path_map_.clear(); | 291 network_view_guid_map_.clear(); |
292 list_empty_ = true; | 292 list_empty_ = true; |
293 if (!UseMd()) { | 293 if (!UseMd()) { |
294 container()->SetLayoutManager( | 294 container()->SetLayoutManager( |
295 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 295 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
296 } | 296 } |
297 | 297 |
298 // Get the list of available VPN networks, in shill's priority order. | 298 // Get the list of available VPN networks, in shill's priority order. |
299 chromeos::NetworkStateHandler::NetworkStateList networks; | 299 chromeos::NetworkStateHandler::NetworkStateList networks; |
300 chromeos::NetworkHandler::Get() | 300 chromeos::NetworkHandler::Get() |
301 ->network_state_handler() | 301 ->network_state_handler() |
302 ->GetVisibleNetworkListByType(chromeos::NetworkTypePattern::VPN(), | 302 ->GetVisibleNetworkListByType(chromeos::NetworkTypePattern::VPN(), |
303 &networks); | 303 &networks); |
304 | 304 |
305 // Show all VPN providers and all networks that are currently disconnected. | 305 // Show all VPN providers and all networks that are currently disconnected. |
306 AddProvidersAndNetworks(networks); | 306 AddProvidersAndNetworks(networks); |
307 | 307 |
308 // Determine whether one of the new list entries corresponds to the entry that | 308 // Determine whether one of the new list entries corresponds to the entry that |
309 // the user was previously hovering over. If such an entry is found, the list | 309 // the user was previously hovering over. If such an entry is found, the list |
310 // will be scrolled to ensure the entry is visible. | 310 // will be scrolled to ensure the entry is visible. |
311 const views::View* scroll_to_show_view = nullptr; | 311 const views::View* scroll_to_show_view = nullptr; |
312 if (hovered_provider) { | 312 if (hovered_provider) { |
313 for (const std::pair<const views::View* const, VPNProvider>& provider : | 313 for (const std::pair<const views::View* const, VPNProvider>& provider : |
314 provider_view_map_) { | 314 provider_view_map_) { |
315 if (provider.second == *hovered_provider) { | 315 if (provider.second == *hovered_provider) { |
316 scroll_to_show_view = provider.first; | 316 scroll_to_show_view = provider.first; |
317 break; | 317 break; |
318 } | 318 } |
319 } | 319 } |
320 } else if (!hovered_network_service_path.empty()) { | 320 } else if (!hovered_network_guid.empty()) { |
321 for (const std::pair<const views::View*, std::string>& entry : | 321 for (const std::pair<const views::View*, std::string>& entry : |
322 network_view_service_path_map_) { | 322 network_view_guid_map_) { |
323 if (entry.second == hovered_network_service_path) { | 323 if (entry.second == hovered_network_guid) { |
324 scroll_to_show_view = entry.first; | 324 scroll_to_show_view = entry.first; |
325 break; | 325 break; |
326 } | 326 } |
327 } | 327 } |
328 } | 328 } |
329 | 329 |
330 // Layout the updated list. | 330 // Layout the updated list. |
331 container()->SizeToPreferredSize(); | 331 container()->SizeToPreferredSize(); |
332 delegate_->RelayoutScrollList(); | 332 delegate_->RelayoutScrollList(); |
333 | 333 |
334 if (scroll_to_show_view) { | 334 if (scroll_to_show_view) { |
335 // Scroll the list so that |scroll_to_show_view| is in view. | 335 // Scroll the list so that |scroll_to_show_view| is in view. |
336 container()->ScrollRectToVisible(scroll_to_show_view->bounds()); | 336 container()->ScrollRectToVisible(scroll_to_show_view->bounds()); |
337 } | 337 } |
338 } | 338 } |
339 | 339 |
340 bool VPNListView::IsNetworkEntry(views::View* view, | 340 bool VPNListView::IsNetworkEntry(views::View* view, std::string* guid) const { |
341 std::string* service_path) const { | 341 const auto& entry = network_view_guid_map_.find(view); |
342 const auto& entry = network_view_service_path_map_.find(view); | 342 if (entry == network_view_guid_map_.end()) |
343 if (entry == network_view_service_path_map_.end()) | |
344 return false; | 343 return false; |
345 *service_path = entry->second; | 344 *guid = entry->second; |
346 return true; | 345 return true; |
347 } | 346 } |
348 | 347 |
349 void VPNListView::OnVPNProvidersChanged() { | 348 void VPNListView::OnVPNProvidersChanged() { |
350 Update(); | 349 Update(); |
351 } | 350 } |
352 | 351 |
353 void VPNListView::OnViewClicked(views::View* sender) { | 352 void VPNListView::OnViewClicked(views::View* sender) { |
354 const auto& provider_iter = provider_view_map_.find(sender); | 353 const auto& provider_iter = provider_view_map_.find(sender); |
355 if (provider_iter != provider_view_map_.end()) { | 354 if (provider_iter != provider_view_map_.end()) { |
(...skipping 15 matching lines...) Expand all Loading... |
371 | 370 |
372 // If the user clicked on a network entry, let the |delegate_| trigger a | 371 // If the user clicked on a network entry, let the |delegate_| trigger a |
373 // connection attempt (if the network is currently disconnected) or show a | 372 // connection attempt (if the network is currently disconnected) or show a |
374 // configuration dialog (if the network is currently connected or connecting). | 373 // configuration dialog (if the network is currently connected or connecting). |
375 delegate_->OnNetworkEntryClicked(sender); | 374 delegate_->OnNetworkEntryClicked(sender); |
376 } | 375 } |
377 | 376 |
378 void VPNListView::AddNetwork(const chromeos::NetworkState* network) { | 377 void VPNListView::AddNetwork(const chromeos::NetworkState* network) { |
379 views::View* entry(new VPNListNetworkEntry(this, network)); | 378 views::View* entry(new VPNListNetworkEntry(this, network)); |
380 container()->AddChildView(entry); | 379 container()->AddChildView(entry); |
381 network_view_service_path_map_[entry] = network->path(); | 380 network_view_guid_map_[entry] = network->guid(); |
382 list_empty_ = false; | 381 list_empty_ = false; |
383 } | 382 } |
384 | 383 |
385 void VPNListView::AddProviderAndNetworks( | 384 void VPNListView::AddProviderAndNetworks( |
386 const VPNProvider& vpn_provider, | 385 const VPNProvider& vpn_provider, |
387 const chromeos::NetworkStateHandler::NetworkStateList& networks) { | 386 const chromeos::NetworkStateHandler::NetworkStateList& networks) { |
388 // Add a visual separator, unless this is the topmost entry in the list. | 387 // Add a visual separator, unless this is the topmost entry in the list. |
389 if (!list_empty_) | 388 if (!list_empty_) |
390 container()->AddChildView(TrayPopupUtils::CreateListSubHeaderSeparator()); | 389 container()->AddChildView(TrayPopupUtils::CreateListSubHeaderSeparator()); |
391 std::string vpn_name = | 390 std::string vpn_name = |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 } | 431 } |
433 } | 432 } |
434 | 433 |
435 // Add providers without any configured networks, in the order that the | 434 // Add providers without any configured networks, in the order that the |
436 // providers were returned by the extensions system. | 435 // providers were returned by the extensions system. |
437 for (const VPNProvider& provider : providers) | 436 for (const VPNProvider& provider : providers) |
438 AddProviderAndNetworks(provider, networks); | 437 AddProviderAndNetworks(provider, networks); |
439 } | 438 } |
440 | 439 |
441 } // namespace ash | 440 } // namespace ash |
OLD | NEW |