diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-01 21:50:22 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-01 21:50:22 +0000 |
commit | 8617f9894392027da2e5bb91a033e343acae9d34 (patch) | |
tree | a3d2c0aed37649bf74d36739613b772849dfdb2a /chromeos | |
parent | b042ecf69a057ca5ed09540e1a1b6aef28a8ee62 (diff) | |
download | chromium_src-8617f9894392027da2e5bb91a033e343acae9d34.zip chromium_src-8617f9894392027da2e5bb91a033e343acae9d34.tar.gz chromium_src-8617f9894392027da2e5bb91a033e343acae9d34.tar.bz2 |
Add ConnectToBestServices call when Certs are loaded
BUG=137711
Review URL: https://codereview.chromium.org/13004024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191675 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r-- | chromeos/dbus/mock_shill_manager_client.h | 3 | ||||
-rw-r--r-- | chromeos/dbus/shill_manager_client.cc | 27 | ||||
-rw-r--r-- | chromeos/dbus/shill_manager_client.h | 22 | ||||
-rw-r--r-- | chromeos/dbus/shill_manager_client_stub.cc | 4 | ||||
-rw-r--r-- | chromeos/dbus/shill_manager_client_stub.h | 20 | ||||
-rw-r--r-- | chromeos/network/network_state_handler.cc | 54 | ||||
-rw-r--r-- | chromeos/network/network_state_handler.h | 17 | ||||
-rw-r--r-- | chromeos/network/shill_property_handler.cc | 24 | ||||
-rw-r--r-- | chromeos/network/shill_property_handler.h | 9 |
9 files changed, 133 insertions, 47 deletions
diff --git a/chromeos/dbus/mock_shill_manager_client.h b/chromeos/dbus/mock_shill_manager_client.h index 6179168..57f2449 100644 --- a/chromeos/dbus/mock_shill_manager_client.h +++ b/chromeos/dbus/mock_shill_manager_client.h @@ -68,6 +68,9 @@ class MockShillManagerClient : public ShillManagerClient { const std::string& data, const StringCallback& callback, const ErrorCallback& error_callback)); + MOCK_METHOD2(ConnectToBestServices, + void(const base::Closure& callback, + const ErrorCallback& error_callback)); MOCK_METHOD0(GetTestInterface, TestInterface*()); }; diff --git a/chromeos/dbus/shill_manager_client.cc b/chromeos/dbus/shill_manager_client.cc index 04d7bcf..e99a940 100644 --- a/chromeos/dbus/shill_manager_client.cc +++ b/chromeos/dbus/shill_manager_client.cc @@ -212,14 +212,15 @@ class ShillManagerClientImpl : public ShillManagerClient { error_callback); } - virtual void VerifyAndEncryptData(const std::string& certificate, - const std::string& public_key, - const std::string& nonce, - const std::string& signed_data, - const std::string& device_serial, - const std::string& data, - const StringCallback& callback, - const ErrorCallback& error_callback) OVERRIDE { + virtual void VerifyAndEncryptData( + const std::string& certificate, + const std::string& public_key, + const std::string& nonce, + const std::string& signed_data, + const std::string& device_serial, + const std::string& data, + const StringCallback& callback, + const ErrorCallback& error_callback) OVERRIDE { dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, shill::kVerifyAndEncryptDataFunction); dbus::MessageWriter writer(&method_call); @@ -234,6 +235,16 @@ class ShillManagerClientImpl : public ShillManagerClient { error_callback); } + virtual void ConnectToBestServices( + const base::Closure& callback, + const ErrorCallback& error_callback) OVERRIDE { + dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, + shill::kConnectToBestServicesFunction); + helper_.CallVoidMethodWithErrorCallback(&method_call, + callback, + error_callback); + } + virtual TestInterface* GetTestInterface() OVERRIDE { return NULL; } diff --git a/chromeos/dbus/shill_manager_client.h b/chromeos/dbus/shill_manager_client.h index 352614b..bd05253 100644 --- a/chromeos/dbus/shill_manager_client.h +++ b/chromeos/dbus/shill_manager_client.h @@ -156,14 +156,20 @@ class CHROMEOS_EXPORT ShillManagerClient { // Verify that the given data corresponds to a trusted device, and return the // |data| encrypted using the |public_key| for the trusted device. If the // device is not trusted, return the empty string. - virtual void VerifyAndEncryptData(const std::string& certificate, - const std::string& public_key, - const std::string& nonce, - const std::string& signed_data, - const std::string& device_serial, - const std::string& data, - const StringCallback& callback, - const ErrorCallback& error_callback) = 0; + virtual void VerifyAndEncryptData( + const std::string& certificate, + const std::string& public_key, + const std::string& nonce, + const std::string& signed_data, + const std::string& device_serial, + const std::string& data, + const StringCallback& callback, + const ErrorCallback& error_callback) = 0; + + // For each technology present, connect to the "best" service available. + // Called once the user is logged in and certificates are loaded. + virtual void ConnectToBestServices(const base::Closure& callback, + const ErrorCallback& error_callback) = 0; // Returns an interface for testing (stub only), or returns NULL. virtual TestInterface* GetTestInterface() = 0; diff --git a/chromeos/dbus/shill_manager_client_stub.cc b/chromeos/dbus/shill_manager_client_stub.cc index 8681baf..468c727b 100644 --- a/chromeos/dbus/shill_manager_client_stub.cc +++ b/chromeos/dbus/shill_manager_client_stub.cc @@ -254,6 +254,10 @@ void ShillManagerClientStub::VerifyAndEncryptData( FROM_HERE, base::Bind(callback, "encrypted_data")); } +void ShillManagerClientStub::ConnectToBestServices( + const base::Closure& callback, + const ErrorCallback& error_callback) { +} ShillManagerClient::TestInterface* ShillManagerClientStub::GetTestInterface() { return this; diff --git a/chromeos/dbus/shill_manager_client_stub.h b/chromeos/dbus/shill_manager_client_stub.h index 44491be..1eb666d 100644 --- a/chromeos/dbus/shill_manager_client_stub.h +++ b/chromeos/dbus/shill_manager_client_stub.h @@ -70,14 +70,18 @@ class ShillManagerClientStub : public ShillManagerClient, const std::string& service_path, const StringCallback& callback, const ErrorCallback& error_callback) OVERRIDE; - virtual void VerifyAndEncryptData(const std::string& certificate, - const std::string& public_key, - const std::string& nonce, - const std::string& signed_data, - const std::string& device_serial, - const std::string& data, - const StringCallback& callback, - const ErrorCallback& error_callback) OVERRIDE; + virtual void VerifyAndEncryptData( + const std::string& certificate, + const std::string& public_key, + const std::string& nonce, + const std::string& signed_data, + const std::string& device_serial, + const std::string& data, + const StringCallback& callback, + const ErrorCallback& error_callback) OVERRIDE; + virtual void ConnectToBestServices( + const base::Closure& callback, + const ErrorCallback& error_callback) OVERRIDE; virtual ShillManagerClient::TestInterface* GetTestInterface() OVERRIDE; // ShillManagerClient::TestInterface overrides. diff --git a/chromeos/network/network_state_handler.cc b/chromeos/network/network_state_handler.cc index cdcec42..be8696e 100644 --- a/chromeos/network/network_state_handler.cc +++ b/chromeos/network/network_state_handler.cc @@ -4,6 +4,7 @@ #include "chromeos/network/network_state_handler.h" +#include "base/bind.h" #include "base/format_macros.h" #include "base/stl_util.h" #include "base/string_util.h" @@ -297,9 +298,24 @@ void NetworkStateHandler::GetNetworkList(NetworkStateList* list) const { } void NetworkStateHandler::RequestScan() const { + network_event_log::AddEntry(kLogModule, "RequestScan", ""); shill_property_handler_->RequestScan(); } +void NetworkStateHandler::WaitForScan(const std::string& type, + const base::Closure& callback) { + scan_complete_callbacks_[type].push_back(callback); + if (!GetScanningByType(type)) + RequestScan(); +} + +void NetworkStateHandler::ConnectToBestWifiNetwork() { + network_event_log::AddEntry(kLogModule, "ConnectToBestWifiNetwork", ""); + WaitForScan(flimflam::kTypeWifi, + base::Bind(&internal::ShillPropertyHandler::ConnectToBestServices, + shill_property_handler_->AsWeakPtr())); +} + void NetworkStateHandler::SetConnectingNetwork( const std::string& service_path) { connecting_network_ = service_path; @@ -386,6 +402,9 @@ void NetworkStateHandler::UpdateManagedStateProperties( managed->PropertyChanged(iter.key(), iter.value()); } } + network_event_log::AddEntry( + kLogModule, "PropertiesReceived", + base::StringPrintf("%s (%s)", path.c_str(), managed->name().c_str())); // Notify observers. if (network_property_updated) { NetworkState* network = managed->AsNetworkState(); @@ -395,9 +414,6 @@ void NetworkStateHandler::UpdateManagedStateProperties( OnNetworkConnectionStateChanged(network); NetworkPropertiesUpdated(network); } - network_event_log::AddEntry( - kLogModule, "PropertiesReceived", - base::StringPrintf("%s (%s)", path.c_str(), managed->name().c_str())); } void NetworkStateHandler::UpdateNetworkServiceProperty( @@ -410,16 +426,16 @@ void NetworkStateHandler::UpdateNetworkServiceProperty( std::string prev_connection_state = network->connection_state(); if (!network->PropertyChanged(key, value)) return; - if (network->connection_state() != prev_connection_state) - OnNetworkConnectionStateChanged(network); - - NetworkPropertiesUpdated(network); std::string detail = network->name() + "." + key; std::string vstr = ValueAsString(value); if (!vstr.empty()) detail += " = " + vstr; network_event_log::AddEntry(kLogModule, "NetworkPropertyUpdated", detail); + + if (network->connection_state() != prev_connection_state) + OnNetworkConnectionStateChanged(network); + NetworkPropertiesUpdated(network); } void NetworkStateHandler::UpdateNetworkServiceIPAddress( @@ -443,14 +459,17 @@ void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, if (!device->PropertyChanged(key, value)) return; - FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, - DeviceListChanged()); - std::string detail = device->name() + "." + key; std::string vstr = ValueAsString(value); if (!vstr.empty()) detail += " = " + vstr; network_event_log::AddEntry(kLogModule, "DevicePropertyUpdated", detail); + + FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, + DeviceListChanged()); + + if (key == flimflam::kScanningProperty && device->scanning() == false) + ScanCompleted(device->type()); } void NetworkStateHandler::ManagerPropertyChanged() { @@ -575,4 +594,19 @@ void NetworkStateHandler::NetworkPropertiesUpdated( } } +void NetworkStateHandler::ScanCompleted(const std::string& type) { + size_t num_callbacks = scan_complete_callbacks_.count(type); + network_event_log::AddEntry( + kLogModule, "ScanCompleted", + base::StringPrintf("%s: %"PRIuS, type.c_str(), num_callbacks)); + if (num_callbacks == 0) + return; + ScanCallbackList& callback_list = scan_complete_callbacks_[type]; + for (ScanCallbackList::iterator iter = callback_list.begin(); + iter != callback_list.end(); ++iter) { + (*iter).Run(); + } + scan_complete_callbacks_.erase(type); +} + } // namespace chromeos diff --git a/chromeos/network/network_state_handler.h b/chromeos/network/network_state_handler.h index 31d1de6..ce65e0d 100644 --- a/chromeos/network/network_state_handler.h +++ b/chromeos/network/network_state_handler.h @@ -10,6 +10,7 @@ #include <string> #include <vector> +#include "base/callback_forward.h" #include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" #include "base/observer_list.h" @@ -139,6 +140,14 @@ class CHROMEOS_EXPORT NetworkStateHandler // list, which will trigger the appropriate observer calls. void RequestScan() const; + // Request a scan if not scanning and run |callback| when the Scanning state + // for any Device matching |type| completes. + void WaitForScan(const std::string& type, const base::Closure& callback); + + // Request a network scan then signal Shill to connect to the best available + // networks when completed. + void ConnectToBestWifiNetwork(); + // Set the user initiated connecting network. void SetConnectingNetwork(const std::string& service_path); @@ -203,6 +212,8 @@ class CHROMEOS_EXPORT NetworkStateHandler void InitShillPropertyHandler(); private: + typedef std::list<base::Closure> ScanCallbackList; + typedef std::map<std::string, ScanCallbackList> ScanCompleteCallbackMap; friend class NetworkStateHandlerTest; FRIEND_TEST_ALL_PREFIXES(NetworkStateHandlerTest, NetworkStateHandlerStub); @@ -231,6 +242,9 @@ class CHROMEOS_EXPORT NetworkStateHandler // Notifies observers and updates connecting_network_. void NetworkPropertiesUpdated(const NetworkState* network); + // Called whenever Device.Scanning state transitions to false. + void ScanCompleted(const std::string& type); + // Shill property handler instance, owned by this class. scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; @@ -250,6 +264,9 @@ class CHROMEOS_EXPORT NetworkStateHandler // TODO(stevenjb): Move this to NetworkConfigurationHandler. std::string connecting_network_; + // Callbacks to run when a scan for the technology type completes. + ScanCompleteCallbackMap scan_complete_callbacks_; + DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); }; diff --git a/chromeos/network/shill_property_handler.cc b/chromeos/network/shill_property_handler.cc index e3083cd..2041139 100644 --- a/chromeos/network/shill_property_handler.cc +++ b/chromeos/network/shill_property_handler.cc @@ -100,8 +100,7 @@ class ShillPropertyObserver : public ShillPropertyChangedObserver { ShillPropertyHandler::ShillPropertyHandler(Listener* listener) : listener_(listener), - shill_manager_(DBusThreadManager::Get()->GetShillManagerClient()), - weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { + shill_manager_(DBusThreadManager::Get()->GetShillManagerClient()) { } ShillPropertyHandler::~ShillPropertyHandler() { @@ -117,7 +116,7 @@ ShillPropertyHandler::~ShillPropertyHandler() { void ShillPropertyHandler::Init() { shill_manager_->GetProperties( base::Bind(&ShillPropertyHandler::ManagerPropertiesCallback, - weak_ptr_factory_.GetWeakPtr())); + AsWeakPtr())); shill_manager_->AddPropertyChangedObserver(this); } @@ -163,6 +162,14 @@ void ShillPropertyHandler::RequestScan() const { kLogModule, "", network_handler::ErrorCallback())); } +void ShillPropertyHandler::ConnectToBestServices() const { + network_event_log::AddEntry(kLogModule, "ConnectToBestServices", ""); + shill_manager_->ConnectToBestServices( + base::Bind(&base::DoNothing), + base::Bind(&network_handler::ShillErrorCallbackFunction, + kLogModule, "", network_handler::ErrorCallback())); +} + void ShillPropertyHandler::RequestProperties(ManagedState::ManagedType type, const std::string& path) { if (pending_updates_[type].find(path) != pending_updates_[type].end()) @@ -173,12 +180,12 @@ void ShillPropertyHandler::RequestProperties(ManagedState::ManagedType type, DBusThreadManager::Get()->GetShillServiceClient()->GetProperties( dbus::ObjectPath(path), base::Bind(&ShillPropertyHandler::GetPropertiesCallback, - weak_ptr_factory_.GetWeakPtr(), type, path)); + AsWeakPtr(), type, path)); } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { DBusThreadManager::Get()->GetShillDeviceClient()->GetProperties( dbus::ObjectPath(path), base::Bind(&ShillPropertyHandler::GetPropertiesCallback, - weak_ptr_factory_.GetWeakPtr(), type, path)); + AsWeakPtr(), type, path)); } else { NOTREACHED(); } @@ -297,8 +304,7 @@ void ShillPropertyHandler::UpdateObserved(ManagedState::ManagedType type, // Create an observer for future updates. new_observed[path] = new ShillPropertyObserver( type, path, base::Bind( - &ShillPropertyHandler::PropertyChangedCallback, - weak_ptr_factory_.GetWeakPtr())); + &ShillPropertyHandler::PropertyChangedCallback, AsWeakPtr())); network_event_log::AddEntry(kLogModule, "StartObserving", path); } observer_map.erase(path); @@ -382,7 +388,7 @@ void ShillPropertyHandler::GetPropertiesCallback( DBusThreadManager::Get()->GetShillIPConfigClient()->GetProperties( dbus::ObjectPath(ip_config_path), base::Bind(&ShillPropertyHandler::GetIPConfigCallback, - weak_ptr_factory_.GetWeakPtr(), path)); + AsWeakPtr(), path)); } } @@ -417,7 +423,7 @@ void ShillPropertyHandler::NetworkServicePropertyChangedCallback( DBusThreadManager::Get()->GetShillIPConfigClient()->GetProperties( dbus::ObjectPath(ip_config_path), base::Bind(&ShillPropertyHandler::GetIPConfigCallback, - weak_ptr_factory_.GetWeakPtr(), path)); + AsWeakPtr(), path)); } else { listener_->UpdateNetworkServiceProperty(path, key, value); } diff --git a/chromeos/network/shill_property_handler.h b/chromeos/network/shill_property_handler.h index 66678ac..154a656 100644 --- a/chromeos/network/shill_property_handler.h +++ b/chromeos/network/shill_property_handler.h @@ -38,7 +38,8 @@ class ShillPropertyObserver; // It also observes Shill.Service for all services in Manager.ServiceWatchList. // This class must not outlive the ShillManagerClient instance. class CHROMEOS_EXPORT ShillPropertyHandler - : public ShillPropertyChangedObserver { + : public ShillPropertyChangedObserver, + public base::SupportsWeakPtr<ShillPropertyHandler> { public: typedef std::map<std::string, ShillPropertyObserver*> ShillPropertyObserverMap; @@ -107,6 +108,9 @@ class CHROMEOS_EXPORT ShillPropertyHandler // Requests an immediate network scan. void RequestScan() const; + // Calls Manager.ConnectToBestServices(). + void ConnectToBestServices() const; + // Requests all properties for the service or device (called for new items). void RequestProperties(ManagedState::ManagedType type, const std::string& path); @@ -184,9 +188,6 @@ class CHROMEOS_EXPORT ShillPropertyHandler std::set<std::string> enabled_technologies_; std::set<std::string> uninitialized_technologies_; - // For Shill client callbacks - base::WeakPtrFactory<ShillPropertyHandler> weak_ptr_factory_; - DISALLOW_COPY_AND_ASSIGN(ShillPropertyHandler); }; |