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 APPS_SHELL_BROWSER_SHELL_NETWORK_CONTROLLER_CHROMEOS_H_
6 #define APPS_SHELL_BROWSER_SHELL_NETWORK_CONTROLLER_CHROMEOS_H_
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"
20 // Handles network-related tasks for app_shell on Chrome OS.
21 class ShellNetworkController : public chromeos::NetworkStateHandlerObserver {
23 // This class must be instantiated after chromeos::DBusThreadManager and
24 // destroyed before it.
25 ShellNetworkController();
26 virtual ~ShellNetworkController();
28 // chromeos::NetworkStateHandlerObserver overrides:
29 virtual void NetworkListChanged() OVERRIDE;
30 virtual void DefaultNetworkChanged(
31 const chromeos::NetworkState* state) OVERRIDE;
34 // Controls whether scanning is performed periodically.
35 void SetScanningEnabled(bool enabled);
37 // Asks shill to scan for networks.
40 // If not currently connected or connecting, chooses a wireless network and
41 // asks shill to connect to it.
42 void ConnectIfUnconnected();
44 // Handles a successful or failed connection attempt.
45 void HandleConnectionSuccess();
46 void HandleConnectionError(
47 const std::string& error_name,
48 scoped_ptr<base::DictionaryValue> error_data);
50 // True when ConnectIfUnconnected() has asked shill to connect but the attempt
51 // hasn't succeeded or failed yet. This is tracked to avoid sending duplicate
52 // requests before chromeos::NetworkStateHandler has acknowledged the initial
53 // connection attempt.
54 bool waiting_for_connection_result_;
56 // Invokes RequestScan() periodically.
57 base::RepeatingTimer<ShellNetworkController> scan_timer_;
59 base::WeakPtrFactory<ShellNetworkController> weak_ptr_factory_;
61 DISALLOW_COPY_AND_ASSIGN(ShellNetworkController);
66 #endif // APPS_SHELL_BROWSER_SHELL_NETWORK_CONTROLLER_CHROMEOS_H_