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

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

Issue 2861883002: [CrOS Tether] Transform NetworkConnectionHandler to an interface. (Closed)
Patch Set: stevenjb@ comments. Created 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2017 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_IMPL_H_
6 #define CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_IMPL_H_
7
8 #include "chromeos/cert_loader.h"
9 #include "chromeos/chromeos_export.h"
10 #include "chromeos/dbus/dbus_method_call_status.h"
11 #include "chromeos/login/login_state.h"
12 #include "chromeos/network/network_connection_handler.h"
13 #include "chromeos/network/network_state_handler_observer.h"
14
15 namespace chromeos {
16
17 // Implementation of NetworkConnectionHandler.
18 class CHROMEOS_EXPORT NetworkConnectionHandlerImpl
19 : public NetworkConnectionHandler,
20 public LoginState::Observer,
21 public CertLoader::Observer,
22 public NetworkStateHandlerObserver,
23 public base::SupportsWeakPtr<NetworkConnectionHandlerImpl> {
24 public:
25 NetworkConnectionHandlerImpl();
26 ~NetworkConnectionHandlerImpl() override;
27
28 // NetworkConnectionHandler:
29 void ConnectToNetwork(const std::string& service_path,
30 const base::Closure& success_callback,
31 const network_handler::ErrorCallback& error_callback,
32 bool check_error_state) override;
33 void DisconnectNetwork(
34 const std::string& service_path,
35 const base::Closure& success_callback,
36 const network_handler::ErrorCallback& error_callback) override;
37 bool HasConnectingNetwork(const std::string& service_path) override;
38 bool HasPendingConnectRequest() override;
39
40 // NetworkStateHandlerObserver
41 void NetworkListChanged() override;
42 void NetworkPropertiesUpdated(const NetworkState* network) override;
43
44 // LoginState::Observer
45 void LoggedInStateChanged() override;
46
47 // CertLoader::Observer
48 void OnCertificatesLoaded(const net::CertificateList& cert_list,
49 bool initial_load) override;
50
51 protected:
52 void Init(NetworkStateHandler* network_state_handler,
53 NetworkConfigurationHandler* network_configuration_handler,
54 ManagedNetworkConfigurationHandler*
55 managed_network_configuration_handler) override;
56
57 private:
58 struct ConnectRequest {
59 ConnectRequest(const std::string& service_path,
60 const std::string& profile_path,
61 const base::Closure& success,
62 const network_handler::ErrorCallback& error);
63 ~ConnectRequest();
64 explicit ConnectRequest(const ConnectRequest& other);
65
66 enum ConnectState {
67 CONNECT_REQUESTED = 0,
68 CONNECT_STARTED = 1,
69 CONNECT_CONNECTING = 2
70 };
71
72 std::string service_path;
73 std::string profile_path;
74 ConnectState connect_state;
75 base::Closure success_callback;
76 network_handler::ErrorCallback error_callback;
77 };
78
79 ConnectRequest* GetPendingRequest(const std::string& service_path);
80
81 // Callback from Shill.Service.GetProperties. Parses |properties| to verify
82 // whether or not the network appears to be configured. If configured,
83 // attempts a connection, otherwise invokes error_callback from
84 // pending_requests_[service_path]. |check_error_state| is passed from
85 // ConnectToNetwork(), see comment for info.
86 void VerifyConfiguredAndConnect(bool check_error_state,
87 const std::string& service_path,
88 const base::DictionaryValue& properties);
89
90 bool IsNetworkProhibitedByPolicy(const std::string& type,
91 const std::string& guid,
92 const std::string& profile_path);
93
94 // Queues a connect request until certificates have loaded.
95 void QueueConnectRequest(const std::string& service_path);
96
97 // Checks to see if certificates have loaded and if not, cancels any queued
98 // connect request and notifies the user.
99 void CheckCertificatesLoaded();
100
101 // Handles connecting to a queued network after certificates are loaded or
102 // handle cert load timeout.
103 void ConnectToQueuedNetwork();
104
105 // Calls Shill.Manager.Connect asynchronously.
106 void CallShillConnect(const std::string& service_path);
107
108 // Handles failure from ConfigurationHandler calls.
109 void HandleConfigurationFailure(
110 const std::string& service_path,
111 const std::string& error_name,
112 std::unique_ptr<base::DictionaryValue> error_data);
113
114 // Handles success or failure from Shill.Service.Connect.
115 void HandleShillConnectSuccess(const std::string& service_path);
116 void HandleShillConnectFailure(const std::string& service_path,
117 const std::string& error_name,
118 const std::string& error_message);
119
120 // Note: |service_path| is passed by value here, because in some cases
121 // the value may be located in the map and then it can be deleted, producing
122 // a reference to invalid memory.
123 void CheckPendingRequest(const std::string service_path);
124
125 void CheckAllPendingRequests();
126
127 // Look up the ConnectRequest for |service_path| and call
128 // InvokeConnectErrorCallback.
129 void ErrorCallbackForPendingRequest(const std::string& service_path,
130 const std::string& error_name);
131
132 // Calls Shill.Manager.Disconnect asynchronously.
133 void CallShillDisconnect(
134 const std::string& service_path,
135 const base::Closure& success_callback,
136 const network_handler::ErrorCallback& error_callback);
137
138 // Handle success from Shill.Service.Disconnect.
139 void HandleShillDisconnectSuccess(const std::string& service_path,
140 const base::Closure& success_callback);
141
142 // Local references to the associated handler instances.
143 CertLoader* cert_loader_;
144 NetworkStateHandler* network_state_handler_;
145 NetworkConfigurationHandler* configuration_handler_;
146 ManagedNetworkConfigurationHandler* managed_configuration_handler_;
147
148 // Map of pending connect requests, used to prevent repeated attempts while
149 // waiting for Shill and to trigger callbacks on eventual success or failure.
150 std::map<std::string, ConnectRequest> pending_requests_;
151 std::unique_ptr<ConnectRequest> queued_connect_;
152
153 // Track certificate loading state.
154 bool logged_in_;
155 bool certificates_loaded_;
156 base::TimeTicks logged_in_time_;
157
158 DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandlerImpl);
159 };
160
161 } // namespace chromeos
162
163 #endif // CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_IMPL_H_
OLDNEW
« no previous file with comments | « chromeos/network/network_connection_handler.cc ('k') | chromeos/network/network_connection_handler_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698