OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #ifndef CHROME_BROWSER_CHROMEOS_NET_CONNECTIVITY_STATE_HELPER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_NET_CONNECTIVITY_STATE_HELPER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_NET_CONNECTIVITY_STATE_HELPER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_NET_CONNECTIVITY_STATE_HELPER_H_ |
7 | 7 |
| 8 #include "base/observer_list.h" |
8 #include "chrome/browser/chromeos/cros/network_library.h" | 9 #include "chrome/browser/chromeos/cros/network_library.h" |
| 10 #include "chrome/browser/chromeos/net/connectivity_state_helper_observer.h" |
9 #include "chromeos/network/network_state_handler.h" | 11 #include "chromeos/network/network_state_handler.h" |
10 #include "chromeos/network/network_state_handler_observer.h" | |
11 | 12 |
12 namespace chromeos { | 13 namespace chromeos { |
13 | 14 |
14 // This class provides an interface for consumers to query the connectivity | 15 // This class provides an interface for consumers to query the connectivity |
15 // state on Chrome OS. Subclasses must implement the query methods using an | 16 // state on Chrome OS. Subclasses must implement the query methods using an |
16 // appropriate source (e.g. NetworkStateHandler). | 17 // appropriate source (e.g. NetworkStateHandler). |
17 class ConnectivityStateHelper { | 18 class ConnectivityStateHelper { |
18 public: | 19 public: |
19 virtual ~ConnectivityStateHelper() {} | 20 virtual ~ConnectivityStateHelper(); |
20 | 21 |
21 // Initializes the state helper singleton to use the default (network state | 22 // Initializes the state helper singleton to use the default (network state |
22 // handler) implementation or the network library implementation based | 23 // handler) implementation or the network library implementation based |
23 // on the value of command line flag. | 24 // on the value of command line flag. |
24 static void Initialize(); | 25 static void Initialize(); |
25 | 26 |
26 // Similar to initialize, but can be used to inject an alternative | 27 // Similar to initialize, but can be used to inject an alternative |
27 // (say,a MockConnectivityStateHelper) implementation. | 28 // (say,a MockConnectivityStateHelper) implementation. |
28 static void InitializeForTesting(ConnectivityStateHelper* csh); | 29 static void InitializeForTesting(ConnectivityStateHelper* csh); |
29 | 30 |
| 31 // Returns true if the global instance has been initialized. |
| 32 static bool IsInitialized(); |
| 33 |
30 static void Shutdown(); | 34 static void Shutdown(); |
31 static ConnectivityStateHelper* Get(); | 35 static ConnectivityStateHelper* Get(); |
32 | 36 |
33 // Returns true if we are in a connected state. | 37 // Returns true if we are in a connected state. |
34 virtual bool IsConnected() = 0; | 38 virtual bool IsConnected() = 0; |
35 | 39 |
36 // Returns true if there's a network of |type| in connected state. | 40 // Returns true if there's a network of |type| in connected state. |
37 virtual bool IsConnectedType(const std::string& type) = 0; | 41 virtual bool IsConnectedType(const std::string& type) = 0; |
38 | 42 |
39 // Returns true if there's a network of |type| in connecting state. | 43 // Returns true if there's a network of |type| in connecting state. |
40 virtual bool IsConnectingType(const std::string& type) = 0; | 44 virtual bool IsConnectingType(const std::string& type) = 0; |
41 | 45 |
42 // Get the name for the primary network of type |type| which is not | 46 // Get the name for the primary network of type |type| which is not |
43 // in non-idle state (i.e. connecting or connected state). | 47 // in non-idle state (i.e. connecting or connected state). |
44 virtual std::string NetworkNameForType(const std::string& type) = 0; | 48 virtual std::string NetworkNameForType(const std::string& type) = 0; |
45 | 49 |
46 // Returns the name of the default network. | 50 // Returns the name of the default network. |
47 virtual std::string DefaultNetworkName() = 0; | 51 virtual std::string DefaultNetworkName() = 0; |
48 | 52 |
49 // Returns true if we have a default network and are in online state. | 53 // Returns true if we have a default network and are in online state. |
50 virtual bool DefaultNetworkOnline() = 0; | 54 virtual bool DefaultNetworkOnline() = 0; |
51 | 55 |
| 56 // Request a network scan. |
| 57 virtual void RequestScan() const = 0; |
| 58 |
| 59 // Add/remove observers for listening to connection manager changes. |
| 60 virtual void AddNetworkManagerObserver( |
| 61 ConnectivityStateHelperObserver* observer); |
| 62 virtual void RemoveNetworkManagerObserver( |
| 63 ConnectivityStateHelperObserver* observer); |
| 64 |
52 protected: | 65 protected: |
53 ConnectivityStateHelper() {} | 66 ConnectivityStateHelper(); |
| 67 ObserverList<ConnectivityStateHelperObserver> network_manager_observers_; |
54 }; | 68 }; |
55 | 69 |
56 } // namespace chromeos | 70 } // namespace chromeos |
57 | 71 |
58 #endif // CHROME_BROWSER_CHROMEOS_NET_CONNECTIVITY_STATE_HELPER_H_ | 72 #endif // CHROME_BROWSER_CHROMEOS_NET_CONNECTIVITY_STATE_HELPER_H_ |
OLD | NEW |