Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / apps / shell / browser / shell_network_controller_chromeos.h
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   ShellNetworkController();
26   virtual ~ShellNetworkController();
27
28   // chromeos::NetworkStateHandlerObserver overrides:
29   virtual void NetworkListChanged() OVERRIDE;
30   virtual void DefaultNetworkChanged(
31       const chromeos::NetworkState* state) OVERRIDE;
32
33  private:
34   // Controls whether scanning is performed periodically.
35   void SetScanningEnabled(bool enabled);
36
37   // Asks shill to scan for networks.
38   void RequestScan();
39
40   // If not currently connected or connecting, chooses a wireless network and
41   // asks shill to connect to it.
42   void ConnectIfUnconnected();
43
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);
49
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_;
55
56   // Invokes RequestScan() periodically.
57   base::RepeatingTimer<ShellNetworkController> scan_timer_;
58
59   base::WeakPtrFactory<ShellNetworkController> weak_ptr_factory_;
60
61   DISALLOW_COPY_AND_ASSIGN(ShellNetworkController);
62 };
63
64 }  // namespace apps
65
66 #endif  // APPS_SHELL_BROWSER_SHELL_NETWORK_CONTROLLER_CHROMEOS_H_