ProfilePolicyConnectorFactory: Refactoring from Profile to BrowserContext.
[chromium-blink-merge.git] / ash / system / chromeos / network / tray_network_state_observer.cc
blobc23279e1188848344176cc334d2da882c54e75bf
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/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;
21 namespace {
23 const int kUpdateFrequencyMs = 1000;
25 } // namespace
27 namespace ash {
29 TrayNetworkStateObserver::TrayNetworkStateObserver(Delegate* delegate)
30 : delegate_(delegate),
31 purge_icons_(false),
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,
39 FROM_HERE);
43 TrayNetworkStateObserver::~TrayNetworkStateObserver() {
44 if (NetworkHandler::IsInitialized()) {
45 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
46 FROM_HERE);
50 void TrayNetworkStateObserver::NetworkListChanged() {
51 purge_icons_ = true;
52 SignalUpdate();
55 void TrayNetworkStateObserver::DeviceListChanged() {
56 SignalUpdate();
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) {
63 SignalUpdate();
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
68 // connected.
69 void TrayNetworkStateObserver::NetworkConnectionStateChanged(
70 const chromeos::NetworkState* network) {
71 SignalUpdate();
74 // This tracks Strength and other property changes for all networks. It will
75 // be called in addition to NetworkConnectionStateChanged for connection state
76 // changes.
77 void TrayNetworkStateObserver::NetworkPropertiesUpdated(
78 const chromeos::NetworkState* network) {
79 SignalUpdate();
82 void TrayNetworkStateObserver::SignalUpdate() {
83 if (timer_.IsRunning())
84 return;
85 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(update_frequency_),
86 this, &TrayNetworkStateObserver::SendNetworkStateChanged);
89 void TrayNetworkStateObserver::SendNetworkStateChanged() {
90 delegate_->NetworkStateChanged();
91 if (purge_icons_) {
92 ui::network_icon::PurgeNetworkIconCache();
93 purge_icons_ = false;
97 } // namespace ash