Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / system / chromeos / network / tray_network_state_observer.cc
blob4239be295bbdc7a8d52beb56e91caa4608058cfe
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 "base/location.h"
11 #include "chromeos/network/network_state.h"
12 #include "chromeos/network/network_state_handler.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h"
14 #include "ui/chromeos/network/network_icon.h"
16 using chromeos::NetworkHandler;
18 namespace ash {
20 TrayNetworkStateObserver::TrayNetworkStateObserver(Delegate* delegate)
21 : delegate_(delegate) {
22 if (NetworkHandler::IsInitialized()) {
23 NetworkHandler::Get()->network_state_handler()->AddObserver(
24 this, FROM_HERE);
28 TrayNetworkStateObserver::~TrayNetworkStateObserver() {
29 if (NetworkHandler::IsInitialized()) {
30 NetworkHandler::Get()->network_state_handler()->RemoveObserver(
31 this, FROM_HERE);
35 void TrayNetworkStateObserver::NetworkListChanged() {
36 delegate_->NetworkStateChanged(true);
37 ui::network_icon::PurgeNetworkIconCache();
40 void TrayNetworkStateObserver::DeviceListChanged() {
41 delegate_->NetworkStateChanged(false);
44 // Any change to the Default (primary connected) network, including Strength
45 // changes, should trigger a NetworkStateChanged update.
46 void TrayNetworkStateObserver::DefaultNetworkChanged(
47 const chromeos::NetworkState* network) {
48 delegate_->NetworkStateChanged(true);
51 // Any change to the Connection State should trigger a NetworkStateChanged
52 // update. This is important when both a VPN and a physical network are
53 // connected.
54 void TrayNetworkStateObserver::NetworkConnectionStateChanged(
55 const chromeos::NetworkState* network) {
56 delegate_->NetworkStateChanged(true);
59 // This tracks Strength and other property changes for all networks. It will
60 // be called in addition to NetworkConnectionStateChanged for connection state
61 // changes.
62 void TrayNetworkStateObserver::NetworkPropertiesUpdated(
63 const chromeos::NetworkState* network) {
64 if (network ==
65 NetworkHandler::Get()->network_state_handler()->DefaultNetwork()) {
66 // Trigger NetworkStateChanged in case the Strength property of the
67 // Default network changed.
68 delegate_->NetworkStateChanged(true);
70 delegate_->NetworkServiceChanged(network);
73 } // namespace ash