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"
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
;
22 const int kUpdateFrequencyMs
= 1000;
28 TrayNetworkStateObserver::TrayNetworkStateObserver(Delegate
* delegate
)
29 : delegate_(delegate
),
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,
42 TrayNetworkStateObserver::~TrayNetworkStateObserver() {
43 if (NetworkHandler::IsInitialized()) {
44 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
49 void TrayNetworkStateObserver::NetworkListChanged() {
54 void TrayNetworkStateObserver::DeviceListChanged() {
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
) {
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
68 void TrayNetworkStateObserver::NetworkConnectionStateChanged(
69 const chromeos::NetworkState
* network
) {
73 // This tracks Strength and other property changes for all networks. It will
74 // be called in addition to NetworkConnectionStateChanged for connection state
76 void TrayNetworkStateObserver::NetworkPropertiesUpdated(
77 const chromeos::NetworkState
* network
) {
81 void TrayNetworkStateObserver::SignalUpdate() {
82 if (timer_
.IsRunning())
84 timer_
.Start(FROM_HERE
, base::TimeDelta::FromMilliseconds(update_frequency_
),
85 this, &TrayNetworkStateObserver::SendNetworkStateChanged
);
88 void TrayNetworkStateObserver::SendNetworkStateChanged() {
89 delegate_
->NetworkStateChanged();
91 ui::network_icon::PurgeNetworkIconCache();