Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: ash/common/system/chromeos/network/tray_network_state_observer.cc

Issue 2732813002: chromeos: Move files in //ash/common to //ash, part 1 (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "ash/common/system/chromeos/network/tray_network_state_observer.h"
6
7 #include <set>
8 #include <string>
9
10 #include "ash/common/system/chromeos/network/network_icon.h"
11 #include "ash/common/system/tray/system_tray.h"
12 #include "base/location.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/compositor/scoped_animation_duration_scale_mode.h"
17
18 using chromeos::NetworkHandler;
19
20 namespace {
21
22 const int kUpdateFrequencyMs = 1000;
23
24 } // namespace
25
26 namespace ash {
27
28 TrayNetworkStateObserver::TrayNetworkStateObserver(Delegate* delegate)
29 : delegate_(delegate),
30 purge_icons_(false),
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.
35 }
36 if (NetworkHandler::IsInitialized()) {
37 NetworkHandler::Get()->network_state_handler()->AddObserver(this,
38 FROM_HERE);
39 }
40 }
41
42 TrayNetworkStateObserver::~TrayNetworkStateObserver() {
43 if (NetworkHandler::IsInitialized()) {
44 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
45 FROM_HERE);
46 }
47 }
48
49 void TrayNetworkStateObserver::NetworkListChanged() {
50 purge_icons_ = true;
51 SignalUpdate();
52 }
53
54 void TrayNetworkStateObserver::DeviceListChanged() {
55 SignalUpdate();
56 }
57
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) {
62 SignalUpdate();
63 }
64
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
67 // connected.
68 void TrayNetworkStateObserver::NetworkConnectionStateChanged(
69 const chromeos::NetworkState* network) {
70 SignalUpdate();
71 }
72
73 // This tracks Strength and other property changes for all networks. It will
74 // be called in addition to NetworkConnectionStateChanged for connection state
75 // changes.
76 void TrayNetworkStateObserver::NetworkPropertiesUpdated(
77 const chromeos::NetworkState* network) {
78 SignalUpdate();
79 }
80
81 void TrayNetworkStateObserver::SignalUpdate() {
82 if (timer_.IsRunning())
83 return;
84 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(update_frequency_),
85 this, &TrayNetworkStateObserver::SendNetworkStateChanged);
86 }
87
88 void TrayNetworkStateObserver::SendNetworkStateChanged() {
89 delegate_->NetworkStateChanged();
90 if (purge_icons_) {
91 network_icon::PurgeNetworkIconCache();
92 purge_icons_ = false;
93 }
94 }
95
96 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/network/tray_network_state_observer.h ('k') | ash/common/system/chromeos/network/tray_vpn.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698