NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / network_state_informer.h
blob94764dbf5c25376ffadc6c6b08d80f7b10e299f4
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 CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_STATE_INFORMER_H_
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_STATE_INFORMER_H_
8 #include <map>
9 #include <string>
11 #include "base/cancelable_callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/observer_list.h"
16 #include "chrome/browser/chromeos/login/captive_portal_window_proxy.h"
17 #include "chrome/browser/chromeos/login/screens/error_screen_actor.h"
18 #include "chrome/browser/chromeos/net/network_portal_detector.h"
19 #include "chromeos/network/network_state_handler_observer.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/notification_service.h"
24 namespace chromeos {
26 // Class which observes network state changes and calls registered callbacks.
27 // State is considered changed if connection or the active network has been
28 // changed. Also, it answers to the requests about current network state.
29 class NetworkStateInformer
30 : public chromeos::NetworkStateHandlerObserver,
31 public chromeos::NetworkPortalDetector::Observer,
32 public content::NotificationObserver,
33 public CaptivePortalWindowProxyDelegate,
34 public base::RefCounted<NetworkStateInformer> {
35 public:
36 enum State {
37 OFFLINE = 0,
38 ONLINE,
39 CAPTIVE_PORTAL,
40 CONNECTING,
41 PROXY_AUTH_REQUIRED,
42 UNKNOWN
45 class NetworkStateInformerObserver {
46 public:
47 NetworkStateInformerObserver() {}
48 virtual ~NetworkStateInformerObserver() {}
50 virtual void UpdateState(ErrorScreenActor::ErrorReason reason) = 0;
51 virtual void OnNetworkReady() {}
54 NetworkStateInformer();
56 void Init();
58 // Adds observer to be notified when network state has been changed.
59 void AddObserver(NetworkStateInformerObserver* observer);
61 // Removes observer.
62 void RemoveObserver(NetworkStateInformerObserver* observer);
64 // NetworkStateHandlerObserver implementation:
65 virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE;
67 // NetworkPortalDetector::Observer implementation:
68 virtual void OnPortalDetectionCompleted(
69 const NetworkState* network,
70 const NetworkPortalDetector::CaptivePortalState& state) OVERRIDE;
72 // content::NotificationObserver implementation.
73 virtual void Observe(int type,
74 const content::NotificationSource& source,
75 const content::NotificationDetails& details) OVERRIDE;
77 // CaptivePortalWindowProxyDelegate implementation:
78 virtual void OnPortalDetected() OVERRIDE;
80 State state() const { return state_; }
81 std::string network_path() const { return network_path_; }
82 std::string network_type() const { return network_type_; }
84 static const char* StatusString(State state);
86 private:
87 friend class base::RefCounted<NetworkStateInformer>;
89 virtual ~NetworkStateInformer();
91 bool UpdateState();
93 void UpdateStateAndNotify();
95 void SendStateToObservers(ErrorScreenActor::ErrorReason reason);
97 State state_;
98 std::string network_path_;
99 std::string network_type_;
101 ObserverList<NetworkStateInformerObserver> observers_;
102 content::NotificationRegistrar registrar_;
104 base::WeakPtrFactory<NetworkStateInformer> weak_ptr_factory_;
107 } // namespace chromeos
109 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_STATE_INFORMER_H_