Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / ash / system / chromeos / network / tray_network_state_observer.cc
blob8d7f181e60a571e782f9f15c5954467615cf6511
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
3 // found in the LICENSE file.
5 #include "ash/system/chromeos/network/tray_network_state_observer.h"
7 #include <set>
8 #include <string>
10 #include "ash/system/tray/system_tray.h"
11 #include "base/location.h"
12 #include "chromeos/network/network_state.h"
13 #include "chromeos/network/network_state_handler.h"
14 #include "third_party/cros_system_api/dbus/service_constants.h"
15 #include "ui/chromeos/network/network_icon.h"
16 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
18 using chromeos::NetworkHandler;
20 namespace {
22 const int kUpdateFrequencyMs = 1000;
24 } // namespace
26 namespace ash {
28 TrayNetworkStateObserver::TrayNetworkStateObserver(Delegate* delegate)
29 : delegate_(delegate),
30 purge_icons_(false),
31 update_frequency_(kUpdateFrequencyMs) {
32 if (ui::ScopedAnimationDurationScaleMode::duration_scale_mode() !=
33 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION) {
34 update_frequency_ = 0; // Send updates immediately for tests.
36 if (NetworkHandler::IsInitialized()) {
37 NetworkHandler::Get()->network_state_handler()->AddObserver(this,
38 FROM_HERE);
42 TrayNetworkStateObserver::~TrayNetworkStateObserver() {
43 if (NetworkHandler::IsInitialized()) {
44 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
45 FROM_HERE);
49 void TrayNetworkStateObserver::NetworkListChanged() {
50 purge_icons_ = true;
51 SignalUpdate();
54 void TrayNetworkStateObserver::DeviceListChanged() {
55 SignalUpdate();
58 // Any change to the Default (primary connected) network, including Strength
59 // changes, should trigger a NetworkStateChanged update.
60 void TrayNetworkStateObserver::DefaultNetworkChanged(
61 const chromeos::NetworkState* network) {
62 SignalUpdate();
65 // Any change to the Connection State should trigger a NetworkStateChanged
66 // update. This is important when both a VPN and a physical network are
67 // connected.
68 void TrayNetworkStateObserver::NetworkConnectionStateChanged(
69 const chromeos::NetworkState* network) {
70 SignalUpdate();
73 // This tracks Strength and other property changes for all networks. It will
74 // be called in addition to NetworkConnectionStateChanged for connection state
75 // changes.
76 void TrayNetworkStateObserver::NetworkPropertiesUpdated(
77 const chromeos::NetworkState* network) {
78 SignalUpdate();
81 void TrayNetworkStateObserver::SignalUpdate() {
82 if (timer_.IsRunning())
83 return;
84 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(update_frequency_),
85 this, &TrayNetworkStateObserver::SendNetworkStateChanged);
88 void TrayNetworkStateObserver::SendNetworkStateChanged() {
89 delegate_->NetworkStateChanged();
90 if (purge_icons_) {
91 ui::network_icon::PurgeNetworkIconCache();
92 purge_icons_ = false;
96 } // namespace ash