Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / extensions / shell / browser / shell_network_controller_chromeos.h
blob4945c805885b65ca215a2348d2f657dbee911662
1 // Copyright 2014 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 EXTENSIONS_SHELL_BROWSER_SHELL_NETWORK_CONTROLLER_CHROMEOS_H_
6 #define EXTENSIONS_SHELL_BROWSER_SHELL_NETWORK_CONTROLLER_CHROMEOS_H_
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/timer/timer.h"
15 #include "base/values.h"
16 #include "chromeos/network/network_state_handler_observer.h"
18 namespace extensions {
20 // Handles network-related tasks for app_shell on Chrome OS.
21 class ShellNetworkController : public chromeos::NetworkStateHandlerObserver {
22 public:
23 // This class must be instantiated after chromeos::DBusThreadManager and
24 // destroyed before it.
25 explicit ShellNetworkController(const std::string& preferred_network_name);
26 ~ShellNetworkController() override;
28 // chromeos::NetworkStateHandlerObserver overrides:
29 void NetworkListChanged() override;
30 void NetworkConnectionStateChanged(
31 const chromeos::NetworkState* state) override;
33 // Control whether the cellular network connection allows roaming.
34 void SetCellularAllowRoaming(bool allow_roaming);
36 private:
37 // State of communication with the connection manager.
38 enum State {
39 // No in-progress requests.
40 STATE_IDLE = 0,
41 // Waiting for the result of an attempt to connect to the preferred network.
42 STATE_WAITING_FOR_PREFERRED_RESULT,
43 // Waiting for the result of an attempt to connect to a non-preferred
44 // network.
45 STATE_WAITING_FOR_NON_PREFERRED_RESULT,
48 // Returns the connected or connecting WiFi network or NULL if no network
49 // matches that description.
50 const chromeos::NetworkState* GetActiveWiFiNetwork();
52 // Controls whether scanning is performed periodically.
53 void SetScanningEnabled(bool enabled);
55 // Asks the connection manager to scan for networks.
56 void RequestScan();
58 // If not currently connected or connecting, chooses a wireless network and
59 // asks the connection manager to connect to it. Also switches to
60 // |preferred_network_name_| if possible.
61 void ConnectIfUnconnected();
63 // Handles a successful or failed connection attempt.
64 void HandleConnectionSuccess();
65 void HandleConnectionError(const std::string& error_name,
66 scoped_ptr<base::DictionaryValue> error_data);
68 // Current status of communication with the chromeos::NetworkStateHandler.
69 // This is tracked to avoid sending duplicate requests before the handler has
70 // acknowledged the initial connection attempt.
71 State state_;
73 // Invokes RequestScan() periodically.
74 base::RepeatingTimer<ShellNetworkController> scan_timer_;
76 // Optionally-supplied name of the preferred network.
77 std::string preferred_network_name_;
79 // True if the preferred network is connected or connecting.
80 bool preferred_network_is_active_;
82 base::WeakPtrFactory<ShellNetworkController> weak_ptr_factory_;
84 DISALLOW_COPY_AND_ASSIGN(ShellNetworkController);
87 } // namespace extensions
89 #endif // EXTENSIONS_SHELL_BROWSER_SHELL_NETWORK_CONTROLLER_CHROMEOS_H_