Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: chromeos/network/network_connection_handler.h

Issue 14566009: Add NetworkConnectionHandler class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address feedback, remove configuration. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_
6 #define CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_
7
8 #include <set>
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/values.h"
15 #include "chromeos/chromeos_export.h"
16 #include "chromeos/dbus/dbus_method_call_status.h"
17 #include "chromeos/network/network_handler_callbacks.h"
18
19 namespace chromeos {
20
21 class NetworkState;
22
23 // The NetworkConnectionHandler class is used to manage network connection
24 // requests. This is the only class that should make Shill Connect calls.
25 // It handles the following steps:
26 // 1. Determine whether or not sufficient information (e.g. passphrase) is
27 // known to be available to connect to the network.
28 // 2. Request additional information (e.g. user data which contains certificate
29 // information) and determine whether sufficient information is available.
30 // 3. Send the connect request.
31 // 4. Invoke the appropriate callback (always) on success or failure.
32 //
33 // NetworkConnectionHandler depends on NetworkStateHandler for immediately
34 // available State information, and NetworkConfigurationHandler for any
35 // configuration calls.
36
37 class CHROMEOS_EXPORT NetworkConnectionHandler
38 : public base::SupportsWeakPtr<NetworkConnectionHandler> {
39 public:
40 // Sets the global instance. Must be called before any calls to Get().
41 static void Initialize();
42
43 // Destroys the global instance.
44 static void Shutdown();
45
46 // Gets the global instance. Initialize() must be called first.
47 static NetworkConnectionHandler* Get();
48
49 // ConnectToNetwork() will start an asynchronous connection attempt.
50 // On success, |success_callback| will be called.
51 // On failure, |error_callback| will be called with |error_name| one of:
52 // kNetworkNotFound if no network matching |service_path| is found
53 // (hidden networks must be configured before connecting).
54 // kConnected if already connected to the network.
55 // kConnecting if already connecting to the network.
56 // kCertificateRequired if the network requires a cert and none exists.
57 // kPassphraseRequired if passphrase only is required.
58 // kConfigurationRequired if additional configuration is required.
59 // kShillError if a DBus or Shill error occurred.
60 // |error_message| will contain an additional error string for debugging.
61 void ConnectToNetwork(const std::string& service_path,
62 const base::Closure& success_callback,
63 const network_handler::ErrorCallback& error_callback);
64
65 // DisconnectToNetwork() will send a Disconnect request to Shill.
66 // On success, |success_callback| will be called.
67 // On failure, |error_callback| will be called with |error_name| one of:
68 // kNetworkNotFound if no network matching |service_path| is found.
69 // kNotConnected if not connected to the network.
70 // kShillError if a DBus or Shill error occurred.
71 // |error_message| will contain and additional error string for debugging.
72 void DisconnectNetwork(const std::string& service_path,
73 const base::Closure& success_callback,
74 const network_handler::ErrorCallback& error_callback);
75
76 // Constants for |error_name| from |error_callback| for Connect/Disconnect.
77 static const char kNetworkNotFound[];
78 static const char kConnected[];
79 static const char kConnecting[];
80 static const char kNotConnected[];
81 static const char kPassphraseRequired[];
82 static const char kActivationRequired[];
83 static const char kCertificateRequired[];
84 static const char kConfigurationRequired[];
85 static const char kShillError[];
86
87 private:
88 NetworkConnectionHandler();
89 ~NetworkConnectionHandler();
90
91 // Calls Shill.Manager.Connect asynchronously.
92 void CallShillConnect(
93 const std::string& service_path,
94 const base::Closure& success_callback,
95 const network_handler::ErrorCallback& error_callback);
96
97 // Calls Shill.Manager.Disconnect asynchronously.
98 void CallShillDisconnect(
99 const std::string& service_path,
100 const base::Closure& success_callback,
101 const network_handler::ErrorCallback& error_callback);
102
103 // Callback to Shill.Service.GetProperties. Parses properties to determine
104 // whether to invoke |error_callback|, or attemt a connection.
105 void GetPropertiesCallback(
106 const base::Closure& success_callback,
107 const network_handler::ErrorCallback& error_callback,
108 const std::string& service_path,
109 const base::DictionaryValue& properties);
110
111 // Sets the property for the service with an empty callback (logs errors).
112 void SetServiceProperty(const std::string& service_path,
113 const std::string& property,
114 const std::string& value) const;
115
116 // Handle failure from ConfigurationHandler calls.
117 void HandleConfigurationFailure(
118 const std::string& service_path,
119 const network_handler::ErrorCallback& error_callback,
120 const std::string& error_name,
121 scoped_ptr<base::DictionaryValue> error_data);
122
123 // Handle success or failure from Shill.Service.Connect.
124 void HandleShillSuccess(const std::string& service_path,
125 const base::Closure& success_callback);
126 void HandleShillFailure(const std::string& service_path,
127 const network_handler::ErrorCallback& error_callback,
128 const std::string& error_name,
129 const std::string& error_message);
130
131 // Set of pending connect requests, used to prevent repeat attempts while
132 // waiting for Shill.
133 std::set<std::string> pending_requests_;
134
135 DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandler);
136 };
137
138 } // namespace chromeos
139
140 #endif // CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698