OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/system/chromeos/network/tray_network_state_observer.h" | 5 #include "ash/system/chromeos/network/tray_network_state_observer.h" |
6 | 6 |
7 #include "ash/system/chromeos/network/network_detailed_view.h" | 7 #include <set> |
8 #include "ash/system/chromeos/network/tray_network.h" | 8 #include <string> |
9 #include "ash/system/tray/tray_constants.h" | 9 |
10 #include "chromeos/network/network_state.h" | |
10 #include "chromeos/network/network_state_handler.h" | 11 #include "chromeos/network/network_state_handler.h" |
11 #include "third_party/cros_system_api/dbus/service_constants.h" | 12 #include "third_party/cros_system_api/dbus/service_constants.h" |
12 | 13 |
14 namespace { | |
15 | |
16 std::set<std::string>& GetConnectingNetworks() { | |
17 static std::set<std::string> s_connecting_networks_; | |
18 return s_connecting_networks_; | |
19 } | |
20 | |
21 } | |
22 | |
13 namespace ash { | 23 namespace ash { |
14 namespace internal { | 24 namespace internal { |
15 | 25 |
16 TrayNetworkStateObserver::TrayNetworkStateObserver(TrayNetwork* tray) | 26 TrayNetworkStateObserver::TrayNetworkStateObserver(Delegate* delegate) |
17 : tray_(tray), | 27 : delegate_(delegate) { |
18 wifi_state_(WIFI_UNKNOWN) { | |
19 chromeos::NetworkStateHandler::Get()->AddObserver(this); | 28 chromeos::NetworkStateHandler::Get()->AddObserver(this); |
20 } | 29 } |
21 | 30 |
22 TrayNetworkStateObserver::~TrayNetworkStateObserver() { | 31 TrayNetworkStateObserver::~TrayNetworkStateObserver() { |
23 chromeos::NetworkStateHandler::Get()->RemoveObserver(this); | 32 chromeos::NetworkStateHandler::Get()->RemoveObserver(this); |
24 } | 33 } |
25 | 34 |
26 void TrayNetworkStateObserver::NetworkManagerChanged() { | 35 void TrayNetworkStateObserver::NetworkManagerChanged() { |
27 tray::NetworkDetailedView* detailed = tray_->detailed(); | 36 delegate_->NetworkStateChanged(false); |
28 bool wifi_enabled = chromeos::NetworkStateHandler::Get()-> | |
29 TechnologyEnabled(flimflam::kTypeWifi); | |
30 WifiState wifi_state = wifi_enabled ? WIFI_ENABLED : WIFI_DISABLED; | |
31 if ((wifi_state_ != WIFI_UNKNOWN && wifi_state_ != wifi_state) && | |
32 (!detailed || | |
33 detailed->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW)) { | |
34 tray_->set_request_wifi_view(true); | |
35 tray_->PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); | |
36 } | |
37 wifi_state_ = wifi_state; | |
stevenjb
2013/03/02 03:14:45
This code was actually doing the wrong thing; we a
| |
38 if (detailed) | |
39 detailed->ManagerChanged(); | |
40 } | 37 } |
41 | 38 |
42 void TrayNetworkStateObserver::NetworkListChanged() { | 39 void TrayNetworkStateObserver::NetworkListChanged() { |
43 tray::NetworkDetailedView* detailed = tray_->detailed(); | 40 delegate_->NetworkStateChanged(true); |
44 if (detailed) | |
45 detailed->NetworkListChanged(); | |
46 tray_->TrayNetworkUpdated(); | |
47 } | 41 } |
48 | 42 |
49 void TrayNetworkStateObserver::DeviceListChanged() { | 43 void TrayNetworkStateObserver::DeviceListChanged() { |
50 tray::NetworkDetailedView* detailed = tray_->detailed(); | 44 delegate_->NetworkStateChanged(false); |
51 if (detailed) | |
52 detailed->ManagerChanged(); | |
53 tray_->TrayNetworkUpdated(); | |
54 } | 45 } |
55 | 46 |
56 void TrayNetworkStateObserver::DefaultNetworkChanged( | 47 void TrayNetworkStateObserver::DefaultNetworkChanged( |
57 const chromeos::NetworkState* network) { | 48 const chromeos::NetworkState* network) { |
58 tray_->TrayNetworkUpdated(); | 49 delegate_->NetworkStateChanged(true); |
59 } | 50 } |
60 | 51 |
61 void TrayNetworkStateObserver::NetworkPropertiesUpdated( | 52 void TrayNetworkStateObserver::NetworkPropertiesUpdated( |
62 const chromeos::NetworkState* network) { | 53 const chromeos::NetworkState* network) { |
63 tray_->NetworkServiceChanged(network); | 54 if (!network->IsConnectingState()) |
64 tray::NetworkDetailedView* detailed = tray_->detailed(); | 55 GetConnectingNetworks().erase(network->path()); |
65 if (detailed) | 56 delegate_->NetworkServiceChanged(network); |
66 detailed->NetworkServiceChanged(network); | 57 } |
58 | |
59 // static | |
60 void TrayNetworkStateObserver::AddConnectingNetwork( | |
61 const std::string& service_path) { | |
62 GetConnectingNetworks().insert(service_path); | |
63 } | |
64 | |
65 // static | |
66 bool TrayNetworkStateObserver::HasConnectingNetwork( | |
67 const std::string& service_path) { | |
68 return GetConnectingNetworks().count(service_path) > 0; | |
67 } | 69 } |
68 | 70 |
69 } // namespace ash | 71 } // namespace ash |
70 } // namespace internal | 72 } // namespace internal |
OLD | NEW |