| 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 "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chromeos/network/device_state.h" | 11 #include "chromeos/network/device_state.h" |
| 12 #include "chromeos/network/network_state.h" | 12 #include "chromeos/network/network_state.h" |
| 13 #include "chromeos/network/network_state_handler.h" | 13 #include "chromeos/network/network_state_handler.h" |
| 14 #include "grit/ash_resources.h" | 14 #include "grit/ash_resources.h" |
| 15 #include "grit/ash_strings.h" | 15 #include "grit/ash_strings.h" |
| 16 #include "third_party/cros_system_api/dbus/service_constants.h" | 16 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 20 #include "ui/gfx/image/image_skia_operations.h" | 20 #include "ui/gfx/image/image_skia_operations.h" |
| 21 #include "ui/gfx/image/image_skia_source.h" | 21 #include "ui/gfx/image/image_skia_source.h" |
| 22 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
| 23 #include "ui/gfx/size_conversions.h" | 23 #include "ui/gfx/size_conversions.h" |
| 24 | 24 |
| 25 using chromeos::DeviceState; | 25 using chromeos::DeviceState; |
| 26 using chromeos::NetworkHandler; |
| 27 using chromeos::NetworkState; |
| 26 using chromeos::NetworkStateHandler; | 28 using chromeos::NetworkStateHandler; |
| 27 using chromeos::NetworkState; | |
| 28 | 29 |
| 29 namespace ash { | 30 namespace ash { |
| 30 namespace network_icon { | 31 namespace network_icon { |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 //------------------------------------------------------------------------------ | 35 //------------------------------------------------------------------------------ |
| 35 // Struct to pass icon badges to NetworkIconImageSource. | 36 // Struct to pass icon badges to NetworkIconImageSource. |
| 36 struct Badges { | 37 struct Badges { |
| 37 Badges() | 38 Badges() |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 } else { | 438 } else { |
| 438 LOG(WARNING) << "Request for icon for unsupported type: " << type; | 439 LOG(WARNING) << "Request for icon for unsupported type: " << type; |
| 439 return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); | 440 return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); |
| 440 } | 441 } |
| 441 } | 442 } |
| 442 | 443 |
| 443 //------------------------------------------------------------------------------ | 444 //------------------------------------------------------------------------------ |
| 444 // Get connecting images | 445 // Get connecting images |
| 445 | 446 |
| 446 gfx::ImageSkia GetConnectingVpnImage(IconType icon_type) { | 447 gfx::ImageSkia GetConnectingVpnImage(IconType icon_type) { |
| 447 NetworkStateHandler* handler = NetworkStateHandler::Get(); | 448 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
| 448 const NetworkState* connected_network = NULL; | 449 const NetworkState* connected_network = NULL; |
| 449 if (icon_type == ICON_TYPE_TRAY) { | 450 if (icon_type == ICON_TYPE_TRAY) { |
| 450 connected_network = handler->ConnectedNetworkByType( | 451 connected_network = handler->ConnectedNetworkByType( |
| 451 NetworkStateHandler::kMatchTypeNonVirtual); | 452 NetworkStateHandler::kMatchTypeNonVirtual); |
| 452 } | 453 } |
| 453 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); | 454 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); |
| 454 | 455 |
| 455 if (connected_network) { | 456 if (connected_network) { |
| 456 gfx::ImageSkia icon = GetImageForNetwork(connected_network, icon_type); | 457 gfx::ImageSkia icon = GetImageForNetwork(connected_network, icon_type); |
| 457 Badges badges; | 458 Badges badges; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 } | 540 } |
| 540 std::string roaming_state = network->roaming(); | 541 std::string roaming_state = network->roaming(); |
| 541 if (roaming_state != roaming_state_) { | 542 if (roaming_state != roaming_state_) { |
| 542 roaming_state_ = roaming_state; | 543 roaming_state_ = roaming_state; |
| 543 dirty = true; | 544 dirty = true; |
| 544 } | 545 } |
| 545 return dirty; | 546 return dirty; |
| 546 } | 547 } |
| 547 | 548 |
| 548 bool NetworkIconImpl::UpdateVPNBadge() { | 549 bool NetworkIconImpl::UpdateVPNBadge() { |
| 549 const NetworkState* vpn = | 550 const NetworkState* vpn = NetworkHandler::Get()->network_state_handler()-> |
| 550 NetworkStateHandler::Get()->ConnectedNetworkByType(flimflam::kTypeVPN); | 551 ConnectedNetworkByType(flimflam::kTypeVPN); |
| 551 if (vpn && vpn_badge_ == NULL) { | 552 if (vpn && vpn_badge_ == NULL) { |
| 552 vpn_badge_ = BadgeForVPN(icon_type_); | 553 vpn_badge_ = BadgeForVPN(icon_type_); |
| 553 return true; | 554 return true; |
| 554 } else if (!vpn && vpn_badge_ != NULL) { | 555 } else if (!vpn && vpn_badge_ != NULL) { |
| 555 vpn_badge_ = NULL; | 556 vpn_badge_ = NULL; |
| 556 return true; | 557 return true; |
| 557 } | 558 } |
| 558 return false; | 559 return false; |
| 559 } | 560 } |
| 560 | 561 |
| 561 void NetworkIconImpl::GetBadges(const NetworkState* network, Badges* badges) { | 562 void NetworkIconImpl::GetBadges(const NetworkState* network, Badges* badges) { |
| 562 DCHECK(network); | 563 DCHECK(network); |
| 563 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 564 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 564 NetworkStateHandler* handler = NetworkStateHandler::Get(); | 565 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
| 565 | 566 |
| 566 const std::string& type = network->type(); | 567 const std::string& type = network->type(); |
| 567 if (type == flimflam::kTypeWifi) { | 568 if (type == flimflam::kTypeWifi) { |
| 568 if (network->security() != flimflam::kSecurityNone && | 569 if (network->security() != flimflam::kSecurityNone && |
| 569 IconTypeIsDark(icon_type_)) { | 570 IconTypeIsDark(icon_type_)) { |
| 570 badges->bottom_right = rb.GetImageSkiaNamed( | 571 badges->bottom_right = rb.GetImageSkiaNamed( |
| 571 IDR_AURA_UBER_TRAY_NETWORK_SECURE_DARK); | 572 IDR_AURA_UBER_TRAY_NETWORK_SECURE_DARK); |
| 572 } | 573 } |
| 573 } else if (type == flimflam::kTypeWimax) { | 574 } else if (type == flimflam::kTypeWimax) { |
| 574 technology_badge_ = rb.GetImageSkiaNamed( | 575 technology_badge_ = rb.GetImageSkiaNamed( |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ETHERNET); | 685 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ETHERNET); |
| 685 } else { | 686 } else { |
| 686 return UTF8ToUTF16(network->name()); | 687 return UTF8ToUTF16(network->name()); |
| 687 } | 688 } |
| 688 } | 689 } |
| 689 | 690 |
| 690 int GetCellularUninitializedMsg() { | 691 int GetCellularUninitializedMsg() { |
| 691 static base::Time s_uninitialized_state_time; | 692 static base::Time s_uninitialized_state_time; |
| 692 static int s_uninitialized_msg(0); | 693 static int s_uninitialized_msg(0); |
| 693 | 694 |
| 694 NetworkStateHandler* handler = NetworkStateHandler::Get(); | 695 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
| 695 if (handler->GetTechnologyState(NetworkStateHandler::kMatchTypeMobile) | 696 if (handler->GetTechnologyState(NetworkStateHandler::kMatchTypeMobile) |
| 696 == NetworkStateHandler::TECHNOLOGY_UNINITIALIZED) { | 697 == NetworkStateHandler::TECHNOLOGY_UNINITIALIZED) { |
| 697 s_uninitialized_msg = IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR; | 698 s_uninitialized_msg = IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR; |
| 698 s_uninitialized_state_time = base::Time::Now(); | 699 s_uninitialized_state_time = base::Time::Now(); |
| 699 return s_uninitialized_msg; | 700 return s_uninitialized_msg; |
| 700 } else if (handler->GetScanningByType( | 701 } else if (handler->GetScanningByType( |
| 701 NetworkStateHandler::kMatchTypeMobile)) { | 702 NetworkStateHandler::kMatchTypeMobile)) { |
| 702 s_uninitialized_msg = IDS_ASH_STATUS_TRAY_CELLULAR_SCANNING; | 703 s_uninitialized_msg = IDS_ASH_STATUS_TRAY_CELLULAR_SCANNING; |
| 703 s_uninitialized_state_time = base::Time::Now(); | 704 s_uninitialized_state_time = base::Time::Now(); |
| 704 return s_uninitialized_msg; | 705 return s_uninitialized_msg; |
| 705 } | 706 } |
| 706 // There can be a delay between leaving the Initializing state and when | 707 // There can be a delay between leaving the Initializing state and when |
| 707 // a Cellular device shows up, so keep showing the initializing | 708 // a Cellular device shows up, so keep showing the initializing |
| 708 // animation for a bit to avoid flashing the disconnect icon. | 709 // animation for a bit to avoid flashing the disconnect icon. |
| 709 const int kInitializingDelaySeconds = 1; | 710 const int kInitializingDelaySeconds = 1; |
| 710 base::TimeDelta dtime = base::Time::Now() - s_uninitialized_state_time; | 711 base::TimeDelta dtime = base::Time::Now() - s_uninitialized_state_time; |
| 711 if (dtime.InSeconds() < kInitializingDelaySeconds) | 712 if (dtime.InSeconds() < kInitializingDelaySeconds) |
| 712 return s_uninitialized_msg; | 713 return s_uninitialized_msg; |
| 713 return 0; | 714 return 0; |
| 714 } | 715 } |
| 715 | 716 |
| 716 } // namespace network_icon | 717 } // namespace network_icon |
| 717 } // namespace ash | 718 } // namespace ash |
| OLD | NEW |