Elim cr-checkbox
[chromium-blink-merge.git] / ash / system / chromeos / network / tray_network_state_observer.h
blobaf9bed6172aa686827ea5032fddaab368c1f0c41
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 #ifndef ASH_SYSTEM_CHROMEOS_NETWORK_TRAY_NETWORK_STATE_OBSERVER_H
6 #define ASH_SYSTEM_CHROMEOS_NETWORK_TRAY_NETWORK_STATE_OBSERVER_H
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "base/timer/timer.h"
12 #include "chromeos/network/network_state_handler_observer.h"
14 namespace ash {
16 class TrayNetworkStateObserver : public chromeos::NetworkStateHandlerObserver {
17 public:
18 class Delegate {
19 public:
20 // Called when any interesting network changes occur. The frequency of this
21 // event is limited to kUpdateFrequencyMs.
22 virtual void NetworkStateChanged() = 0;
24 protected:
25 virtual ~Delegate() {}
28 explicit TrayNetworkStateObserver(Delegate* delegate);
30 ~TrayNetworkStateObserver() override;
32 // NetworkStateHandlerObserver overrides.
33 void NetworkListChanged() override;
34 void DeviceListChanged() override;
35 void DefaultNetworkChanged(const chromeos::NetworkState* network) override;
36 void NetworkConnectionStateChanged(
37 const chromeos::NetworkState* network) override;
38 void NetworkPropertiesUpdated(const chromeos::NetworkState* network) override;
40 private:
41 void SignalUpdate();
42 void SendNetworkStateChanged();
44 // Unowned Delegate pointer (must outlive this instance).
45 Delegate* delegate_;
47 // Set to true when we should purge stale icons in the cache.
48 bool purge_icons_;
50 // Frequency at which to push NetworkStateChanged updates. This avoids
51 // unnecessarily frequent UI updates (which can be expensive). We set this
52 // to 0 for tests to eliminate timing variance.
53 int update_frequency_;
55 // Timer used to limit the frequency of NetworkStateChanged updates.
56 base::OneShotTimer<TrayNetworkStateObserver> timer_;
58 DISALLOW_COPY_AND_ASSIGN(TrayNetworkStateObserver);
61 } // namespace ash
63 #endif // ASH_SYSTEM_CHROMEOS_NETWORK_TRAY_NETWORK_STATE_OBSERVER_H