OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef APPS_SHELL_BROWSER_SHELL_NETWORK_CONTROLLER_CHROMEOS_H_ | |
6 #define APPS_SHELL_BROWSER_SHELL_NETWORK_CONTROLLER_CHROMEOS_H_ | |
7 | |
8 #include <string> | |
9 | |
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" | |
17 | |
18 namespace apps { | |
19 | |
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 virtual ~ShellNetworkController(); | |
27 | |
28 // chromeos::NetworkStateHandlerObserver overrides: | |
29 virtual void NetworkListChanged() OVERRIDE; | |
30 virtual void NetworkConnectionStateChanged( | |
31 const chromeos::NetworkState* state) OVERRIDE; | |
32 | |
33 private: | |
34 // State of communication with the connection manager. | |
35 enum State { | |
36 // No in-progress requests. | |
37 STATE_IDLE = 0, | |
38 // Waiting for the result of an attempt to connect to the preferred network. | |
39 STATE_WAITING_FOR_PREFERRED_RESULT, | |
40 // Waiting for the result of an attempt to connect to a non-preferred | |
41 // network. | |
42 STATE_WAITING_FOR_NON_PREFERRED_RESULT, | |
43 }; | |
44 | |
45 // Returns the connected or connecting WiFi network or NULL if no network | |
46 // matches that description. | |
47 const chromeos::NetworkState* GetActiveWiFiNetwork(); | |
48 | |
49 // Controls whether scanning is performed periodically. | |
50 void SetScanningEnabled(bool enabled); | |
51 | |
52 // Asks the connection manager to scan for networks. | |
53 void RequestScan(); | |
54 | |
55 // If not currently connected or connecting, chooses a wireless network and | |
56 // asks the connection manager to connect to it. Also switches to | |
57 // |preferred_network_name_| if possible. | |
58 void ConnectIfUnconnected(); | |
59 | |
60 // Handles a successful or failed connection attempt. | |
61 void HandleConnectionSuccess(); | |
62 void HandleConnectionError( | |
63 const std::string& error_name, | |
64 scoped_ptr<base::DictionaryValue> error_data); | |
65 | |
66 // Current status of communication with the chromeos::NetworkStateHandler. | |
67 // This is tracked to avoid sending duplicate requests before the handler has | |
68 // acknowledged the initial connection attempt. | |
69 State state_; | |
70 | |
71 // Invokes RequestScan() periodically. | |
72 base::RepeatingTimer<ShellNetworkController> scan_timer_; | |
73 | |
74 // Optionally-supplied name of the preferred network. | |
75 std::string preferred_network_name_; | |
76 | |
77 // True if the preferred network is connected or connecting. | |
78 bool preferred_network_is_active_; | |
79 | |
80 base::WeakPtrFactory<ShellNetworkController> weak_ptr_factory_; | |
81 | |
82 DISALLOW_COPY_AND_ASSIGN(ShellNetworkController); | |
83 }; | |
84 | |
85 } // namespace apps | |
86 | |
87 #endif // APPS_SHELL_BROWSER_SHELL_NETWORK_CONTROLLER_CHROMEOS_H_ | |
OLD | NEW |