Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(689)

Side by Side Diff: ash/system/chromeos/network/tray_network_state_observer.cc

Issue 811623002: Add logging for slow device events, limit network UI update rate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch_441650
Patch Set: Feedback Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_state_observer.h" 5 #include "ash/system/chromeos/network/tray_network_state_observer.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "chromeos/device_event_log.h"
11 #include "chromeos/network/network_state.h" 12 #include "chromeos/network/network_state.h"
12 #include "chromeos/network/network_state_handler.h" 13 #include "chromeos/network/network_state_handler.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h" 14 #include "third_party/cros_system_api/dbus/service_constants.h"
14 #include "ui/chromeos/network/network_icon.h" 15 #include "ui/chromeos/network/network_icon.h"
15 16
16 using chromeos::NetworkHandler; 17 using chromeos::NetworkHandler;
17 18
19 namespace {
20
21 const int kUpdateFrequencyMs = 1000;
22
23 } // namespace
24
18 namespace ash { 25 namespace ash {
19 26
20 TrayNetworkStateObserver::TrayNetworkStateObserver(Delegate* delegate) 27 TrayNetworkStateObserver::TrayNetworkStateObserver(Delegate* delegate)
21 : delegate_(delegate) { 28 : delegate_(delegate), purge_icons_(false) {
22 if (NetworkHandler::IsInitialized()) { 29 if (NetworkHandler::IsInitialized()) {
23 NetworkHandler::Get()->network_state_handler()->AddObserver( 30 NetworkHandler::Get()->network_state_handler()->AddObserver(this,
24 this, FROM_HERE); 31 FROM_HERE);
25 } 32 }
26 } 33 }
27 34
28 TrayNetworkStateObserver::~TrayNetworkStateObserver() { 35 TrayNetworkStateObserver::~TrayNetworkStateObserver() {
29 if (NetworkHandler::IsInitialized()) { 36 if (NetworkHandler::IsInitialized()) {
30 NetworkHandler::Get()->network_state_handler()->RemoveObserver( 37 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
31 this, FROM_HERE); 38 FROM_HERE);
32 } 39 }
33 } 40 }
34 41
35 void TrayNetworkStateObserver::NetworkListChanged() { 42 void TrayNetworkStateObserver::NetworkListChanged() {
36 delegate_->NetworkStateChanged(true); 43 purge_icons_ = true;
37 ui::network_icon::PurgeNetworkIconCache(); 44 SignalUpdate();
38 } 45 }
39 46
40 void TrayNetworkStateObserver::DeviceListChanged() { 47 void TrayNetworkStateObserver::DeviceListChanged() {
41 delegate_->NetworkStateChanged(false); 48 SignalUpdate();
42 } 49 }
43 50
44 // Any change to the Default (primary connected) network, including Strength 51 // Any change to the Default (primary connected) network, including Strength
45 // changes, should trigger a NetworkStateChanged update. 52 // changes, should trigger a NetworkStateChanged update.
46 void TrayNetworkStateObserver::DefaultNetworkChanged( 53 void TrayNetworkStateObserver::DefaultNetworkChanged(
47 const chromeos::NetworkState* network) { 54 const chromeos::NetworkState* network) {
48 delegate_->NetworkStateChanged(true); 55 SignalUpdate();
49 } 56 }
50 57
51 // Any change to the Connection State should trigger a NetworkStateChanged 58 // Any change to the Connection State should trigger a NetworkStateChanged
52 // update. This is important when both a VPN and a physical network are 59 // update. This is important when both a VPN and a physical network are
53 // connected. 60 // connected.
54 void TrayNetworkStateObserver::NetworkConnectionStateChanged( 61 void TrayNetworkStateObserver::NetworkConnectionStateChanged(
55 const chromeos::NetworkState* network) { 62 const chromeos::NetworkState* network) {
56 delegate_->NetworkStateChanged(true); 63 SignalUpdate();
57 } 64 }
58 65
59 // This tracks Strength and other property changes for all networks. It will 66 // This tracks Strength and other property changes for all networks. It will
60 // be called in addition to NetworkConnectionStateChanged for connection state 67 // be called in addition to NetworkConnectionStateChanged for connection state
61 // changes. 68 // changes.
62 void TrayNetworkStateObserver::NetworkPropertiesUpdated( 69 void TrayNetworkStateObserver::NetworkPropertiesUpdated(
63 const chromeos::NetworkState* network) { 70 const chromeos::NetworkState* network) {
64 if (network == 71 SignalUpdate();
65 NetworkHandler::Get()->network_state_handler()->DefaultNetwork()) { 72 }
66 // Trigger NetworkStateChanged in case the Strength property of the 73
67 // Default network changed. 74 void TrayNetworkStateObserver::SignalUpdate() {
68 delegate_->NetworkStateChanged(true); 75 if (timer_.IsRunning())
76 return;
77 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kUpdateFrequencyMs),
78 this, &TrayNetworkStateObserver::SendNetworkStateChanged);
79 }
80
81 void TrayNetworkStateObserver::SendNetworkStateChanged() {
82 delegate_->NetworkStateChanged();
83 if (purge_icons_) {
84 ui::network_icon::PurgeNetworkIconCache();
85 purge_icons_ = false;
69 } 86 }
70 delegate_->NetworkServiceChanged(network);
71 } 87 }
72 88
73 } // namespace ash 89 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/network/tray_network_state_observer.h ('k') | ash/system/chromeos/network/tray_vpn.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698