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

Unified Diff: chromeos/network/network_connection_handler_impl.cc

Issue 2861883002: [CrOS Tether] Transform NetworkConnectionHandler to an interface. (Closed)
Patch Set: stevenjb@ comments. Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chromeos/network/network_connection_handler_impl.cc
diff --git a/chromeos/network/network_connection_handler.cc b/chromeos/network/network_connection_handler_impl.cc
similarity index 77%
copy from chromeos/network/network_connection_handler.cc
copy to chromeos/network/network_connection_handler_impl.cc
index 69483bfb0cdf3d07bd25abf79e9cba5648f144e4..fb4f3201a7ffff4117570090fdef29d70afaf983 100644
--- a/chromeos/network/network_connection_handler.cc
+++ b/chromeos/network/network_connection_handler_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chromeos/network/network_connection_handler.h"
+#include "chromeos/network/network_connection_handler_impl.h"
#include "base/bind.h"
#include "base/json/json_reader.h"
@@ -10,6 +10,7 @@
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
+#include "base/time/time.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/shill_manager_client.h"
#include "chromeos/dbus/shill_service_client.h"
@@ -40,8 +41,8 @@ bool IsAuthenticationError(const std::string& error) {
}
bool VPNRequiresCredentials(const std::string& service_path,
- const std::string& provider_type,
- const base::DictionaryValue& provider_properties) {
+ const std::string& provider_type,
+ const base::DictionaryValue& provider_properties) {
if (provider_type == shill::kProviderOpenVpn) {
std::string username;
provider_properties.GetStringWithoutPathExpansion(
@@ -85,7 +86,7 @@ std::string GetDefaultUserProfilePath(const NetworkState* network) {
network->security_class() == shill::kSecurityNone)) {
return NetworkProfileHandler::GetSharedProfilePath();
}
- const NetworkProfile* profile =
+ const NetworkProfile* profile =
NetworkHandler::Get()->network_profile_handler()->GetDefaultUserProfile();
return profile ? profile->path
: NetworkProfileHandler::GetSharedProfilePath();
@@ -93,69 +94,35 @@ std::string GetDefaultUserProfilePath(const NetworkState* network) {
} // namespace
-const char NetworkConnectionHandler::kErrorNotFound[] = "not-found";
-const char NetworkConnectionHandler::kErrorConnected[] = "connected";
-const char NetworkConnectionHandler::kErrorConnecting[] = "connecting";
-const char NetworkConnectionHandler::kErrorNotConnected[] = "not-connected";
-const char NetworkConnectionHandler::kErrorPassphraseRequired[] =
- "passphrase-required";
-const char NetworkConnectionHandler::kErrorBadPassphrase[] = "bad-passphrase";
-const char NetworkConnectionHandler::kErrorCertificateRequired[] =
- "certificate-required";
-const char NetworkConnectionHandler::kErrorConfigurationRequired[] =
- "configuration-required";
-const char NetworkConnectionHandler::kErrorAuthenticationRequired[] =
- "authentication-required";
-const char NetworkConnectionHandler::kErrorConnectFailed[] = "connect-failed";
-const char NetworkConnectionHandler::kErrorDisconnectFailed[] =
- "disconnect-failed";
-const char NetworkConnectionHandler::kErrorConfigureFailed[] =
- "configure-failed";
-const char NetworkConnectionHandler::kErrorConnectCanceled[] =
- "connect-canceled";
-const char NetworkConnectionHandler::kErrorCertLoadTimeout[] =
- "cert-load-timeout";
-const char NetworkConnectionHandler::kErrorUnmanagedNetwork[] =
- "unmanaged-network";
-const char NetworkConnectionHandler::kErrorActivateFailed[] = "activate-failed";
-const char NetworkConnectionHandler::kErrorEnabledOrDisabledWhenNotAvailable[] =
- "not-available";
-const char
- NetworkConnectionHandler::kErrorTetherConnectionAttemptWithNoDelegate[] =
- "tether-with-no-delegate";
-
-struct NetworkConnectionHandler::ConnectRequest {
- ConnectRequest(const std::string& service_path,
- const std::string& profile_path,
- const base::Closure& success,
- const network_handler::ErrorCallback& error)
- : service_path(service_path),
- profile_path(profile_path),
- connect_state(CONNECT_REQUESTED),
- success_callback(success),
- error_callback(error) {
- }
- enum ConnectState {
- CONNECT_REQUESTED = 0,
- CONNECT_STARTED = 1,
- CONNECT_CONNECTING = 2
- };
- std::string service_path;
- std::string profile_path;
- ConnectState connect_state;
- base::Closure success_callback;
- network_handler::ErrorCallback error_callback;
-};
-
-NetworkConnectionHandler::NetworkConnectionHandler()
+NetworkConnectionHandlerImpl::ConnectRequest::ConnectRequest(
+ const std::string& service_path,
+ const std::string& profile_path,
+ const base::Closure& success,
+ const network_handler::ErrorCallback& error)
+ : service_path(service_path),
+ profile_path(profile_path),
+ connect_state(CONNECT_REQUESTED),
+ success_callback(success),
+ error_callback(error) {}
+
+NetworkConnectionHandlerImpl::ConnectRequest::~ConnectRequest() {}
+
+NetworkConnectionHandlerImpl::ConnectRequest::ConnectRequest(
+ const ConnectRequest& other)
+ : service_path(other.service_path),
+ profile_path(other.profile_path),
+ connect_state(other.connect_state),
+ success_callback(other.success_callback),
+ error_callback(other.error_callback) {}
+
+NetworkConnectionHandlerImpl::NetworkConnectionHandlerImpl()
: cert_loader_(NULL),
network_state_handler_(NULL),
configuration_handler_(NULL),
logged_in_(false),
- certificates_loaded_(false),
- tether_delegate_(nullptr) {}
+ certificates_loaded_(false) {}
-NetworkConnectionHandler::~NetworkConnectionHandler() {
+NetworkConnectionHandlerImpl::~NetworkConnectionHandlerImpl() {
if (network_state_handler_)
network_state_handler_->RemoveObserver(this, FROM_HERE);
if (cert_loader_)
@@ -164,7 +131,7 @@ NetworkConnectionHandler::~NetworkConnectionHandler() {
LoginState::Get()->RemoveObserver(this);
}
-void NetworkConnectionHandler::Init(
+void NetworkConnectionHandlerImpl::Init(
NetworkStateHandler* network_state_handler,
NetworkConfigurationHandler* network_configuration_handler,
ManagedNetworkConfigurationHandler* managed_network_configuration_handler) {
@@ -191,24 +158,14 @@ void NetworkConnectionHandler::Init(
configuration_handler_ = network_configuration_handler;
managed_configuration_handler_ = managed_network_configuration_handler;
- // After this point, the NetworkConnectionHandler is fully initialized (all
- // handler references set, observers registered, ...).
+ // After this point, the NetworkConnectionHandlerImpl is fully initialized
+ // (all handler references set, observers registered, ...).
if (LoginState::IsInitialized())
LoggedInStateChanged();
}
-void NetworkConnectionHandler::AddObserver(
- NetworkConnectionObserver* observer) {
- observers_.AddObserver(observer);
-}
-
-void NetworkConnectionHandler::RemoveObserver(
- NetworkConnectionObserver* observer) {
- observers_.RemoveObserver(observer);
-}
-
-void NetworkConnectionHandler::LoggedInStateChanged() {
+void NetworkConnectionHandlerImpl::LoggedInStateChanged() {
LoginState* login_state = LoginState::Get();
if (logged_in_ || !login_state->IsUserLoggedIn())
return;
@@ -217,7 +174,7 @@ void NetworkConnectionHandler::LoggedInStateChanged() {
logged_in_time_ = base::TimeTicks::Now();
}
-void NetworkConnectionHandler::OnCertificatesLoaded(
+void NetworkConnectionHandlerImpl::OnCertificatesLoaded(
const net::CertificateList& cert_list,
bool initial_load) {
certificates_loaded_ = true;
@@ -226,20 +183,7 @@ void NetworkConnectionHandler::OnCertificatesLoaded(
ConnectToQueuedNetwork();
}
-void NetworkConnectionHandler::InitiateTetherNetworkConnection(
- const std::string& tether_network_guid,
- const base::Closure& success_callback,
- const network_handler::ErrorCallback& error_callback) {
- DCHECK(tether_delegate_);
- tether_delegate_->ConnectToNetwork(
- tether_network_guid,
- base::Bind(&NetworkConnectionHandler::InvokeConnectSuccessCallback,
- AsWeakPtr(), tether_network_guid, success_callback),
- base::Bind(&NetworkConnectionHandler::InvokeConnectErrorCallback,
- AsWeakPtr(), tether_network_guid, error_callback));
-}
-
-void NetworkConnectionHandler::ConnectToNetwork(
+void NetworkConnectionHandlerImpl::ConnectToNetwork(
const std::string& service_path,
const base::Closure& success_callback,
const network_handler::ErrorCallback& error_callback,
@@ -311,10 +255,9 @@ void NetworkConnectionHandler::ConnectToNetwork(
profile_path = GetDefaultUserProfilePath(network);
// All synchronous checks passed, add |service_path| to connecting list.
- pending_requests_.insert(std::make_pair(
- service_path,
- ConnectRequest(service_path, profile_path,
- success_callback, error_callback)));
+ pending_requests_.emplace(
+ service_path, ConnectRequest(service_path, profile_path, success_callback,
+ error_callback));
// Connect immediately to 'connectable' networks.
// TODO(stevenjb): Shill needs to properly set Connectable for VPN.
@@ -334,13 +277,13 @@ void NetworkConnectionHandler::ConnectToNetwork(
// are up to date after any recent configuration.
configuration_handler_->GetShillProperties(
service_path,
- base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect,
+ base::Bind(&NetworkConnectionHandlerImpl::VerifyConfiguredAndConnect,
AsWeakPtr(), check_error_state),
- base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure,
+ base::Bind(&NetworkConnectionHandlerImpl::HandleConfigurationFailure,
AsWeakPtr(), service_path));
}
-void NetworkConnectionHandler::DisconnectNetwork(
+void NetworkConnectionHandlerImpl::DisconnectNetwork(
const std::string& service_path,
const base::Closure& success_callback,
const network_handler::ErrorCallback& error_callback) {
@@ -366,32 +309,28 @@ void NetworkConnectionHandler::DisconnectNetwork(
CallShillDisconnect(service_path, success_callback, error_callback);
}
-bool NetworkConnectionHandler::HasConnectingNetwork(
+bool NetworkConnectionHandlerImpl::HasConnectingNetwork(
const std::string& service_path) {
return pending_requests_.count(service_path) != 0;
}
-bool NetworkConnectionHandler::HasPendingConnectRequest() {
+bool NetworkConnectionHandlerImpl::HasPendingConnectRequest() {
return pending_requests_.size() > 0;
}
-void NetworkConnectionHandler::SetTetherDelegate(
- TetherDelegate* tether_delegate) {
- tether_delegate_ = tether_delegate;
-}
-
-void NetworkConnectionHandler::NetworkListChanged() {
+void NetworkConnectionHandlerImpl::NetworkListChanged() {
CheckAllPendingRequests();
}
-void NetworkConnectionHandler::NetworkPropertiesUpdated(
+void NetworkConnectionHandlerImpl::NetworkPropertiesUpdated(
const NetworkState* network) {
if (HasConnectingNetwork(network->path()))
CheckPendingRequest(network->path());
}
-NetworkConnectionHandler::ConnectRequest*
-NetworkConnectionHandler::GetPendingRequest(const std::string& service_path) {
+NetworkConnectionHandlerImpl::ConnectRequest*
+NetworkConnectionHandlerImpl::GetPendingRequest(
+ const std::string& service_path) {
std::map<std::string, ConnectRequest>::iterator iter =
pending_requests_.find(service_path);
return iter != pending_requests_.end() ? &(iter->second) : NULL;
@@ -399,7 +338,7 @@ NetworkConnectionHandler::GetPendingRequest(const std::string& service_path) {
// ConnectToNetwork implementation
-void NetworkConnectionHandler::VerifyConfiguredAndConnect(
+void NetworkConnectionHandlerImpl::VerifyConfiguredAndConnect(
bool check_error_state,
const std::string& service_path,
const base::DictionaryValue& service_properties) {
@@ -420,8 +359,8 @@ void NetworkConnectionHandler::VerifyConfiguredAndConnect(
service_properties.GetStringWithoutPathExpansion(
shill::kSecurityClassProperty, &security_class);
bool connectable = false;
- service_properties.GetBooleanWithoutPathExpansion(
- shill::kConnectableProperty, &connectable);
+ service_properties.GetBooleanWithoutPathExpansion(shill::kConnectableProperty,
+ &connectable);
// In case NetworkState was not available in ConnectToNetwork (e.g. it had
// been recently configured), we need to check Connectable again.
@@ -440,10 +379,10 @@ void NetworkConnectionHandler::VerifyConfiguredAndConnect(
// "Provider.Type", etc keys (which are used only to set the values).
if (service_properties.GetDictionaryWithoutPathExpansion(
shill::kProviderProperty, &provider_properties)) {
- provider_properties->GetStringWithoutPathExpansion(
- shill::kTypeProperty, &vpn_provider_type);
- provider_properties->GetStringWithoutPathExpansion(
- shill::kHostProperty, &vpn_provider_host);
+ provider_properties->GetStringWithoutPathExpansion(shill::kTypeProperty,
+ &vpn_provider_type);
+ provider_properties->GetStringWithoutPathExpansion(shill::kHostProperty,
+ &vpn_provider_host);
provider_properties->GetStringWithoutPathExpansion(
shill::kL2tpIpsecClientCertIdProperty, &vpn_client_cert_id);
}
@@ -525,9 +464,8 @@ void NetworkConnectionHandler::VerifyConfiguredAndConnect(
ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired);
return;
}
- } else if (check_error_state &&
- !client_cert::IsCertificateConfigured(client_cert_type,
- service_properties)) {
+ } else if (check_error_state && !client_cert::IsCertificateConfigured(
+ client_cert_type, service_properties)) {
// Network may not be configured.
ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired);
return;
@@ -538,8 +476,8 @@ void NetworkConnectionHandler::VerifyConfiguredAndConnect(
// VPN may require a username, and/or passphrase to be set. (Check after
// ensuring that any required certificates are configured).
DCHECK(provider_properties);
- if (VPNRequiresCredentials(
- service_path, vpn_provider_type, *provider_properties)) {
+ if (VPNRequiresCredentials(service_path, vpn_provider_type,
+ *provider_properties)) {
NET_LOG_USER("VPN Requires Credentials", service_path);
ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired);
return;
@@ -558,9 +496,9 @@ void NetworkConnectionHandler::VerifyConfiguredAndConnect(
configuration_handler_->SetShillProperties(
service_path, config_properties,
NetworkConfigurationObserver::SOURCE_USER_ACTION,
- base::Bind(&NetworkConnectionHandler::CallShillConnect, AsWeakPtr(),
+ base::Bind(&NetworkConnectionHandlerImpl::CallShillConnect, AsWeakPtr(),
service_path),
- base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure,
+ base::Bind(&NetworkConnectionHandlerImpl::HandleConfigurationFailure,
AsWeakPtr(), service_path));
return;
}
@@ -575,7 +513,7 @@ void NetworkConnectionHandler::VerifyConfiguredAndConnect(
CallShillConnect(service_path);
}
-bool NetworkConnectionHandler::IsNetworkProhibitedByPolicy(
+bool NetworkConnectionHandlerImpl::IsNetworkProhibitedByPolicy(
const std::string& type,
const std::string& guid,
const std::string& profile_path) {
@@ -599,7 +537,7 @@ bool NetworkConnectionHandler::IsNetworkProhibitedByPolicy(
guid, profile_path, nullptr /* onc_source */);
}
-void NetworkConnectionHandler::QueueConnectRequest(
+void NetworkConnectionHandlerImpl::QueueConnectRequest(
const std::string& service_path) {
ConnectRequest* request = GetPendingRequest(service_path);
if (!request) {
@@ -617,21 +555,22 @@ void NetworkConnectionHandler::QueueConnectRequest(
}
NET_LOG_EVENT("Connect Request Queued", service_path);
- queued_connect_.reset(new ConnectRequest(
- service_path, request->profile_path,
- request->success_callback, request->error_callback));
+ queued_connect_.reset(new ConnectRequest(service_path, request->profile_path,
+ request->success_callback,
+ request->error_callback));
pending_requests_.erase(service_path);
// Post a delayed task to check to see if certificates have loaded. If they
// haven't, and queued_connect_ has not been cleared (e.g. by a successful
// connect request), cancel the request and notify the user.
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
- FROM_HERE, base::Bind(&NetworkConnectionHandler::CheckCertificatesLoaded,
- AsWeakPtr()),
+ FROM_HERE,
+ base::Bind(&NetworkConnectionHandlerImpl::CheckCertificatesLoaded,
+ AsWeakPtr()),
base::TimeDelta::FromSeconds(kMaxCertLoadTimeSeconds) - dtime);
}
-void NetworkConnectionHandler::CheckCertificatesLoaded() {
+void NetworkConnectionHandlerImpl::CheckCertificatesLoaded() {
if (certificates_loaded_)
return;
// If queued_connect_ has been cleared (e.g. another connect request occurred
@@ -646,7 +585,7 @@ void NetworkConnectionHandler::CheckCertificatesLoaded() {
queued_connect_.reset();
}
-void NetworkConnectionHandler::ConnectToQueuedNetwork() {
+void NetworkConnectionHandlerImpl::ConnectToQueuedNetwork() {
DCHECK(queued_connect_);
// Make a copy of |queued_connect_| parameters, because |queued_connect_|
@@ -661,19 +600,19 @@ void NetworkConnectionHandler::ConnectToQueuedNetwork() {
false /* check_error_state */);
}
-void NetworkConnectionHandler::CallShillConnect(
+void NetworkConnectionHandlerImpl::CallShillConnect(
const std::string& service_path) {
NET_LOG_EVENT("Sending Connect Request to Shill", service_path);
network_state_handler_->ClearLastErrorForNetwork(service_path);
DBusThreadManager::Get()->GetShillServiceClient()->Connect(
dbus::ObjectPath(service_path),
- base::Bind(&NetworkConnectionHandler::HandleShillConnectSuccess,
+ base::Bind(&NetworkConnectionHandlerImpl::HandleShillConnectSuccess,
AsWeakPtr(), service_path),
- base::Bind(&NetworkConnectionHandler::HandleShillConnectFailure,
+ base::Bind(&NetworkConnectionHandlerImpl::HandleShillConnectFailure,
AsWeakPtr(), service_path));
}
-void NetworkConnectionHandler::HandleConfigurationFailure(
+void NetworkConnectionHandlerImpl::HandleConfigurationFailure(
const std::string& service_path,
const std::string& error_name,
std::unique_ptr<base::DictionaryValue> error_data) {
@@ -689,7 +628,7 @@ void NetworkConnectionHandler::HandleConfigurationFailure(
kErrorConfigureFailed);
}
-void NetworkConnectionHandler::HandleShillConnectSuccess(
+void NetworkConnectionHandlerImpl::HandleShillConnectSuccess(
const std::string& service_path) {
ConnectRequest* request = GetPendingRequest(service_path);
if (!request) {
@@ -706,7 +645,7 @@ void NetworkConnectionHandler::HandleShillConnectSuccess(
CheckPendingRequest(service_path);
}
-void NetworkConnectionHandler::HandleShillConnectFailure(
+void NetworkConnectionHandlerImpl::HandleShillConnectFailure(
const std::string& service_path,
const std::string& dbus_error_name,
const std::string& dbus_error_message) {
@@ -731,7 +670,7 @@ void NetworkConnectionHandler::HandleShillConnectFailure(
InvokeConnectErrorCallback(service_path, error_callback, error);
}
-void NetworkConnectionHandler::CheckPendingRequest(
+void NetworkConnectionHandlerImpl::CheckPendingRequest(
const std::string service_path) {
ConnectRequest* request = GetPendingRequest(service_path);
DCHECK(request);
@@ -750,8 +689,7 @@ void NetworkConnectionHandler::CheckPendingRequest(
if (!request->profile_path.empty()) {
// If a profile path was specified, set it on a successful connection.
configuration_handler_->SetNetworkProfile(
- service_path,
- request->profile_path,
+ service_path, request->profile_path,
NetworkConfigurationObserver::SOURCE_USER_ACTION,
base::Bind(&base::DoNothing),
chromeos::network_handler::ErrorCallback());
@@ -786,26 +724,17 @@ void NetworkConnectionHandler::CheckPendingRequest(
InvokeConnectErrorCallback(service_path, error_callback, error_name);
}
-void NetworkConnectionHandler::CheckAllPendingRequests() {
+void NetworkConnectionHandlerImpl::CheckAllPendingRequests() {
for (std::map<std::string, ConnectRequest>::iterator iter =
- pending_requests_.begin(); iter != pending_requests_.end(); ++iter) {
+ pending_requests_.begin();
+ iter != pending_requests_.end(); ++iter) {
CheckPendingRequest(iter->first);
}
}
// Connect callbacks
-void NetworkConnectionHandler::InvokeConnectSuccessCallback(
- const std::string& service_path,
- const base::Closure& success_callback) {
- NET_LOG_EVENT("Connect Request Succeeded", service_path);
- if (!success_callback.is_null())
- success_callback.Run();
- for (auto& observer : observers_)
- observer.ConnectSucceeded(service_path);
-}
-
-void NetworkConnectionHandler::ErrorCallbackForPendingRequest(
+void NetworkConnectionHandlerImpl::ErrorCallbackForPendingRequest(
const std::string& service_path,
const std::string& error_name) {
ConnectRequest* request = GetPendingRequest(service_path);
@@ -820,33 +749,22 @@ void NetworkConnectionHandler::ErrorCallbackForPendingRequest(
InvokeConnectErrorCallback(service_path, error_callback, error_name);
}
-void NetworkConnectionHandler::InvokeConnectErrorCallback(
- const std::string& service_path,
- const network_handler::ErrorCallback& error_callback,
- const std::string& error_name) {
- NET_LOG_ERROR("Connect Failure: " + error_name, service_path);
- network_handler::RunErrorCallback(error_callback, service_path, error_name,
- "");
- for (auto& observer : observers_)
- observer.ConnectFailed(service_path, error_name);
-}
-
// Disconnect
-void NetworkConnectionHandler::CallShillDisconnect(
+void NetworkConnectionHandlerImpl::CallShillDisconnect(
const std::string& service_path,
const base::Closure& success_callback,
const network_handler::ErrorCallback& error_callback) {
NET_LOG_USER("Disconnect Request", service_path);
DBusThreadManager::Get()->GetShillServiceClient()->Disconnect(
dbus::ObjectPath(service_path),
- base::Bind(&NetworkConnectionHandler::HandleShillDisconnectSuccess,
+ base::Bind(&NetworkConnectionHandlerImpl::HandleShillDisconnectSuccess,
AsWeakPtr(), service_path, success_callback),
base::Bind(&network_handler::ShillErrorCallbackFunction,
kErrorDisconnectFailed, service_path, error_callback));
}
-void NetworkConnectionHandler::HandleShillDisconnectSuccess(
+void NetworkConnectionHandlerImpl::HandleShillDisconnectSuccess(
const std::string& service_path,
const base::Closure& success_callback) {
NET_LOG_EVENT("Disconnect Request Sent", service_path);
« no previous file with comments | « chromeos/network/network_connection_handler_impl.h ('k') | chromeos/network/network_connection_handler_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698