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/network_icon.h" | 5 #include "ash/system/chromeos/network/network_icon.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/system/chromeos/network/network_icon_animation.h" | 8 #include "ash/system/chromeos/network/network_icon_animation.h" |
9 #include "ash/system/chromeos/network/network_icon_animation_observer.h" | 9 #include "ash/system/chromeos/network/network_icon_animation_observer.h" |
10 #include "ash/system/tray/system_tray_delegate.h" | 10 #include "ash/system/tray/system_tray_delegate.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chromeos/network/device_state.h" | 12 #include "chromeos/network/device_state.h" |
13 #include "chromeos/network/network_connection_handler.h" | 13 #include "chromeos/network/network_connection_handler.h" |
14 #include "chromeos/network/network_state.h" | 14 #include "chromeos/network/network_state.h" |
15 #include "chromeos/network/network_state_handler.h" | 15 #include "chromeos/network/network_state_handler.h" |
16 #include "grit/ash_resources.h" | 16 #include "grit/ash_resources.h" |
17 #include "grit/ash_strings.h" | 17 #include "grit/ash_strings.h" |
18 #include "third_party/cros_system_api/dbus/service_constants.h" | 18 #include "third_party/cros_system_api/dbus/service_constants.h" |
19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/base/webui/web_ui_util.h" |
21 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
22 #include "ui/gfx/image/image_skia_operations.h" | 23 #include "ui/gfx/image/image_skia_operations.h" |
23 #include "ui/gfx/image/image_skia_source.h" | 24 #include "ui/gfx/image/image_skia_source.h" |
24 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
25 #include "ui/gfx/size_conversions.h" | 26 #include "ui/gfx/size_conversions.h" |
26 | 27 |
27 using chromeos::DeviceState; | 28 using chromeos::DeviceState; |
28 using chromeos::NetworkConnectionHandler; | 29 using chromeos::NetworkConnectionHandler; |
29 using chromeos::NetworkHandler; | 30 using chromeos::NetworkHandler; |
30 using chromeos::NetworkState; | 31 using chromeos::NetworkState; |
(...skipping 17 matching lines...) Expand all Loading... |
48 const gfx::ImageSkia* top_left; | 49 const gfx::ImageSkia* top_left; |
49 const gfx::ImageSkia* top_right; | 50 const gfx::ImageSkia* top_right; |
50 const gfx::ImageSkia* bottom_left; | 51 const gfx::ImageSkia* bottom_left; |
51 const gfx::ImageSkia* bottom_right; | 52 const gfx::ImageSkia* bottom_right; |
52 }; | 53 }; |
53 | 54 |
54 //------------------------------------------------------------------------------ | 55 //------------------------------------------------------------------------------ |
55 // class used for maintaining a map of network state and images. | 56 // class used for maintaining a map of network state and images. |
56 class NetworkIconImpl { | 57 class NetworkIconImpl { |
57 public: | 58 public: |
58 explicit NetworkIconImpl(IconType icon_type); | 59 NetworkIconImpl(const std::string& path, IconType icon_type); |
59 | 60 |
60 // Determines whether or not the associated network might be dirty and if so | 61 // Determines whether or not the associated network might be dirty and if so |
61 // updates and generates the icon. Does nothing if network no longer exists. | 62 // updates and generates the icon. Does nothing if network no longer exists. |
62 void Update(const chromeos::NetworkState* network); | 63 void Update(const chromeos::NetworkState* network); |
63 | 64 |
| 65 // Returns the cached image url for |image_| based on |scale_factor|. |
| 66 const std::string& GetImageUrl(float scale_factor); |
| 67 |
64 const gfx::ImageSkia& image() const { return image_; } | 68 const gfx::ImageSkia& image() const { return image_; } |
65 | 69 |
66 private: | 70 private: |
| 71 typedef std::map<float, std::string> ImageUrlMap; |
| 72 |
67 // Updates |strength_index_| for wireless networks. Returns true if changed. | 73 // Updates |strength_index_| for wireless networks. Returns true if changed. |
68 bool UpdateWirelessStrengthIndex(const chromeos::NetworkState* network); | 74 bool UpdateWirelessStrengthIndex(const chromeos::NetworkState* network); |
69 | 75 |
70 // Updates the local state for cellular networks. Returns true if changed. | 76 // Updates the local state for cellular networks. Returns true if changed. |
71 bool UpdateCellularState(const chromeos::NetworkState* network); | 77 bool UpdateCellularState(const chromeos::NetworkState* network); |
72 | 78 |
73 // Updates the portal state for wireless networks. Returns true if changed. | 79 // Updates the portal state for wireless networks. Returns true if changed. |
74 bool UpdatePortalState(const chromeos::NetworkState* network); | 80 bool UpdatePortalState(const chromeos::NetworkState* network); |
75 | 81 |
76 // Updates the VPN badge. Returns true if changed. | 82 // Updates the VPN badge. Returns true if changed. |
77 bool UpdateVPNBadge(); | 83 bool UpdateVPNBadge(); |
78 | 84 |
79 // Gets |badges| based on |network| and the current state. | 85 // Gets |badges| based on |network| and the current state. |
80 void GetBadges(const NetworkState* network, Badges* badges); | 86 void GetBadges(const NetworkState* network, Badges* badges); |
81 | 87 |
82 // Gets the appropriate icon and badges and composites the image. | 88 // Gets the appropriate icon and badges and composites the image. |
83 void GenerateImage(const chromeos::NetworkState* network); | 89 void GenerateImage(const chromeos::NetworkState* network); |
84 | 90 |
| 91 // Network path, used for debugging. |
| 92 std::string network_path_; |
| 93 |
85 // Defines color theme and VPN badging | 94 // Defines color theme and VPN badging |
86 const IconType icon_type_; | 95 const IconType icon_type_; |
87 | 96 |
88 // Cached state of the network when the icon was last generated. | 97 // Cached state of the network when the icon was last generated. |
89 std::string state_; | 98 std::string state_; |
90 | 99 |
91 // Cached strength index of the network when the icon was last generated. | 100 // Cached strength index of the network when the icon was last generated. |
92 int strength_index_; | 101 int strength_index_; |
93 | 102 |
94 // Cached technology badge for the network when the icon was last generated. | 103 // Cached technology badge for the network when the icon was last generated. |
95 const gfx::ImageSkia* technology_badge_; | 104 const gfx::ImageSkia* technology_badge_; |
96 | 105 |
97 // Cached vpn badge for the network when the icon was last generated. | 106 // Cached vpn badge for the network when the icon was last generated. |
98 const gfx::ImageSkia* vpn_badge_; | 107 const gfx::ImageSkia* vpn_badge_; |
99 | 108 |
100 // Cached roaming state of the network when the icon was last generated. | 109 // Cached roaming state of the network when the icon was last generated. |
101 std::string roaming_state_; | 110 std::string roaming_state_; |
102 | 111 |
103 // Cached portal state of the network when the icon was last generated. | 112 // Cached portal state of the network when the icon was last generated. |
104 bool behind_captive_portal_; | 113 bool behind_captive_portal_; |
105 | 114 |
106 // Generated icon image. | 115 // Generated icon image. |
107 gfx::ImageSkia image_; | 116 gfx::ImageSkia image_; |
108 | 117 |
| 118 // Map of cached image urls by scale factor. Cleared whenever image_ is |
| 119 // generated. |
| 120 ImageUrlMap image_urls_; |
| 121 |
109 DISALLOW_COPY_AND_ASSIGN(NetworkIconImpl); | 122 DISALLOW_COPY_AND_ASSIGN(NetworkIconImpl); |
110 }; | 123 }; |
111 | 124 |
112 //------------------------------------------------------------------------------ | 125 //------------------------------------------------------------------------------ |
113 // Maintain a static (global) icon map. Note: Icons are never destroyed; | 126 // Maintain a static (global) icon map. Note: Icons are never destroyed; |
114 // it is assumed that a finite and reasonable number of network icons will be | 127 // it is assumed that a finite and reasonable number of network icons will be |
115 // created during a session. | 128 // created during a session. |
116 | 129 |
117 typedef std::map<std::string, NetworkIconImpl*> NetworkIconMap; | 130 typedef std::map<std::string, NetworkIconImpl*> NetworkIconMap; |
118 | 131 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 private: | 263 private: |
251 const gfx::ImageSkia icon_; | 264 const gfx::ImageSkia icon_; |
252 const Badges badges_; | 265 const Badges badges_; |
253 | 266 |
254 DISALLOW_COPY_AND_ASSIGN(NetworkIconImageSource); | 267 DISALLOW_COPY_AND_ASSIGN(NetworkIconImageSource); |
255 }; | 268 }; |
256 | 269 |
257 //------------------------------------------------------------------------------ | 270 //------------------------------------------------------------------------------ |
258 // Utilities for extracting icon images. | 271 // Utilities for extracting icon images. |
259 | 272 |
| 273 // A struct used for caching image urls. |
| 274 struct ImageIdForNetworkType { |
| 275 ImageIdForNetworkType(IconType icon_type, |
| 276 const std::string& network_type, |
| 277 float scale_factor) : |
| 278 icon_type(icon_type), |
| 279 network_type(network_type), |
| 280 scale_factor(scale_factor) {} |
| 281 bool operator<(const ImageIdForNetworkType& other) const { |
| 282 if (icon_type != other.icon_type) |
| 283 return icon_type < other.icon_type; |
| 284 if (network_type != other.network_type) |
| 285 return network_type < other.network_type; |
| 286 return scale_factor < other.scale_factor; |
| 287 } |
| 288 IconType icon_type; |
| 289 std::string network_type; |
| 290 float scale_factor; |
| 291 }; |
| 292 |
| 293 typedef std::map<ImageIdForNetworkType, std::string> ImageIdUrlMap; |
| 294 |
260 bool IconTypeIsDark(IconType icon_type) { | 295 bool IconTypeIsDark(IconType icon_type) { |
261 return (icon_type != ICON_TYPE_TRAY); | 296 return (icon_type != ICON_TYPE_TRAY); |
262 } | 297 } |
263 | 298 |
264 bool IconTypeHasVPNBadge(IconType icon_type) { | 299 bool IconTypeHasVPNBadge(IconType icon_type) { |
265 return (icon_type != ICON_TYPE_LIST); | 300 return (icon_type != ICON_TYPE_LIST); |
266 } | 301 } |
267 | 302 |
268 int NumImagesForType(ImageType type) { | 303 int NumImagesForType(ImageType type) { |
269 return (type == BARS) ? kNumBarsImages : kNumArcsImages; | 304 return (type == BARS) ? kNumBarsImages : kNumArcsImages; |
(...skipping 29 matching lines...) Expand all Loading... |
299 int num_images = NumImagesForType(image_type); | 334 int num_images = NumImagesForType(image_type); |
300 if (index < 0 || index >= num_images) | 335 if (index < 0 || index >= num_images) |
301 return gfx::ImageSkia(); | 336 return gfx::ImageSkia(); |
302 gfx::ImageSkia* images = BaseImageForType(image_type, icon_type); | 337 gfx::ImageSkia* images = BaseImageForType(image_type, icon_type); |
303 int width = images->width(); | 338 int width = images->width(); |
304 int height = images->height() / num_images; | 339 int height = images->height() / num_images; |
305 return gfx::ImageSkiaOperations::ExtractSubset(*images, | 340 return gfx::ImageSkiaOperations::ExtractSubset(*images, |
306 gfx::Rect(0, index * height, width, height)); | 341 gfx::Rect(0, index * height, width, height)); |
307 } | 342 } |
308 | 343 |
309 const gfx::ImageSkia GetConnectedImage(const std::string& type, | 344 const gfx::ImageSkia GetConnectedImage(IconType icon_type, |
310 IconType icon_type) { | 345 const std::string& network_type) { |
311 if (type == shill::kTypeVPN) { | 346 if (network_type == shill::kTypeVPN) { |
312 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 347 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
313 IDR_AURA_UBER_TRAY_NETWORK_VPN); | 348 IDR_AURA_UBER_TRAY_NETWORK_VPN); |
314 } | 349 } |
315 ImageType image_type = ImageTypeForNetworkType(type); | 350 ImageType image_type = ImageTypeForNetworkType(network_type); |
316 const int connected_index = NumImagesForType(image_type) - 1; | 351 const int connected_index = NumImagesForType(image_type) - 1; |
317 return GetImageForIndex(image_type, icon_type, connected_index); | 352 return GetImageForIndex(image_type, icon_type, connected_index); |
318 } | 353 } |
319 | 354 |
320 const gfx::ImageSkia GetDisconnectedImage(const std::string& type, | 355 const gfx::ImageSkia GetDisconnectedImage(IconType icon_type, |
321 IconType icon_type) { | 356 const std::string& network_type) { |
322 if (type == shill::kTypeVPN) { | 357 if (network_type == shill::kTypeVPN) { |
323 // Note: same as connected image, shouldn't normally be seen. | 358 // Note: same as connected image, shouldn't normally be seen. |
324 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 359 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
325 IDR_AURA_UBER_TRAY_NETWORK_VPN); | 360 IDR_AURA_UBER_TRAY_NETWORK_VPN); |
326 } | 361 } |
327 ImageType image_type = ImageTypeForNetworkType(type); | 362 ImageType image_type = ImageTypeForNetworkType(network_type); |
328 const int disconnected_index = 0; | 363 const int disconnected_index = 0; |
329 return GetImageForIndex(image_type, icon_type, disconnected_index); | 364 return GetImageForIndex(image_type, icon_type, disconnected_index); |
330 } | 365 } |
331 | 366 |
| 367 const std::string& GetDisconnectedImageUrl(IconType icon_type, |
| 368 const std::string& network_type, |
| 369 float scale_factor) { |
| 370 static ImageIdUrlMap* s_image_url_map = NULL; |
| 371 if (s_image_url_map == NULL) |
| 372 s_image_url_map = new ImageIdUrlMap; |
| 373 |
| 374 ImageIdForNetworkType key(icon_type, network_type, scale_factor); |
| 375 ImageIdUrlMap::iterator iter = s_image_url_map->find(key); |
| 376 if (iter != s_image_url_map->end()) |
| 377 return iter->second; |
| 378 |
| 379 VLOG(2) << "Generating disconnected bitmap URL for: " << network_type; |
| 380 gfx::ImageSkia image = GetDisconnectedImage(icon_type, network_type); |
| 381 gfx::ImageSkiaRep image_rep = image.GetRepresentation(scale_factor); |
| 382 iter = s_image_url_map->insert(std::make_pair( |
| 383 key, webui::GetBitmapDataUrl(image_rep.sk_bitmap()))).first; |
| 384 return iter->second; |
| 385 } |
| 386 |
332 gfx::ImageSkia* ConnectingWirelessImage(ImageType image_type, | 387 gfx::ImageSkia* ConnectingWirelessImage(ImageType image_type, |
333 IconType icon_type, | 388 IconType icon_type, |
334 double animation) { | 389 double animation) { |
335 static gfx::ImageSkia* s_bars_images_dark[kNumBarsImages - 1]; | 390 static gfx::ImageSkia* s_bars_images_dark[kNumBarsImages - 1]; |
336 static gfx::ImageSkia* s_bars_images_light[kNumBarsImages - 1]; | 391 static gfx::ImageSkia* s_bars_images_light[kNumBarsImages - 1]; |
337 static gfx::ImageSkia* s_arcs_images_dark[kNumArcsImages - 1]; | 392 static gfx::ImageSkia* s_arcs_images_dark[kNumArcsImages - 1]; |
338 static gfx::ImageSkia* s_arcs_images_light[kNumArcsImages - 1]; | 393 static gfx::ImageSkia* s_arcs_images_light[kNumArcsImages - 1]; |
339 int image_count = NumImagesForType(image_type) - 1; | 394 int image_count = NumImagesForType(image_type) - 1; |
340 int index = animation * nextafter(static_cast<float>(image_count), 0); | 395 int index = animation * nextafter(static_cast<float>(image_count), 0); |
341 index = std::max(std::min(index, image_count - 1), 0); | 396 index = std::max(std::min(index, image_count - 1), 0); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 badges.bottom_left = ConnectingVpnBadge(animation); | 557 badges.bottom_left = ConnectingVpnBadge(animation); |
503 return gfx::ImageSkia( | 558 return gfx::ImageSkia( |
504 new NetworkIconImageSource(icon, badges), icon.size()); | 559 new NetworkIconImageSource(icon, badges), icon.size()); |
505 } else { | 560 } else { |
506 gfx::ImageSkia* icon = ConnectingVpnImage(animation); | 561 gfx::ImageSkia* icon = ConnectingVpnImage(animation); |
507 return gfx::ImageSkia( | 562 return gfx::ImageSkia( |
508 new NetworkIconImageSource(*icon, Badges()), icon->size()); | 563 new NetworkIconImageSource(*icon, Badges()), icon->size()); |
509 } | 564 } |
510 } | 565 } |
511 | 566 |
512 gfx::ImageSkia GetConnectingImage(const std::string& network_type, | 567 gfx::ImageSkia GetConnectingImage(IconType icon_type, |
513 IconType icon_type) { | 568 const std::string& network_type) { |
514 if (network_type == shill::kTypeVPN) | 569 if (network_type == shill::kTypeVPN) |
515 return GetConnectingVpnImage(icon_type); | 570 return GetConnectingVpnImage(icon_type); |
516 | 571 |
517 ImageType image_type = ImageTypeForNetworkType(network_type); | 572 ImageType image_type = ImageTypeForNetworkType(network_type); |
518 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); | 573 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); |
519 | 574 |
520 gfx::ImageSkia* icon = ConnectingWirelessImage( | 575 gfx::ImageSkia* icon = ConnectingWirelessImage( |
521 image_type, icon_type, animation); | 576 image_type, icon_type, animation); |
522 return gfx::ImageSkia( | 577 return gfx::ImageSkia( |
523 new NetworkIconImageSource(*icon, Badges()), icon->size()); | 578 new NetworkIconImageSource(*icon, Badges()), icon->size()); |
524 } | 579 } |
525 | 580 |
| 581 std::string GetConnectingImageUrl(IconType icon_type, |
| 582 const std::string& network_type, |
| 583 float scale_factor) { |
| 584 // Caching the connecting image is complicated and we will never draw more |
| 585 // than a few per frame, so just generate the image url each time. |
| 586 gfx::ImageSkia image = GetConnectingImage(icon_type, network_type); |
| 587 gfx::ImageSkiaRep image_rep = image.GetRepresentation(scale_factor); |
| 588 return webui::GetBitmapDataUrl(image_rep.sk_bitmap()); |
| 589 } |
| 590 |
526 } // namespace | 591 } // namespace |
527 | 592 |
528 //------------------------------------------------------------------------------ | 593 //------------------------------------------------------------------------------ |
529 // NetworkIconImpl | 594 // NetworkIconImpl |
530 | 595 |
531 NetworkIconImpl::NetworkIconImpl(IconType icon_type) | 596 NetworkIconImpl::NetworkIconImpl(const std::string& path, IconType icon_type) |
532 : icon_type_(icon_type), | 597 : network_path_(path), |
| 598 icon_type_(icon_type), |
533 strength_index_(-1), | 599 strength_index_(-1), |
534 technology_badge_(NULL), | 600 technology_badge_(NULL), |
535 vpn_badge_(NULL), | 601 vpn_badge_(NULL), |
536 behind_captive_portal_(false) { | 602 behind_captive_portal_(false) { |
537 // Default image | 603 // Default image |
538 image_ = GetDisconnectedImage(shill::kTypeWifi, icon_type); | 604 image_ = GetDisconnectedImage(icon_type, shill::kTypeWifi); |
539 } | 605 } |
540 | 606 |
541 void NetworkIconImpl::Update(const NetworkState* network) { | 607 void NetworkIconImpl::Update(const NetworkState* network) { |
542 DCHECK(network); | 608 DCHECK(network); |
543 // Determine whether or not we need to update the icon. | 609 // Determine whether or not we need to update the icon. |
544 bool dirty = image_.isNull(); | 610 bool dirty = image_.isNull(); |
545 | 611 |
546 // If the network state has changed, the icon needs updating. | 612 // If the network state has changed, the icon needs updating. |
547 if (state_ != network->connection_state()) { | 613 if (state_ != network->connection_state()) { |
548 state_ = network->connection_state(); | 614 state_ = network->connection_state(); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 } | 733 } |
668 } | 734 } |
669 | 735 |
670 void NetworkIconImpl::GenerateImage(const NetworkState* network) { | 736 void NetworkIconImpl::GenerateImage(const NetworkState* network) { |
671 DCHECK(network); | 737 DCHECK(network); |
672 gfx::ImageSkia icon = GetIcon(network, icon_type_, strength_index_); | 738 gfx::ImageSkia icon = GetIcon(network, icon_type_, strength_index_); |
673 Badges badges; | 739 Badges badges; |
674 GetBadges(network, &badges); | 740 GetBadges(network, &badges); |
675 image_ = gfx::ImageSkia( | 741 image_ = gfx::ImageSkia( |
676 new NetworkIconImageSource(icon, badges), icon.size()); | 742 new NetworkIconImageSource(icon, badges), icon.size()); |
| 743 image_urls_.clear(); |
677 } | 744 } |
678 | 745 |
679 //------------------------------------------------------------------------------ | 746 const std::string& NetworkIconImpl::GetImageUrl(float scale_factor) { |
680 // Public interface | 747 ImageUrlMap::iterator iter = image_urls_.find(scale_factor); |
| 748 if (iter != image_urls_.end()) |
| 749 return iter->second; |
681 | 750 |
682 gfx::ImageSkia GetImageForNetwork(const NetworkState* network, | 751 VLOG(2) << "Generating bitmap URL for: " << network_path_; |
683 IconType icon_type) { | 752 gfx::ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); |
684 DCHECK(network); | 753 iter = image_urls_.insert(std::make_pair( |
685 // Handle connecting icons. | 754 scale_factor, webui::GetBitmapDataUrl(image_rep.sk_bitmap()))).first; |
686 if (network->IsConnectingState()) | 755 return iter->second; |
687 return GetConnectingImage(network->type(), icon_type); | 756 } |
688 | 757 |
| 758 namespace { |
| 759 |
| 760 NetworkIconImpl* FindAndUpdateImageImpl(const NetworkState* network, |
| 761 IconType icon_type) { |
689 // Find or add the icon. | 762 // Find or add the icon. |
690 NetworkIconMap* icon_map = GetIconMap(icon_type); | 763 NetworkIconMap* icon_map = GetIconMap(icon_type); |
691 NetworkIconImpl* icon; | 764 NetworkIconImpl* icon; |
692 NetworkIconMap::iterator iter = icon_map->find(network->path()); | 765 NetworkIconMap::iterator iter = icon_map->find(network->path()); |
693 if (iter == icon_map->end()) { | 766 if (iter == icon_map->end()) { |
694 icon = new NetworkIconImpl(icon_type); | 767 icon = new NetworkIconImpl(network->path(), icon_type); |
695 icon_map->insert(std::make_pair(network->path(), icon)); | 768 icon_map->insert(std::make_pair(network->path(), icon)); |
696 } else { | 769 } else { |
697 icon = iter->second; | 770 icon = iter->second; |
698 } | 771 } |
699 | 772 |
700 // Update and return the icon's image. | 773 // Update and return the icon's image. |
701 icon->Update(network); | 774 icon->Update(network); |
| 775 return icon; |
| 776 } |
| 777 |
| 778 } // namespace |
| 779 |
| 780 //------------------------------------------------------------------------------ |
| 781 // Public interface |
| 782 |
| 783 gfx::ImageSkia GetImageForNetwork(const NetworkState* network, |
| 784 IconType icon_type) { |
| 785 DCHECK(network); |
| 786 // Handle connecting icons. |
| 787 if (network->IsConnectingState()) |
| 788 return GetConnectingImage(icon_type, network->type()); |
| 789 |
| 790 NetworkIconImpl* icon = FindAndUpdateImageImpl(network, icon_type); |
702 return icon->image(); | 791 return icon->image(); |
703 } | 792 } |
704 | 793 |
| 794 std::string GetImageUrlForNetwork(const NetworkState* network, |
| 795 IconType icon_type, |
| 796 float scale_factor) { |
| 797 DCHECK(network); |
| 798 // Handle connecting icons. |
| 799 if (network->IsConnectingState()) |
| 800 return GetConnectingImageUrl(icon_type, network->type(), scale_factor); |
| 801 |
| 802 NetworkIconImpl* icon = FindAndUpdateImageImpl(network, icon_type); |
| 803 return icon->GetImageUrl(scale_factor); |
| 804 } |
| 805 |
705 gfx::ImageSkia GetImageForConnectedNetwork(IconType icon_type, | 806 gfx::ImageSkia GetImageForConnectedNetwork(IconType icon_type, |
706 const std::string& network_type) { | 807 const std::string& network_type) { |
707 return GetConnectedImage(network_type, icon_type); | 808 return GetConnectedImage(icon_type, network_type); |
708 } | 809 } |
709 | 810 |
710 gfx::ImageSkia GetImageForConnectingNetwork(IconType icon_type, | 811 gfx::ImageSkia GetImageForConnectingNetwork(IconType icon_type, |
711 const std::string& network_type) { | 812 const std::string& network_type) { |
712 return GetConnectingImage(network_type, icon_type); | 813 return GetConnectingImage(icon_type, network_type); |
713 } | 814 } |
714 | 815 |
715 gfx::ImageSkia GetImageForDisconnectedNetwork(IconType icon_type, | 816 gfx::ImageSkia GetImageForDisconnectedNetwork(IconType icon_type, |
716 const std::string& network_type) { | 817 const std::string& network_type) { |
717 return GetDisconnectedImage(network_type, icon_type); | 818 return GetDisconnectedImage(icon_type, network_type); |
| 819 } |
| 820 |
| 821 std::string GetImageUrlForDisconnectedNetwork(IconType icon_type, |
| 822 const std::string& network_type, |
| 823 float scale_factor) { |
| 824 return GetDisconnectedImageUrl(icon_type, network_type, scale_factor); |
718 } | 825 } |
719 | 826 |
720 base::string16 GetLabelForNetwork(const chromeos::NetworkState* network, | 827 base::string16 GetLabelForNetwork(const chromeos::NetworkState* network, |
721 IconType icon_type) { | 828 IconType icon_type) { |
722 DCHECK(network); | 829 DCHECK(network); |
723 std::string activation_state = network->activation_state(); | 830 std::string activation_state = network->activation_state(); |
724 if (icon_type == ICON_TYPE_LIST) { | 831 if (icon_type == ICON_TYPE_LIST) { |
725 // Show "<network>: [Connecting|Activating]..." | 832 // Show "<network>: [Connecting|Activating]..." |
726 if (network->IsConnectingState()) { | 833 if (network->IsConnectingState()) { |
727 return l10n_util::GetStringFUTF16( | 834 return l10n_util::GetStringFUTF16( |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 iter != networks.end(); ++iter) { | 976 iter != networks.end(); ++iter) { |
870 network_paths.insert((*iter)->path()); | 977 network_paths.insert((*iter)->path()); |
871 } | 978 } |
872 PurgeIconMap(ICON_TYPE_TRAY, network_paths); | 979 PurgeIconMap(ICON_TYPE_TRAY, network_paths); |
873 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); | 980 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); |
874 PurgeIconMap(ICON_TYPE_LIST, network_paths); | 981 PurgeIconMap(ICON_TYPE_LIST, network_paths); |
875 } | 982 } |
876 | 983 |
877 } // namespace network_icon | 984 } // namespace network_icon |
878 } // namespace ash | 985 } // namespace ash |
OLD | NEW |