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/device_event_log.h"
13 #include "chromeos/network/network_state.h"
14 #include "chromeos/network/network_state_handler.h"
15 #include "third_party/cros_system_api/dbus/service_constants.h"
16 #include "ui/chromeos/network/network_icon.h"
17 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
19 using chromeos::NetworkHandler
;
23 const int kUpdateFrequencyMs
= 1000;
29 TrayNetworkStateObserver::TrayNetworkStateObserver(Delegate
* delegate
)
30 : delegate_(delegate
),
32 update_frequency_(kUpdateFrequencyMs
) {
33 if (ui::ScopedAnimationDurationScaleMode::duration_scale_mode() !=
34 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION
) {
35 update_frequency_
= 0; // Send updates immediately for tests.
37 if (NetworkHandler::IsInitialized()) {
38 NetworkHandler::Get()->network_state_handler()->AddObserver(this,
43 TrayNetworkStateObserver::~TrayNetworkStateObserver() {
44 if (NetworkHandler::IsInitialized()) {
45 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
50 void TrayNetworkStateObserver::NetworkListChanged() {
55 void TrayNetworkStateObserver::DeviceListChanged() {
59 // Any change to the Default (primary connected) network, including Strength
60 // changes, should trigger a NetworkStateChanged update.
61 void TrayNetworkStateObserver::DefaultNetworkChanged(
62 const chromeos::NetworkState
* network
) {
66 // Any change to the Connection State should trigger a NetworkStateChanged
67 // update. This is important when both a VPN and a physical network are
69 void TrayNetworkStateObserver::NetworkConnectionStateChanged(
70 const chromeos::NetworkState
* network
) {
74 // This tracks Strength and other property changes for all networks. It will
75 // be called in addition to NetworkConnectionStateChanged for connection state
77 void TrayNetworkStateObserver::NetworkPropertiesUpdated(
78 const chromeos::NetworkState
* network
) {
82 void TrayNetworkStateObserver::SignalUpdate() {
83 if (timer_
.IsRunning())
85 timer_
.Start(FROM_HERE
, base::TimeDelta::FromMilliseconds(update_frequency_
),
86 this, &TrayNetworkStateObserver::SendNetworkStateChanged
);
89 void TrayNetworkStateObserver::SendNetworkStateChanged() {
90 delegate_
->NetworkStateChanged();
92 ui::network_icon::PurgeNetworkIconCache();