| 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/tray_network.h" | 5 #include "ash/system/chromeos/network/tray_network.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/system/chromeos/network/network_icon_animation.h" | 9 #include "ash/system/chromeos/network/network_icon_animation.h" |
| 10 #include "ash/system/chromeos/network/network_list_detailed_view.h" | 10 #include "ash/system/chromeos/network/network_list_detailed_view.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
| 33 #include "ui/views/controls/image_view.h" | 33 #include "ui/views/controls/image_view.h" |
| 34 #include "ui/views/controls/link.h" | 34 #include "ui/views/controls/link.h" |
| 35 #include "ui/views/controls/link_listener.h" | 35 #include "ui/views/controls/link_listener.h" |
| 36 #include "ui/views/layout/box_layout.h" | 36 #include "ui/views/layout/box_layout.h" |
| 37 #include "ui/views/widget/widget.h" | 37 #include "ui/views/widget/widget.h" |
| 38 | 38 |
| 39 using ash::internal::TrayNetwork; | 39 using ash::internal::TrayNetwork; |
| 40 using ash::NetworkObserver; | 40 using ash::NetworkObserver; |
| 41 using chromeos::NetworkHandler; |
| 41 using chromeos::NetworkState; | 42 using chromeos::NetworkState; |
| 42 using chromeos::NetworkStateHandler; | 43 using chromeos::NetworkStateHandler; |
| 43 | 44 |
| 44 namespace { | 45 namespace { |
| 45 | 46 |
| 46 int GetMessageIcon(NetworkObserver::MessageType message_type, | 47 int GetMessageIcon(NetworkObserver::MessageType message_type, |
| 47 NetworkObserver::NetworkType network_type) { | 48 NetworkObserver::NetworkType network_type) { |
| 48 switch(message_type) { | 49 switch(message_type) { |
| 49 case NetworkObserver::ERROR_CONNECT_FAILED: | 50 case NetworkObserver::ERROR_CONNECT_FAILED: |
| 50 if (NetworkObserver::NETWORK_CELLULAR == network_type) | 51 if (NetworkObserver::NETWORK_CELLULAR == network_type) |
| 51 return IDR_AURA_UBER_TRAY_CELLULAR_NETWORK_FAILED; | 52 return IDR_AURA_UBER_TRAY_CELLULAR_NETWORK_FAILED; |
| 52 else | 53 else |
| 53 return IDR_AURA_UBER_TRAY_NETWORK_FAILED; | 54 return IDR_AURA_UBER_TRAY_NETWORK_FAILED; |
| 54 case NetworkObserver::ERROR_OUT_OF_CREDITS: | 55 case NetworkObserver::ERROR_OUT_OF_CREDITS: |
| 55 case NetworkObserver::MESSAGE_DATA_PROMO: | 56 case NetworkObserver::MESSAGE_DATA_PROMO: |
| 56 if (network_type == TrayNetwork::NETWORK_CELLULAR_LTE) | 57 if (network_type == TrayNetwork::NETWORK_CELLULAR_LTE) |
| 57 return IDR_AURA_UBER_TRAY_NOTIFICATION_LTE; | 58 return IDR_AURA_UBER_TRAY_NOTIFICATION_LTE; |
| 58 else | 59 else |
| 59 return IDR_AURA_UBER_TRAY_NOTIFICATION_3G; | 60 return IDR_AURA_UBER_TRAY_NOTIFICATION_3G; |
| 60 } | 61 } |
| 61 NOTREACHED(); | 62 NOTREACHED(); |
| 62 return 0; | 63 return 0; |
| 63 } | 64 } |
| 64 | 65 |
| 65 bool UseNewNetworkHandlers() { | 66 bool UseNewNetworkHandlers() { |
| 66 return !CommandLine::ForCurrentProcess()->HasSwitch( | 67 return !CommandLine::ForCurrentProcess()->HasSwitch( |
| 67 ash::switches::kAshDisableNewNetworkStatusArea) && | 68 ash::switches::kAshDisableNewNetworkStatusArea); |
| 68 NetworkStateHandler::IsInitialized(); | |
| 69 } | 69 } |
| 70 | 70 |
| 71 } // namespace | 71 } // namespace |
| 72 | 72 |
| 73 namespace ash { | 73 namespace ash { |
| 74 namespace internal { | 74 namespace internal { |
| 75 | 75 |
| 76 namespace tray { | 76 namespace tray { |
| 77 | 77 |
| 78 class NetworkMessages { | 78 class NetworkMessages { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 void Update(const NetworkIconInfo& info) { | 138 void Update(const NetworkIconInfo& info) { |
| 139 if (UseNewNetworkHandlers()) | 139 if (UseNewNetworkHandlers()) |
| 140 return; | 140 return; |
| 141 UpdateIcon(info.tray_icon_visible, info.image); | 141 UpdateIcon(info.tray_icon_visible, info.image); |
| 142 UpdateConnectionStatus(info.name, info.connected); | 142 UpdateConnectionStatus(info.name, info.connected); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void UpdateNetworkStateHandlerIcon() { | 145 void UpdateNetworkStateHandlerIcon() { |
| 146 DCHECK(UseNewNetworkHandlers()); | 146 DCHECK(UseNewNetworkHandlers()); |
| 147 NetworkStateHandler* handler = NetworkStateHandler::Get(); | 147 NetworkStateHandler* handler = |
| 148 NetworkHandler::Get()->network_state_handler(); |
| 148 gfx::ImageSkia image; | 149 gfx::ImageSkia image; |
| 149 base::string16 name; | 150 base::string16 name; |
| 150 bool animating = false; | 151 bool animating = false; |
| 151 network_tray_->GetNetworkStateHandlerImageAndLabel( | 152 network_tray_->GetNetworkStateHandlerImageAndLabel( |
| 152 network_icon::ICON_TYPE_TRAY, &image, &name, &animating); | 153 network_icon::ICON_TYPE_TRAY, &image, &name, &animating); |
| 153 bool show_in_tray = !image.isNull(); | 154 bool show_in_tray = !image.isNull(); |
| 154 UpdateIcon(show_in_tray, image); | 155 UpdateIcon(show_in_tray, image); |
| 155 if (animating) | 156 if (animating) |
| 156 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 157 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 157 else | 158 else |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 } // namespace tray | 415 } // namespace tray |
| 415 | 416 |
| 416 TrayNetwork::TrayNetwork(SystemTray* system_tray) | 417 TrayNetwork::TrayNetwork(SystemTray* system_tray) |
| 417 : SystemTrayItem(system_tray), | 418 : SystemTrayItem(system_tray), |
| 418 tray_(NULL), | 419 tray_(NULL), |
| 419 default_(NULL), | 420 default_(NULL), |
| 420 detailed_(NULL), | 421 detailed_(NULL), |
| 421 notification_(NULL), | 422 notification_(NULL), |
| 422 messages_(new tray::NetworkMessages()), | 423 messages_(new tray::NetworkMessages()), |
| 423 request_wifi_view_(false) { | 424 request_wifi_view_(false) { |
| 424 if (UseNewNetworkHandlers()) | 425 if (UseNewNetworkHandlers()) { |
| 425 network_state_observer_.reset(new TrayNetworkStateObserver(this)); | 426 network_state_observer_.reset(new TrayNetworkStateObserver(this)); |
| 426 if (NetworkStateHandler::IsInitialized()) | |
| 427 network_state_notifier_.reset(new NetworkStateNotifier()); | 427 network_state_notifier_.reset(new NetworkStateNotifier()); |
| 428 } |
| 428 Shell::GetInstance()->system_tray_notifier()->AddNetworkObserver(this); | 429 Shell::GetInstance()->system_tray_notifier()->AddNetworkObserver(this); |
| 429 } | 430 } |
| 430 | 431 |
| 431 TrayNetwork::~TrayNetwork() { | 432 TrayNetwork::~TrayNetwork() { |
| 432 network_state_notifier_.reset(); | 433 network_state_notifier_.reset(); |
| 433 Shell::GetInstance()->system_tray_notifier()->RemoveNetworkObserver(this); | 434 Shell::GetInstance()->system_tray_notifier()->RemoveNetworkObserver(this); |
| 434 } | 435 } |
| 435 | 436 |
| 436 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { | 437 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { |
| 437 CHECK(tray_ == NULL); | 438 CHECK(tray_ == NULL); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 void TrayNetwork::NetworkServiceChanged(const chromeos::NetworkState* network) { | 565 void TrayNetwork::NetworkServiceChanged(const chromeos::NetworkState* network) { |
| 565 if (detailed_) | 566 if (detailed_) |
| 566 detailed_->NetworkServiceChanged(network); | 567 detailed_->NetworkServiceChanged(network); |
| 567 } | 568 } |
| 568 | 569 |
| 569 void TrayNetwork::GetNetworkStateHandlerImageAndLabel( | 570 void TrayNetwork::GetNetworkStateHandlerImageAndLabel( |
| 570 network_icon::IconType icon_type, | 571 network_icon::IconType icon_type, |
| 571 gfx::ImageSkia* image, | 572 gfx::ImageSkia* image, |
| 572 base::string16* label, | 573 base::string16* label, |
| 573 bool* animating) { | 574 bool* animating) { |
| 574 NetworkStateHandler* handler = NetworkStateHandler::Get(); | 575 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
| 575 const NetworkState* connected_network = handler->ConnectedNetworkByType( | 576 const NetworkState* connected_network = handler->ConnectedNetworkByType( |
| 576 NetworkStateHandler::kMatchTypeNonVirtual); | 577 NetworkStateHandler::kMatchTypeNonVirtual); |
| 577 const NetworkState* connecting_network = handler->ConnectingNetworkByType( | 578 const NetworkState* connecting_network = handler->ConnectingNetworkByType( |
| 578 NetworkStateHandler::kMatchTypeWireless); | 579 NetworkStateHandler::kMatchTypeWireless); |
| 579 if (!connecting_network && icon_type == network_icon::ICON_TYPE_TRAY) | 580 if (!connecting_network && icon_type == network_icon::ICON_TYPE_TRAY) |
| 580 connecting_network = handler->ConnectingNetworkByType(flimflam::kTypeVPN); | 581 connecting_network = handler->ConnectingNetworkByType(flimflam::kTypeVPN); |
| 581 | 582 |
| 582 const NetworkState* network; | 583 const NetworkState* network; |
| 583 // If we are connecting to a network, and there is either no connected | 584 // If we are connecting to a network, and there is either no connected |
| 584 // network, or the connection was user requested, use the connecting | 585 // network, or the connection was user requested, use the connecting |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 | 639 |
| 639 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { | 640 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { |
| 640 tray::NetworkMessages::MessageMap::const_iterator iter = | 641 tray::NetworkMessages::MessageMap::const_iterator iter = |
| 641 messages()->messages().find(message_type); | 642 messages()->messages().find(message_type); |
| 642 if (iter != messages()->messages().end() && iter->second.delegate) | 643 if (iter != messages()->messages().end() && iter->second.delegate) |
| 643 iter->second.delegate->NotificationLinkClicked(message_type, link_id); | 644 iter->second.delegate->NotificationLinkClicked(message_type, link_id); |
| 644 } | 645 } |
| 645 | 646 |
| 646 } // namespace internal | 647 } // namespace internal |
| 647 } // namespace ash | 648 } // namespace ash |
| OLD | NEW |