diff options
-rw-r--r-- | ash/system/chromeos/network/network_detailed_view.h | 13 | ||||
-rw-r--r-- | ash/system/chromeos/network/network_state_list_detailed_view.cc | 138 | ||||
-rw-r--r-- | ash/system/chromeos/network/network_state_list_detailed_view.h | 36 | ||||
-rw-r--r-- | ash/system/chromeos/network/tray_network.cc | 120 | ||||
-rw-r--r-- | ash/system/chromeos/network/tray_network.h | 28 | ||||
-rw-r--r-- | ash/system/chromeos/network/tray_network_state_observer.cc | 56 | ||||
-rw-r--r-- | ash/system/chromeos/network/tray_network_state_observer.h | 40 | ||||
-rw-r--r-- | ash/system/chromeos/network/tray_vpn.cc | 28 | ||||
-rw-r--r-- | ash/system/chromeos/network/tray_vpn.h | 23 | ||||
-rw-r--r-- | chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc | 12 | ||||
-rw-r--r-- | chromeos/dbus/fake_shill_manager_client.cc | 16 | ||||
-rw-r--r-- | chromeos/device_event_log.cc | 20 | ||||
-rw-r--r-- | chromeos/device_event_log.h | 34 | ||||
-rw-r--r-- | chromeos/network/network_state_handler.cc | 9 | ||||
-rw-r--r-- | ui/chromeos/DEPS | 4 | ||||
-rw-r--r-- | ui/chromeos/network/network_list.cc | 88 | ||||
-rw-r--r-- | ui/chromeos/network/network_list.h | 5 |
17 files changed, 342 insertions, 328 deletions
diff --git a/ash/system/chromeos/network/network_detailed_view.h b/ash/system/chromeos/network/network_detailed_view.h index 772f239..0d17c7a 100644 --- a/ash/system/chromeos/network/network_detailed_view.h +++ b/ash/system/chromeos/network/network_detailed_view.h @@ -29,17 +29,10 @@ class NetworkDetailedView : public TrayDetailsView { virtual DetailedViewType GetViewType() const = 0; - // Called when network manager state has changed. - // (Generic update for NetworkTray <> AshSystemTrayDelegate interface). - virtual void ManagerChanged() = 0; - - // Called when the contents of the network list have changed. - // (Called only from TrayNetworkStateObserver). - virtual void NetworkListChanged() = 0; - - // Called when a network service property has changed. + // Called when the contents of the network list have changed or when any + // Manager properties (e.g. technology state) have changed. // (Called only from TrayNetworkStateObserver). - virtual void NetworkServiceChanged(const chromeos::NetworkState* network) = 0; + virtual void Update() = 0; protected: virtual ~NetworkDetailedView() {} diff --git a/ash/system/chromeos/network/network_state_list_detailed_view.cc b/ash/system/chromeos/network/network_state_list_detailed_view.cc index 3f334b5..63d801a 100644 --- a/ash/system/chromeos/network/network_state_list_detailed_view.cc +++ b/ash/system/chromeos/network/network_state_list_detailed_view.cc @@ -24,6 +24,7 @@ #include "base/strings/utf_string_conversions.h" #include "base/time/time.h" #include "chromeos/chromeos_switches.h" +#include "chromeos/device_event_log.h" #include "chromeos/network/device_state.h" #include "chromeos/network/network_configuration_handler.h" #include "chromeos/network/network_state.h" @@ -82,7 +83,6 @@ views::View* CreateInfoBubbleLine(const base::string16& text_label, } // namespace - //------------------------------------------------------------------------------ // A bubble which displays network info. @@ -102,9 +102,7 @@ class NetworkStateListDetailedView::InfoBubble AddChildView(content); } - virtual ~InfoBubble() { - detailed_view_->OnInfoBubbleDestroyed(); - } + ~InfoBubble() override { detailed_view_->OnInfoBubbleDestroyed(); } private: // Not owned. @@ -141,26 +139,13 @@ NetworkStateListDetailedView::~NetworkStateListDetailedView() { info_bubble_->GetWidget()->CloseNow(); } -void NetworkStateListDetailedView::ManagerChanged() { +void NetworkStateListDetailedView::Update() { UpdateNetworkList(); UpdateHeaderButtons(); UpdateNetworkExtra(); Layout(); } -void NetworkStateListDetailedView::NetworkListChanged() { - UpdateNetworkList(); - UpdateHeaderButtons(); - UpdateNetworkExtra(); - Layout(); -} - -void NetworkStateListDetailedView::NetworkServiceChanged( - const NetworkState* network) { - UpdateNetworkList(); - Layout(); -} - // Overridden from NetworkDetailedView: void NetworkStateListDetailedView::Init() { @@ -181,7 +166,7 @@ void NetworkStateListDetailedView::Init() { CreateHeaderButtons(); network_list_view_.set_content_view(scroll_content()); - NetworkListChanged(); + Update(); CallRequestScan(); } @@ -207,22 +192,19 @@ void NetworkStateListDetailedView::ButtonPressed(views::Button* sender, ash::SystemTrayDelegate* delegate = ash::Shell::GetInstance()->system_tray_delegate(); if (sender == button_wifi_) { - bool enabled = handler->IsTechnologyEnabled( - NetworkTypePattern::WiFi()); - handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(), - !enabled, + bool enabled = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()); + handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(), !enabled, chromeos::network_handler::ErrorCallback()); } else if (sender == turn_on_wifi_) { - handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(), - true, + handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(), true, chromeos::network_handler::ErrorCallback()); } else if (sender == button_mobile_) { ToggleMobile(); } else if (sender == settings_) { Shell::GetInstance()->metrics()->RecordUserMetricsAction( - list_type_ == LIST_TYPE_VPN ? - ash::UMA_STATUS_AREA_VPN_SETTINGS_CLICKED : - ash::UMA_STATUS_AREA_NETWORK_SETTINGS_CLICKED); + list_type_ == LIST_TYPE_VPN + ? ash::UMA_STATUS_AREA_VPN_SETTINGS_CLICKED + : ash::UMA_STATUS_AREA_NETWORK_SETTINGS_CLICKED); delegate->ShowNetworkSettings(""); } else if (sender == proxy_settings_) { delegate->ChangeProxySettings(); @@ -257,20 +239,21 @@ void NetworkStateListDetailedView::OnViewClicked(views::View* sender) { if (!network_list_view_.IsViewInList(sender, &service_path)) return; - const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> - GetNetworkState(service_path); + const NetworkState* network = + NetworkHandler::Get()->network_state_handler()->GetNetworkState( + service_path); if (!network || network->IsConnectedState() || network->IsConnectingState()) { Shell::GetInstance()->metrics()->RecordUserMetricsAction( - list_type_ == LIST_TYPE_VPN ? - ash::UMA_STATUS_AREA_SHOW_NETWORK_CONNECTION_DETAILS : - ash::UMA_STATUS_AREA_SHOW_VPN_CONNECTION_DETAILS); + list_type_ == LIST_TYPE_VPN + ? ash::UMA_STATUS_AREA_SHOW_NETWORK_CONNECTION_DETAILS + : ash::UMA_STATUS_AREA_SHOW_VPN_CONNECTION_DETAILS); Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( service_path); } else { Shell::GetInstance()->metrics()->RecordUserMetricsAction( - list_type_ == LIST_TYPE_VPN ? - ash::UMA_STATUS_AREA_CONNECT_TO_VPN : - ash::UMA_STATUS_AREA_CONNECT_TO_CONFIGURED_NETWORK); + list_type_ == LIST_TYPE_VPN + ? ash::UMA_STATUS_AREA_CONNECT_TO_VPN + : ash::UMA_STATUS_AREA_CONNECT_TO_CONFIGURED_NETWORK); ui::NetworkConnect::Get()->ConnectToNetwork(service_path); } } @@ -284,25 +267,21 @@ void NetworkStateListDetailedView::CreateHeaderEntry() { void NetworkStateListDetailedView::CreateHeaderButtons() { if (list_type_ != LIST_TYPE_VPN) { button_wifi_ = new TrayPopupHeaderButton( - this, - IDR_AURA_UBER_TRAY_WIFI_ENABLED, - IDR_AURA_UBER_TRAY_WIFI_DISABLED, + this, IDR_AURA_UBER_TRAY_WIFI_ENABLED, IDR_AURA_UBER_TRAY_WIFI_DISABLED, IDR_AURA_UBER_TRAY_WIFI_ENABLED_HOVER, - IDR_AURA_UBER_TRAY_WIFI_DISABLED_HOVER, - IDS_ASH_STATUS_TRAY_WIFI); + IDR_AURA_UBER_TRAY_WIFI_DISABLED_HOVER, IDS_ASH_STATUS_TRAY_WIFI); button_wifi_->SetTooltipText( l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_WIFI)); button_wifi_->SetToggledTooltipText( l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_WIFI)); footer()->AddButton(button_wifi_); - button_mobile_ = new TrayPopupHeaderButton( - this, - IDR_AURA_UBER_TRAY_CELLULAR_ENABLED, - IDR_AURA_UBER_TRAY_CELLULAR_DISABLED, - IDR_AURA_UBER_TRAY_CELLULAR_ENABLED_HOVER, - IDR_AURA_UBER_TRAY_CELLULAR_DISABLED_HOVER, - IDS_ASH_STATUS_TRAY_CELLULAR); + button_mobile_ = + new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_CELLULAR_ENABLED, + IDR_AURA_UBER_TRAY_CELLULAR_DISABLED, + IDR_AURA_UBER_TRAY_CELLULAR_ENABLED_HOVER, + IDR_AURA_UBER_TRAY_CELLULAR_DISABLED_HOVER, + IDS_ASH_STATUS_TRAY_CELLULAR); button_mobile_->SetTooltipText( l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_MOBILE)); button_mobile_->SetToggledTooltipText( @@ -311,12 +290,9 @@ void NetworkStateListDetailedView::CreateHeaderButtons() { } info_icon_ = new TrayPopupHeaderButton( - this, - IDR_AURA_UBER_TRAY_NETWORK_INFO, - IDR_AURA_UBER_TRAY_NETWORK_INFO, - IDR_AURA_UBER_TRAY_NETWORK_INFO_HOVER, + this, IDR_AURA_UBER_TRAY_NETWORK_INFO, IDR_AURA_UBER_TRAY_NETWORK_INFO, IDR_AURA_UBER_TRAY_NETWORK_INFO_HOVER, - IDS_ASH_STATUS_TRAY_NETWORK_INFO); + IDR_AURA_UBER_TRAY_NETWORK_INFO_HOVER, IDS_ASH_STATUS_TRAY_NETWORK_INFO); info_icon_->SetTooltipText( l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_INFO)); footer()->AddButton(info_icon_); @@ -330,10 +306,8 @@ void NetworkStateListDetailedView::CreateNetworkExtra() { views::View* bottom_row = new views::View(); views::BoxLayout* layout = new views::BoxLayout( - views::BoxLayout::kHorizontal, - kTrayMenuBottomRowPadding, - kTrayMenuBottomRowPadding, - kTrayMenuBottomRowPaddingBetweenItems); + views::BoxLayout::kHorizontal, kTrayMenuBottomRowPadding, + kTrayMenuBottomRowPadding, kTrayMenuBottomRowPaddingBetweenItems); layout->SetDefaultFlex(1); bottom_row->SetLayoutManager(layout); @@ -351,9 +325,8 @@ void NetworkStateListDetailedView::CreateNetworkExtra() { bottom_row->AddChildView(other_mobile_); } else { other_vpn_ = new TrayPopupLabelButton( - this, - ui::ResourceBundle::GetSharedInstance().GetLocalizedString( - IDS_ASH_STATUS_TRAY_OTHER_VPN)); + this, ui::ResourceBundle::GetSharedInstance().GetLocalizedString( + IDS_ASH_STATUS_TRAY_OTHER_VPN)); bottom_row->AddChildView(other_vpn_); } @@ -466,8 +439,8 @@ void NetworkStateListDetailedView::UpdateNetworkExtra() { } if (show_other_mobile) { other_mobile_->SetVisible(true); - other_mobile_->SetEnabled( - state == NetworkStateHandler::TECHNOLOGY_ENABLED); + other_mobile_->SetEnabled(state == + NetworkStateHandler::TECHNOLOGY_ENABLED); } else { other_mobile_->SetVisible(false); } @@ -481,8 +454,8 @@ void NetworkStateListDetailedView::UpdateNetworkExtra() { void NetworkStateListDetailedView::CreateSettingsEntry() { ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - bool show_settings = ash::Shell::GetInstance()-> - system_tray_delegate()->ShouldShowSettings(); + bool show_settings = + ash::Shell::GetInstance()->system_tray_delegate()->ShouldShowSettings(); if (login_ != user::LOGGED_IN_NONE) { // Allow user access settings only if user is logged in // and showing settings is allowed. There're situations (supervised user @@ -492,7 +465,7 @@ void NetworkStateListDetailedView::CreateSettingsEntry() { settings_ = new TrayPopupLabelButton( this, rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_NETWORK_SETTINGS)); } - } else { + } else { // Allow users to change proxy settings only when not logged in. proxy_settings_ = new TrayPopupLabelButton( this, @@ -504,8 +477,7 @@ void NetworkStateListDetailedView::ToggleInfoBubble() { if (ResetInfoBubble()) return; - info_bubble_ = new InfoBubble( - info_icon_, CreateNetworkInfoView(), this); + info_bubble_ = new InfoBubble(info_icon_, CreateNetworkInfoView(), this); views::BubbleDelegateView::CreateBubble(info_bubble_)->Show(); } @@ -547,27 +519,28 @@ views::View* NetworkStateListDetailedView::CreateNetworkInfoView() { } if (!ip_address.empty()) { - container->AddChildView(CreateInfoBubbleLine(bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_IP), ip_address)); + container->AddChildView(CreateInfoBubbleLine( + bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_IP), ip_address)); } if (!ethernet_address.empty()) { - container->AddChildView(CreateInfoBubbleLine(bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_ETHERNET), ethernet_address)); + container->AddChildView(CreateInfoBubbleLine( + bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_ETHERNET), + ethernet_address)); } if (!wifi_address.empty()) { - container->AddChildView(CreateInfoBubbleLine(bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_WIFI), wifi_address)); + container->AddChildView(CreateInfoBubbleLine( + bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_WIFI), wifi_address)); } if (!vpn_address.empty()) { - container->AddChildView(CreateInfoBubbleLine(bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_VPN), vpn_address)); + container->AddChildView(CreateInfoBubbleLine( + bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_VPN), vpn_address)); } // Avoid an empty bubble in the unlikely event that there is no network // information at all. if (!container->has_children()) { - container->AddChildView(CreateInfoBubbleLabel(bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_NO_NETWORKS))); + container->AddChildView(CreateInfoBubbleLabel( + bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_NO_NETWORKS))); } return container; @@ -585,8 +558,7 @@ void NetworkStateListDetailedView::CallRequestScan() { void NetworkStateListDetailedView::ToggleMobile() { NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); - bool enabled = - handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()); + bool enabled = handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()); ui::NetworkConnect::Get()->SetTechnologyEnabled(NetworkTypePattern::Mobile(), !enabled); } @@ -622,11 +594,9 @@ void NetworkStateListDetailedView::UpdateViewForNetwork( views::Label* NetworkStateListDetailedView::CreateInfoLabel() { views::Label* label = new views::Label(); - label->SetBorder( - views::Border::CreateEmptyBorder(ash::kTrayPopupPaddingBetweenItems, - ash::kTrayPopupPaddingHorizontal, - ash::kTrayPopupPaddingBetweenItems, - 0)); + label->SetBorder(views::Border::CreateEmptyBorder( + ash::kTrayPopupPaddingBetweenItems, ash::kTrayPopupPaddingHorizontal, + ash::kTrayPopupPaddingBetweenItems, 0)); label->SetHorizontalAlignment(gfx::ALIGN_LEFT); label->SetEnabledColor(SkColorSetARGB(192, 0, 0, 0)); return label; diff --git a/ash/system/chromeos/network/network_state_list_detailed_view.h b/ash/system/chromeos/network/network_state_list_detailed_view.h index 4400bec..b00f19af 100644 --- a/ash/system/chromeos/network/network_state_list_detailed_view.h +++ b/ash/system/chromeos/network/network_state_list_detailed_view.h @@ -38,31 +38,24 @@ class NetworkStateListDetailedView public ui::NetworkListDelegate, public base::SupportsWeakPtr<NetworkStateListDetailedView> { public: - enum ListType { - LIST_TYPE_NETWORK, - LIST_TYPE_VPN - }; + enum ListType { LIST_TYPE_NETWORK, LIST_TYPE_VPN }; NetworkStateListDetailedView(SystemTrayItem* owner, ListType list_type, user::LoginStatus login); - virtual ~NetworkStateListDetailedView(); + ~NetworkStateListDetailedView() override; // Overridden from NetworkDetailedView: - virtual void Init() override; - virtual DetailedViewType GetViewType() const override; - virtual void ManagerChanged() override; - virtual void NetworkListChanged() override; - virtual void NetworkServiceChanged( - const chromeos::NetworkState* network) override; + void Init() override; + DetailedViewType GetViewType() const override; + void Update() override; protected: // Overridden from ButtonListener. - virtual void ButtonPressed(views::Button* sender, - const ui::Event& event) override; + void ButtonPressed(views::Button* sender, const ui::Event& event) override; // Overridden from ViewClickListener. - virtual void OnViewClicked(views::View* sender) override; + void OnViewClicked(views::View* sender) override; private: class InfoBubble; @@ -100,14 +93,13 @@ class NetworkStateListDetailedView void ToggleMobile(); // ui::NetworkListDelegate: - virtual views::View* CreateViewForNetwork( - const ui::NetworkInfo& info) override; - virtual bool IsViewHovered(views::View* view) override; - virtual chromeos::NetworkTypePattern GetNetworkTypePattern() const override; - virtual void UpdateViewForNetwork(views::View* view, - const ui::NetworkInfo& info) override; - virtual views::Label* CreateInfoLabel() override; - virtual void RelayoutScrollList() override; + views::View* CreateViewForNetwork(const ui::NetworkInfo& info) override; + bool IsViewHovered(views::View* view) override; + chromeos::NetworkTypePattern GetNetworkTypePattern() const override; + void UpdateViewForNetwork(views::View* view, + const ui::NetworkInfo& info) override; + views::Label* CreateInfoLabel() override; + void RelayoutScrollList() override; // Type of list (all networks or vpn) ListType list_type_; diff --git a/ash/system/chromeos/network/tray_network.cc b/ash/system/chromeos/network/tray_network.cc index a5c5570..b00e220 100644 --- a/ash/system/chromeos/network/tray_network.cc +++ b/ash/system/chromeos/network/tray_network.cc @@ -47,8 +47,7 @@ class NetworkTrayView : public TrayItemView, public ui::network_icon::AnimationObserver { public: explicit NetworkTrayView(TrayNetwork* network_tray) - : TrayItemView(network_tray), - network_tray_(network_tray) { + : TrayItemView(network_tray), network_tray_(network_tray) { SetLayoutManager( new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); @@ -58,13 +57,11 @@ class NetworkTrayView : public TrayItemView, UpdateNetworkStateHandlerIcon(); } - virtual ~NetworkTrayView() { + ~NetworkTrayView() override { ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); } - virtual const char* GetClassName() const override { - return "NetworkTrayView"; - } + const char* GetClassName() const override { return "NetworkTrayView"; } void UpdateNetworkStateHandlerIcon() { NetworkStateHandler* handler = @@ -85,31 +82,29 @@ class NetworkTrayView : public TrayItemView, const NetworkState* connected_network = handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); if (connected_network) { - UpdateConnectionStatus( - base::UTF8ToUTF16(connected_network->name()), true); + UpdateConnectionStatus(base::UTF8ToUTF16(connected_network->name()), + true); } else { UpdateConnectionStatus(base::string16(), false); } } void UpdateAlignment(ShelfAlignment alignment) { - SetLayoutManager(new views::BoxLayout( - alignment == SHELF_ALIGNMENT_BOTTOM ? - views::BoxLayout::kHorizontal : views::BoxLayout::kVertical, - 0, 0, 0)); + SetLayoutManager(new views::BoxLayout(alignment == SHELF_ALIGNMENT_BOTTOM + ? views::BoxLayout::kHorizontal + : views::BoxLayout::kVertical, + 0, 0, 0)); Layout(); } // views::View override. - virtual void GetAccessibleState(ui::AXViewState* state) override { + void GetAccessibleState(ui::AXViewState* state) override { state->name = connection_status_string_; state->role = ui::AX_ROLE_BUTTON; } // ui::network_icon::AnimationObserver - virtual void NetworkIconChanged() override { - UpdateNetworkStateHandlerIcon(); - } + void NetworkIconChanged() override { UpdateNetworkStateHandlerIcon(); } private: // Updates connection status and notifies accessibility event when necessary. @@ -122,7 +117,7 @@ class NetworkTrayView : public TrayItemView, } if (new_connection_status_string != connection_status_string_) { connection_status_string_ = new_connection_status_string; - if(!connection_status_string_.empty()) + if (!connection_status_string_.empty()) NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); } } @@ -144,12 +139,11 @@ class NetworkDefaultView : public TrayItemMore, public ui::network_icon::AnimationObserver { public: NetworkDefaultView(TrayNetwork* network_tray, bool show_more) - : TrayItemMore(network_tray, show_more), - network_tray_(network_tray) { + : TrayItemMore(network_tray, show_more), network_tray_(network_tray) { Update(); } - virtual ~NetworkDefaultView() { + ~NetworkDefaultView() override { ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); } @@ -170,9 +164,7 @@ class NetworkDefaultView : public TrayItemMore, } // ui::network_icon::AnimationObserver - virtual void NetworkIconChanged() override { - Update(); - } + void NetworkIconChanged() override { Update(); } private: TrayNetwork* network_tray_; @@ -185,8 +177,7 @@ class NetworkWifiDetailedView : public NetworkDetailedView { explicit NetworkWifiDetailedView(SystemTrayItem* owner) : NetworkDetailedView(owner) { SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, - kTrayPopupPaddingHorizontal, - 10, + kTrayPopupPaddingHorizontal, 10, kTrayPopupPaddingBetweenItems)); image_view_ = new views::ImageView; AddChildView(image_view_); @@ -199,58 +190,44 @@ class NetworkWifiDetailedView : public NetworkDetailedView { Update(); } - virtual ~NetworkWifiDetailedView() { - } + ~NetworkWifiDetailedView() override {} // Overridden from NetworkDetailedView: - virtual void Init() override { - } + void Init() override {} - virtual NetworkDetailedView::DetailedViewType GetViewType() const override { + NetworkDetailedView::DetailedViewType GetViewType() const override { return NetworkDetailedView::WIFI_VIEW; } - virtual void ManagerChanged() override { - Update(); - } - - virtual void NetworkListChanged() override { - Update(); - } - - virtual void NetworkServiceChanged( - const chromeos::NetworkState* network) override { - } - - private: - virtual void Layout() override { + void Layout() override { // Center both views vertically. views::View::Layout(); - image_view_->SetY( - (height() - image_view_->GetPreferredSize().height()) / 2); - label_view_->SetY( - (height() - label_view_->GetPreferredSize().height()) / 2); + image_view_->SetY((height() - image_view_->GetPreferredSize().height()) / + 2); + label_view_->SetY((height() - label_view_->GetPreferredSize().height()) / + 2); } - void Update() { + void Update() override { bool wifi_enabled = NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled( NetworkTypePattern::WiFi()); - const int image_id = wifi_enabled ? - IDR_AURA_UBER_TRAY_WIFI_ENABLED : IDR_AURA_UBER_TRAY_WIFI_DISABLED; + const int image_id = wifi_enabled ? IDR_AURA_UBER_TRAY_WIFI_ENABLED + : IDR_AURA_UBER_TRAY_WIFI_DISABLED; ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); image_view_->SetImage(bundle.GetImageNamed(image_id).ToImageSkia()); - const int string_id = wifi_enabled ? - IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED : - IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; + const int string_id = wifi_enabled + ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED + : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; label_view_->SetText(bundle.GetLocalizedString(string_id)); - label_view_->SizeToFit(kTrayPopupMinWidth - - kTrayPopupPaddingHorizontal * 2 - kTrayPopupPaddingBetweenItems - - kTrayPopupDetailsIconWidth); + label_view_->SizeToFit( + kTrayPopupMinWidth - kTrayPopupPaddingHorizontal * 2 - + kTrayPopupPaddingBetweenItems - kTrayPopupDetailsIconWidth); } + private: views::ImageView* image_view_; views::Label* label_view_; @@ -290,15 +267,15 @@ views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { if (!chromeos::NetworkHandler::IsInitialized()) return NULL; CHECK(tray_ != NULL); - default_ = new tray::NetworkDefaultView( - this, status != user::LOGGED_IN_LOCKED); + default_ = + new tray::NetworkDefaultView(this, status != user::LOGGED_IN_LOCKED); return default_; } views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { CHECK(detailed_ == NULL); Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_DETAILED_NETWORK_VIEW); + ash::UMA_STATUS_AREA_DETAILED_NETWORK_VIEW); if (!chromeos::NetworkHandler::IsInitialized()) return NULL; if (request_wifi_view_) { @@ -344,35 +321,24 @@ void TrayNetwork::RequestToggleWifi() { NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); bool enabled = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()); Shell::GetInstance()->metrics()->RecordUserMetricsAction( - enabled ? - ash::UMA_STATUS_AREA_DISABLE_WIFI : - ash::UMA_STATUS_AREA_ENABLE_WIFI); - handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(), - !enabled, + enabled ? ash::UMA_STATUS_AREA_DISABLE_WIFI + : ash::UMA_STATUS_AREA_ENABLE_WIFI); + handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(), !enabled, chromeos::network_handler::ErrorCallback()); } void TrayNetwork::OnCaptivePortalDetected( const std::string& /* service_path */) { - NetworkStateChanged(false); + NetworkStateChanged(); } -void TrayNetwork::NetworkStateChanged(bool list_changed) { +void TrayNetwork::NetworkStateChanged() { if (tray_) tray_->UpdateNetworkStateHandlerIcon(); if (default_) default_->Update(); - if (detailed_) { - if (list_changed) - detailed_->NetworkListChanged(); - else - detailed_->ManagerChanged(); - } -} - -void TrayNetwork::NetworkServiceChanged(const chromeos::NetworkState* network) { if (detailed_) - detailed_->NetworkServiceChanged(network); + detailed_->Update(); } } // namespace ash diff --git a/ash/system/chromeos/network/tray_network.h b/ash/system/chromeos/network/tray_network.h index 407b64e..72c0a09 100644 --- a/ash/system/chromeos/network/tray_network.h +++ b/ash/system/chromeos/network/tray_network.h @@ -31,32 +31,28 @@ class TrayNetwork : public SystemTrayItem, public TrayNetworkStateObserver::Delegate { public: explicit TrayNetwork(SystemTray* system_tray); - virtual ~TrayNetwork(); + ~TrayNetwork() override; tray::NetworkDetailedView* detailed() { return detailed_; } // SystemTrayItem - virtual views::View* CreateTrayView(user::LoginStatus status) override; - virtual views::View* CreateDefaultView(user::LoginStatus status) override; - virtual views::View* CreateDetailedView(user::LoginStatus status) override; - virtual void DestroyTrayView() override; - virtual void DestroyDefaultView() override; - virtual void DestroyDetailedView() override; - virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) override; - virtual void UpdateAfterShelfAlignmentChange( - ShelfAlignment alignment) override; + views::View* CreateTrayView(user::LoginStatus status) override; + views::View* CreateDefaultView(user::LoginStatus status) override; + views::View* CreateDetailedView(user::LoginStatus status) override; + void DestroyTrayView() override; + void DestroyDefaultView() override; + void DestroyDetailedView() override; + void UpdateAfterLoginStatusChange(user::LoginStatus status) override; + void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) override; // NetworkObserver - virtual void RequestToggleWifi() override; + void RequestToggleWifi() override; // NetworkPortalDetectorObserver - virtual void OnCaptivePortalDetected( - const std::string& service_path) override; + void OnCaptivePortalDetected(const std::string& service_path) override; // TrayNetworkStateObserver::Delegate - virtual void NetworkStateChanged(bool list_changed) override; - virtual void NetworkServiceChanged( - const chromeos::NetworkState* network) override; + void NetworkStateChanged() override; private: tray::NetworkTrayView* tray_; diff --git a/ash/system/chromeos/network/tray_network_state_observer.cc b/ash/system/chromeos/network/tray_network_state_observer.cc index 4239be2..c23279e 100644 --- a/ash/system/chromeos/network/tray_network_state_observer.cc +++ b/ash/system/chromeos/network/tray_network_state_observer.cc @@ -7,45 +7,60 @@ #include <set> #include <string> +#include "ash/system/tray/system_tray.h" #include "base/location.h" +#include "chromeos/device_event_log.h" #include "chromeos/network/network_state.h" #include "chromeos/network/network_state_handler.h" #include "third_party/cros_system_api/dbus/service_constants.h" #include "ui/chromeos/network/network_icon.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" using chromeos::NetworkHandler; +namespace { + +const int kUpdateFrequencyMs = 1000; + +} // namespace + namespace ash { TrayNetworkStateObserver::TrayNetworkStateObserver(Delegate* delegate) - : delegate_(delegate) { + : delegate_(delegate), + purge_icons_(false), + update_frequency_(kUpdateFrequencyMs) { + if (ui::ScopedAnimationDurationScaleMode::duration_scale_mode() != + ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION) { + update_frequency_ = 0; // Send updates immediately for tests. + } if (NetworkHandler::IsInitialized()) { - NetworkHandler::Get()->network_state_handler()->AddObserver( - this, FROM_HERE); + NetworkHandler::Get()->network_state_handler()->AddObserver(this, + FROM_HERE); } } TrayNetworkStateObserver::~TrayNetworkStateObserver() { if (NetworkHandler::IsInitialized()) { - NetworkHandler::Get()->network_state_handler()->RemoveObserver( - this, FROM_HERE); + NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, + FROM_HERE); } } void TrayNetworkStateObserver::NetworkListChanged() { - delegate_->NetworkStateChanged(true); - ui::network_icon::PurgeNetworkIconCache(); + purge_icons_ = true; + SignalUpdate(); } void TrayNetworkStateObserver::DeviceListChanged() { - delegate_->NetworkStateChanged(false); + SignalUpdate(); } // Any change to the Default (primary connected) network, including Strength // changes, should trigger a NetworkStateChanged update. void TrayNetworkStateObserver::DefaultNetworkChanged( const chromeos::NetworkState* network) { - delegate_->NetworkStateChanged(true); + SignalUpdate(); } // Any change to the Connection State should trigger a NetworkStateChanged @@ -53,7 +68,7 @@ void TrayNetworkStateObserver::DefaultNetworkChanged( // connected. void TrayNetworkStateObserver::NetworkConnectionStateChanged( const chromeos::NetworkState* network) { - delegate_->NetworkStateChanged(true); + SignalUpdate(); } // This tracks Strength and other property changes for all networks. It will @@ -61,13 +76,22 @@ void TrayNetworkStateObserver::NetworkConnectionStateChanged( // changes. void TrayNetworkStateObserver::NetworkPropertiesUpdated( const chromeos::NetworkState* network) { - if (network == - NetworkHandler::Get()->network_state_handler()->DefaultNetwork()) { - // Trigger NetworkStateChanged in case the Strength property of the - // Default network changed. - delegate_->NetworkStateChanged(true); + SignalUpdate(); +} + +void TrayNetworkStateObserver::SignalUpdate() { + if (timer_.IsRunning()) + return; + timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(update_frequency_), + this, &TrayNetworkStateObserver::SendNetworkStateChanged); +} + +void TrayNetworkStateObserver::SendNetworkStateChanged() { + delegate_->NetworkStateChanged(); + if (purge_icons_) { + ui::network_icon::PurgeNetworkIconCache(); + purge_icons_ = false; } - delegate_->NetworkServiceChanged(network); } } // namespace ash diff --git a/ash/system/chromeos/network/tray_network_state_observer.h b/ash/system/chromeos/network/tray_network_state_observer.h index f062a6b..af9bed6 100644 --- a/ash/system/chromeos/network/tray_network_state_observer.h +++ b/ash/system/chromeos/network/tray_network_state_observer.h @@ -8,6 +8,7 @@ #include <string> #include "base/compiler_specific.h" +#include "base/timer/timer.h" #include "chromeos/network/network_state_handler_observer.h" namespace ash { @@ -16,13 +17,9 @@ class TrayNetworkStateObserver : public chromeos::NetworkStateHandlerObserver { public: class Delegate { public: - // Called when the network state may have changed. If |list_changed| is - // true then the list of networks may have changed. - virtual void NetworkStateChanged(bool list_changed) = 0; - - // Called when the properties for |network| may have been updated. - virtual void NetworkServiceChanged( - const chromeos::NetworkState* network) = 0; + // Called when any interesting network changes occur. The frequency of this + // event is limited to kUpdateFrequencyMs. + virtual void NetworkStateChanged() = 0; protected: virtual ~Delegate() {} @@ -30,21 +27,34 @@ class TrayNetworkStateObserver : public chromeos::NetworkStateHandlerObserver { explicit TrayNetworkStateObserver(Delegate* delegate); - virtual ~TrayNetworkStateObserver(); + ~TrayNetworkStateObserver() override; // NetworkStateHandlerObserver overrides. - virtual void NetworkListChanged() override; - virtual void DeviceListChanged() override; - virtual void DefaultNetworkChanged( - const chromeos::NetworkState* network) override; - virtual void NetworkConnectionStateChanged( - const chromeos::NetworkState* network) override; - virtual void NetworkPropertiesUpdated( + void NetworkListChanged() override; + void DeviceListChanged() override; + void DefaultNetworkChanged(const chromeos::NetworkState* network) override; + void NetworkConnectionStateChanged( const chromeos::NetworkState* network) override; + void NetworkPropertiesUpdated(const chromeos::NetworkState* network) override; private: + void SignalUpdate(); + void SendNetworkStateChanged(); + + // Unowned Delegate pointer (must outlive this instance). Delegate* delegate_; + // Set to true when we should purge stale icons in the cache. + bool purge_icons_; + + // Frequency at which to push NetworkStateChanged updates. This avoids + // unnecessarily frequent UI updates (which can be expensive). We set this + // to 0 for tests to eliminate timing variance. + int update_frequency_; + + // Timer used to limit the frequency of NetworkStateChanged updates. + base::OneShotTimer<TrayNetworkStateObserver> timer_; + DISALLOW_COPY_AND_ASSIGN(TrayNetworkStateObserver); }; diff --git a/ash/system/chromeos/network/tray_vpn.cc b/ash/system/chromeos/network/tray_vpn.cc index 545a5ba..0d4cbea 100644 --- a/ash/system/chromeos/network/tray_vpn.cc +++ b/ash/system/chromeos/network/tray_vpn.cc @@ -13,6 +13,7 @@ #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_item_more.h" #include "ash/system/tray/tray_popup_label_button.h" +#include "chromeos/device_event_log.h" #include "chromeos/network/network_state.h" #include "chromeos/network/network_state_handler.h" #include "grit/ash_strings.h" @@ -38,7 +39,7 @@ class VpnDefaultView : public TrayItemMore, Update(); } - virtual ~VpnDefaultView() { + ~VpnDefaultView() override { ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); } @@ -67,9 +68,7 @@ class VpnDefaultView : public TrayItemMore, } // ui::network_icon::AnimationObserver - virtual void NetworkIconChanged() override { - Update(); - } + void NetworkIconChanged() override { Update(); } private: void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, @@ -83,8 +82,8 @@ class VpnDefaultView : public TrayItemMore, *image = ui::network_icon::GetImageForDisconnectedNetwork( ui::network_icon::ICON_TYPE_DEFAULT_VIEW, shill::kTypeVPN); if (label) { - *label = l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED); + *label = + l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED); } *animating = false; return; @@ -104,9 +103,7 @@ class VpnDefaultView : public TrayItemMore, } // namespace tray TrayVPN::TrayVPN(SystemTray* system_tray) - : SystemTrayItem(system_tray), - default_(NULL), - detailed_(NULL) { + : SystemTrayItem(system_tray), default_(NULL), detailed_(NULL) { network_state_observer_.reset(new TrayNetworkStateObserver(this)); } @@ -166,20 +163,11 @@ void TrayVPN::UpdateAfterLoginStatusChange(user::LoginStatus status) { void TrayVPN::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { } -void TrayVPN::NetworkStateChanged(bool list_changed) { +void TrayVPN::NetworkStateChanged() { if (default_) default_->Update(); - if (detailed_) { - if (list_changed) - detailed_->NetworkListChanged(); - else - detailed_->ManagerChanged(); - } -} - -void TrayVPN::NetworkServiceChanged(const chromeos::NetworkState* network) { if (detailed_) - detailed_->NetworkServiceChanged(network); + detailed_->Update(); } } // namespace ash diff --git a/ash/system/chromeos/network/tray_vpn.h b/ash/system/chromeos/network/tray_vpn.h index 74d7aaa..9b56c82 100644 --- a/ash/system/chromeos/network/tray_vpn.h +++ b/ash/system/chromeos/network/tray_vpn.h @@ -22,23 +22,20 @@ class TrayVPN : public SystemTrayItem, public TrayNetworkStateObserver::Delegate { public: explicit TrayVPN(SystemTray* system_tray); - virtual ~TrayVPN(); + ~TrayVPN() override; // SystemTrayItem - virtual views::View* CreateTrayView(user::LoginStatus status) override; - virtual views::View* CreateDefaultView(user::LoginStatus status) override; - virtual views::View* CreateDetailedView(user::LoginStatus status) override; - virtual void DestroyTrayView() override; - virtual void DestroyDefaultView() override; - virtual void DestroyDetailedView() override; - virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) override; - virtual void UpdateAfterShelfAlignmentChange( - ShelfAlignment alignment) override; + views::View* CreateTrayView(user::LoginStatus status) override; + views::View* CreateDefaultView(user::LoginStatus status) override; + views::View* CreateDetailedView(user::LoginStatus status) override; + void DestroyTrayView() override; + void DestroyDefaultView() override; + void DestroyDetailedView() override; + void UpdateAfterLoginStatusChange(user::LoginStatus status) override; + void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) override; // TrayNetworkStateObserver::Delegate - virtual void NetworkStateChanged(bool list_changed) override; - virtual void NetworkServiceChanged( - const chromeos::NetworkState* network) override; + void NetworkStateChanged() override; private: tray::VpnDefaultView* default_; diff --git a/chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc b/chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc index bc9ec36..edeaa8c 100644 --- a/chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc +++ b/chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc @@ -40,6 +40,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "ui/app_list/app_list_switches.h" #include "ui/base/test/ui_controls.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/views/widget/widget.h" using extensions::api::braille_display_private::StubBrailleController; @@ -52,14 +53,15 @@ namespace chromeos { class LoggedInSpokenFeedbackTest : public InProcessBrowserTest { protected: - LoggedInSpokenFeedbackTest() {} - virtual ~LoggedInSpokenFeedbackTest() {} + LoggedInSpokenFeedbackTest() + : animation_mode_(ui::ScopedAnimationDurationScaleMode::ZERO_DURATION) {} + ~LoggedInSpokenFeedbackTest() override {} - virtual void SetUpInProcessBrowserTestFixture() override { + void SetUpInProcessBrowserTestFixture() override { AccessibilityManager::SetBrailleControllerForTest(&braille_controller_); } - virtual void TearDownOnMainThread() override { + void TearDownOnMainThread() override { AccessibilityManager::SetBrailleControllerForTest(NULL); } @@ -174,6 +176,8 @@ class LoggedInSpokenFeedbackTest : public InProcessBrowserTest { private: StubBrailleController braille_controller_; + ui::ScopedAnimationDurationScaleMode animation_mode_; + DISALLOW_COPY_AND_ASSIGN(LoggedInSpokenFeedbackTest); }; diff --git a/chromeos/dbus/fake_shill_manager_client.cc b/chromeos/dbus/fake_shill_manager_client.cc index 96a308d..4c1aa9a 100644 --- a/chromeos/dbus/fake_shill_manager_client.cc +++ b/chromeos/dbus/fake_shill_manager_client.cc @@ -136,7 +136,7 @@ void FakeShillManagerClient::RemovePropertyChangedObserver( void FakeShillManagerClient::GetProperties( const DictionaryValueCallback& callback) { - DVLOG(1) << "Manager.GetProperties"; + VLOG(1) << "Manager.GetProperties"; base::MessageLoop::current()->PostTask( FROM_HERE, base::Bind( &FakeShillManagerClient::PassStubProperties, @@ -157,7 +157,7 @@ void FakeShillManagerClient::SetProperty(const std::string& name, const base::Value& value, const base::Closure& callback, const ErrorCallback& error_callback) { - DVLOG(2) << "SetProperty: " << name; + VLOG(2) << "SetProperty: " << name; stub_properties_.SetWithoutPathExpansion(name, value.DeepCopy()); CallNotifyObserversPropertyChanged(name); base::MessageLoop::current()->PostTask(FROM_HERE, callback); @@ -460,7 +460,7 @@ void FakeShillManagerClient::SetManagerProperty(const std::string& key, void FakeShillManagerClient::AddManagerService( const std::string& service_path, bool notify_observers) { - DVLOG(2) << "AddManagerService: " << service_path; + VLOG(2) << "AddManagerService: " << service_path; GetListProperty(shill::kServiceCompleteListProperty) ->AppendIfNotPresent(new base::StringValue(service_path)); SortManagerServices(false); @@ -470,7 +470,7 @@ void FakeShillManagerClient::AddManagerService( void FakeShillManagerClient::RemoveManagerService( const std::string& service_path) { - DVLOG(2) << "RemoveManagerService: " << service_path; + VLOG(2) << "RemoveManagerService: " << service_path; base::StringValue service_path_value(service_path); GetListProperty(shill::kServiceCompleteListProperty)->Remove( service_path_value, NULL); @@ -478,7 +478,7 @@ void FakeShillManagerClient::RemoveManagerService( } void FakeShillManagerClient::ClearManagerServices() { - DVLOG(1) << "ClearManagerServices"; + VLOG(1) << "ClearManagerServices"; GetListProperty(shill::kServiceCompleteListProperty)->Clear(); CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); } @@ -495,7 +495,7 @@ void FakeShillManagerClient::ServiceStateChanged( } void FakeShillManagerClient::SortManagerServices(bool notify) { - DVLOG(1) << "SortManagerServices"; + VLOG(1) << "SortManagerServices"; static const char* ordered_types[] = {shill::kTypeEthernet, shill::kTypeEthernetEap, shill::kTypeWifi, @@ -867,7 +867,7 @@ void FakeShillManagerClient::CallNotifyObserversPropertyChanged( void FakeShillManagerClient::NotifyObserversPropertyChanged( const std::string& property) { - DVLOG(1) << "NotifyObserversPropertyChanged: " << property; + VLOG(1) << "NotifyObserversPropertyChanged: " << property; base::Value* value = NULL; if (!stub_properties_.GetWithoutPathExpansion(property, &value)) { LOG(ERROR) << "Notify for unknown property: " << property; @@ -964,7 +964,7 @@ void FakeShillManagerClient::ScanCompleted(const std::string& device_path, shill::kScanningProperty, base::FundamentalValue(false)); } - DVLOG(2) << "ScanCompleted"; + VLOG(2) << "ScanCompleted"; CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); base::MessageLoop::current()->PostTask(FROM_HERE, callback); } diff --git a/chromeos/device_event_log.cc b/chromeos/device_event_log.cc index 8251e7d..aaded58 100644 --- a/chromeos/device_event_log.cc +++ b/chromeos/device_event_log.cc @@ -17,6 +17,9 @@ namespace { const size_t kDefaultMaxEntries = 4000; +const int kSlowMethodThresholdMs = 10; +const int kVerySlowMethodThresholdMs = 50; + DeviceEventLogImpl* g_device_event_log = NULL; } // namespace @@ -83,6 +86,23 @@ DeviceEventLogInstance::~DeviceEventLogInstance() { device_event_log::AddEntry(file_, line_, type_, level_, stream_.str()); } +ScopedDeviceLogIfSlow::ScopedDeviceLogIfSlow(LogType type, + const char* file, + const std::string& name) + : file_(file), type_(type), name_(name) { +} + +ScopedDeviceLogIfSlow::~ScopedDeviceLogIfSlow() { + if (timer_.Elapsed().InMilliseconds() >= kSlowMethodThresholdMs) { + LogLevel level(LOG_LEVEL_DEBUG); + if (timer_.Elapsed().InMilliseconds() >= kVerySlowMethodThresholdMs) + level = LOG_LEVEL_ERROR; + DEVICE_LOG(type_, level) << "@@@ Slow method: " << file_ << ":" << name_ + << ": " << timer_.Elapsed().InMilliseconds() + << "ms"; + } +} + } // namespace internal } // namespace device_event_log diff --git a/chromeos/device_event_log.h b/chromeos/device_event_log.h index 34f02e3..a71f8d6 100644 --- a/chromeos/device_event_log.h +++ b/chromeos/device_event_log.h @@ -9,6 +9,7 @@ #include <sstream> #include "base/basictypes.h" +#include "base/timer/elapsed_timer.h" #include "chromeos/chromeos_export.h" namespace chromeos { @@ -33,12 +34,23 @@ namespace chromeos { DEVICE_LOG(::chromeos::device_event_log::LOG_TYPE_LOGIN, \ ::chromeos::device_event_log::LOG_LEVEL_##level) -// Generally prefer the above macros unless |level| is not constant. +// Generally prefer the above macros unless |type| or |level| is not constant. #define DEVICE_LOG(type, level) \ ::chromeos::device_event_log::internal::DeviceEventLogInstance( \ __FILE__, __LINE__, type, level).stream() +// Declare {Type_LOG_IF_SLOW() at the top of a method to log slow methods +// where "slow" is defined by kSlowMethodThresholdMs in the .cc file. +#define SCOPED_NET_LOG_IF_SLOW() \ + SCOPED_DEVICE_LOG_IF_SLOW(::chromeos::device_event_log::LOG_TYPE_NETWORK) + +// Generally prefer the above macros unless |type| is not constant. + +#define SCOPED_DEVICE_LOG_IF_SLOW(type) \ + ::chromeos::device_event_log::internal::ScopedDeviceLogIfSlow \ + scoped_device_log_if_slow(type, __FILE__, __func__) + namespace device_event_log { // Used to specify the type of event. NOTE: Be sure to update LogTypeFromString @@ -117,6 +129,9 @@ CHROMEOS_EXPORT extern const LogLevel kDefaultLogLevel; namespace internal { +// Implementation class for DEVICE_LOG macros. Provides a stream for creating +// a log string and adds the event using device_event_log::AddEntry on +// destruction. class CHROMEOS_EXPORT DeviceEventLogInstance { public: DeviceEventLogInstance(const char* file, @@ -137,6 +152,23 @@ class CHROMEOS_EXPORT DeviceEventLogInstance { DISALLOW_COPY_AND_ASSIGN(DeviceEventLogInstance); }; +// Implementation class for SCOPED_LOG_IF_SLOW macros. Tests the elapsed time on +// destruction and adds a Debug or Error log entry if it exceeds the +// corresponding expected maximum elapsed time. +class CHROMEOS_EXPORT ScopedDeviceLogIfSlow { + public: + ScopedDeviceLogIfSlow(LogType type, + const char* file, + const std::string& name); + ~ScopedDeviceLogIfSlow(); + + private: + const char* file_; + LogType type_; + std::string name_; + base::ElapsedTimer timer_; +}; + } // namespace internal } // namespace device_event_log diff --git a/chromeos/network/network_state_handler.cc b/chromeos/network/network_state_handler.cc index a4562b0..9e2e83c 100644 --- a/chromeos/network/network_state_handler.cc +++ b/chromeos/network/network_state_handler.cc @@ -542,6 +542,7 @@ void NetworkStateHandler::UpdateNetworkServiceProperty( const std::string& service_path, const std::string& key, const base::Value& value) { + SCOPED_NET_LOG_IF_SLOW(); bool changed = false; NetworkState* network = GetModifiableNetworkState(service_path); if (!network) @@ -601,6 +602,7 @@ void NetworkStateHandler::UpdateNetworkServiceProperty( void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, const std::string& key, const base::Value& value) { + SCOPED_NET_LOG_IF_SLOW(); DeviceState* device = GetModifiableDeviceState(device_path); if (!device) return; @@ -678,6 +680,7 @@ void NetworkStateHandler::TechnologyListChanged() { void NetworkStateHandler::ManagedStateListChanged( ManagedState::ManagedType type) { + SCOPED_NET_LOG_IF_SLOW(); if (type == ManagedState::MANAGED_TYPE_NETWORK) { SortNetworkList(); UpdateNetworkStats(); @@ -817,6 +820,7 @@ void NetworkStateHandler::UpdateGuid(NetworkState* network) { } void NetworkStateHandler::NotifyDeviceListChanged() { + SCOPED_NET_LOG_IF_SLOW(); NET_LOG_DEBUG("NOTIFY:DeviceListChanged", base::StringPrintf("Size:%" PRIuS, device_list_.size())); FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, @@ -866,6 +870,7 @@ NetworkStateHandler::ManagedStateList* NetworkStateHandler::GetManagedList( void NetworkStateHandler::OnNetworkConnectionStateChanged( NetworkState* network) { + SCOPED_NET_LOG_IF_SLOW(); DCHECK(network); std::string event = "NetworkConnectionStateChanged"; if (network->path() == default_network_path_) { @@ -889,6 +894,7 @@ void NetworkStateHandler::OnNetworkConnectionStateChanged( void NetworkStateHandler::NotifyDefaultNetworkChanged( const NetworkState* default_network) { + SCOPED_NET_LOG_IF_SLOW(); NET_LOG_EVENT("NOTIFY:DefaultNetworkChanged", GetLogName(default_network)); FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, DefaultNetworkChanged(default_network)); @@ -896,6 +902,7 @@ void NetworkStateHandler::NotifyDefaultNetworkChanged( void NetworkStateHandler::NotifyNetworkPropertiesUpdated( const NetworkState* network) { + SCOPED_NET_LOG_IF_SLOW(); NET_LOG_DEBUG("NOTIFY:NetworkPropertiesUpdated", GetLogName(network)); FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, NetworkPropertiesUpdated(network)); @@ -903,12 +910,14 @@ void NetworkStateHandler::NotifyNetworkPropertiesUpdated( void NetworkStateHandler::NotifyDevicePropertiesUpdated( const DeviceState* device) { + SCOPED_NET_LOG_IF_SLOW(); NET_LOG_DEBUG("NOTIFY:DevicePropertiesUpdated", GetLogName(device)); FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, DevicePropertiesUpdated(device)); } void NetworkStateHandler::NotifyScanCompleted(const DeviceState* device) { + SCOPED_NET_LOG_IF_SLOW(); NET_LOG_DEBUG("NOTIFY:ScanCompleted", GetLogName(device)); FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, ScanCompleted(device)); diff --git a/ui/chromeos/DEPS b/ui/chromeos/DEPS index 15d5882..e89a792 100644 --- a/ui/chromeos/DEPS +++ b/ui/chromeos/DEPS @@ -1,7 +1,5 @@ include_rules = [ - "+chromeos/dbus", - "+chromeos/login", - "+chromeos/network", + "+chromeos", "+grit/ui_chromeos_resources.h", "+grit/ui_chromeos_strings.h", "+third_party/cros_system_api", diff --git a/ui/chromeos/network/network_list.cc b/ui/chromeos/network/network_list.cc index 687951c..fb807e5 100644 --- a/ui/chromeos/network/network_list.cc +++ b/ui/chromeos/network/network_list.cc @@ -7,6 +7,7 @@ #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" #include "chromeos/dbus/power_manager_client.h" +#include "chromeos/device_event_log.h" #include "chromeos/network/network_state.h" #include "chromeos/network/network_state_handler.h" #include "chromeos/network/network_state_handler_observer.h" @@ -47,6 +48,7 @@ void NetworkListView::UpdateNetworkList() { NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); handler->GetVisibleNetworkList(&network_list); UpdateNetworks(network_list); + UpdateNetworkIcons(); UpdateNetworkListInternal(); } @@ -62,6 +64,7 @@ bool NetworkListView::IsViewInList(views::View* view, void NetworkListView::UpdateNetworks( const NetworkStateHandler::NetworkStateList& networks) { + SCOPED_NET_LOG_IF_SLOW(); network_list_.clear(); const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); for (NetworkStateHandler::NetworkStateList::const_iterator iter = @@ -76,7 +79,8 @@ void NetworkListView::UpdateNetworks( } } -void NetworkListView::UpdateNetworkListInternal() { +void NetworkListView::UpdateNetworkIcons() { + SCOPED_NET_LOG_IF_SLOW(); NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); // First, update state for all networks @@ -98,12 +102,14 @@ void NetworkListView::UpdateNetworkListInternal() { if (!animating && network->IsConnectingState()) animating = true; } - if (animating) network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); else network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); +} +void NetworkListView::UpdateNetworkListInternal() { + SCOPED_NET_LOG_IF_SLOW(); // Get the updated list entries network_map_.clear(); std::set<std::string> new_service_paths; @@ -129,21 +135,22 @@ void NetworkListView::UpdateNetworkListInternal() { service_path_map_.erase(*remove_it); } - if (needs_relayout) { - views::View* selected_view = NULL; - for (ServicePathMap::const_iterator iter = service_path_map_.begin(); - iter != service_path_map_.end(); - ++iter) { - if (delegate_->IsViewHovered(iter->second)) { - selected_view = iter->second; - break; - } + if (needs_relayout) + HandleRelayout(); +} + +void NetworkListView::HandleRelayout() { + views::View* selected_view = NULL; + for (auto& iter : service_path_map_) { + if (delegate_->IsViewHovered(iter.second)) { + selected_view = iter.second; + break; } - content_->SizeToPreferredSize(); - delegate_->RelayoutScrollList(); - if (selected_view) - content_->ScrollRectToVisible(selected_view->bounds()); } + content_->SizeToPreferredSize(); + delegate_->RelayoutScrollList(); + if (selected_view) + content_->ScrollRectToVisible(selected_view->bounds()); } bool NetworkListView::UpdateNetworkListEntries( @@ -155,14 +162,8 @@ bool NetworkListView::UpdateNetworkListEntries( int index = 0; // Highlighted networks - for (size_t i = 0; i < network_list_.size(); ++i) { - const NetworkInfo* info = network_list_[i]; - if (info->highlight) { - if (UpdateNetworkChild(index++, info)) - needs_relayout = true; - new_service_paths->insert(info->service_path); - } - } + needs_relayout |= + UpdateNetworkChildren(new_service_paths, &index, true /* highlighted */); const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); if (pattern.MatchesPattern(NetworkTypePattern::Cellular())) { @@ -173,8 +174,9 @@ bool NetworkListView::UpdateNetworkListEntries( !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { message_id = IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS; } - if (UpdateInfoLabel(message_id, index, &no_cellular_networks_view_)) - needs_relayout = true; + needs_relayout |= + UpdateInfoLabel(message_id, index, &no_cellular_networks_view_); + if (message_id) ++index; } @@ -187,8 +189,8 @@ bool NetworkListView::UpdateNetworkListEntries( ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; } - if (UpdateInfoLabel(message_id, index, &no_wifi_networks_view_)) - needs_relayout = true; + needs_relayout |= + UpdateInfoLabel(message_id, index, &no_wifi_networks_view_); if (message_id) ++index; @@ -196,21 +198,14 @@ bool NetworkListView::UpdateNetworkListEntries( message_id = 0; if (handler->GetScanningByType(NetworkTypePattern::WiFi())) message_id = IDS_ASH_STATUS_TRAY_WIFI_SCANNING_MESSAGE; - if (UpdateInfoLabel(message_id, index, &scanning_view_)) - needs_relayout = true; + needs_relayout |= UpdateInfoLabel(message_id, index, &scanning_view_); if (message_id) ++index; } // Un-highlighted networks - for (size_t i = 0; i < network_list_.size(); ++i) { - const NetworkInfo* info = network_list_[i]; - if (!info->highlight) { - if (UpdateNetworkChild(index++, info)) - needs_relayout = true; - new_service_paths->insert(info->service_path); - } - } + needs_relayout |= UpdateNetworkChildren(new_service_paths, &index, + false /* not highlighted */); // No networks or other messages (fallback) if (index == 0) { @@ -219,13 +214,28 @@ bool NetworkListView::UpdateNetworkListEntries( message_id = IDS_ASH_STATUS_TRAY_NETWORK_NO_VPN; else message_id = IDS_ASH_STATUS_TRAY_NO_NETWORKS; - if (UpdateInfoLabel(message_id, index, &scanning_view_)) - needs_relayout = true; + needs_relayout |= UpdateInfoLabel(message_id, index, &scanning_view_); } return needs_relayout; } +bool NetworkListView::UpdateNetworkChildren( + std::set<std::string>* new_service_paths, + int* child_index, + bool highlighted) { + bool needs_relayout = false; + int index = *child_index; + for (auto& info : network_list_) { + if (info->highlight != highlighted) + continue; + needs_relayout |= UpdateNetworkChild(index++, info); + new_service_paths->insert(info->service_path); + } + *child_index = index; + return needs_relayout; +} + bool NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) { bool needs_relayout = false; views::View* container = NULL; diff --git a/ui/chromeos/network/network_list.h b/ui/chromeos/network/network_list.h index ca98f5d..1d4632d 100644 --- a/ui/chromeos/network/network_list.h +++ b/ui/chromeos/network/network_list.h @@ -44,8 +44,13 @@ class UI_CHROMEOS_EXPORT NetworkListView private: void UpdateNetworks( const chromeos::NetworkStateHandler::NetworkStateList& networks); + void UpdateNetworkIcons(); void UpdateNetworkListInternal(); + void HandleRelayout(); bool UpdateNetworkListEntries(std::set<std::string>* new_service_paths); + bool UpdateNetworkChildren(std::set<std::string>* new_service_paths, + int* child_index, + bool highlighted); bool UpdateNetworkChild(int index, const NetworkInfo* info); bool PlaceViewAtIndex(views::View* view, int index); bool UpdateInfoLabel(int message_id, int index, views::Label** label); |