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