Commit 1ee14a25 authored by gspencer@chromium.org's avatar gspencer@chromium.org

This adds Cros API for calling the "Refresh" function on shill's

IPConfig interface.

BUG=chromium-os:33223,chromium:129052
TEST=built and tested with another in-process CL that will use it.


Review URL: https://chromiumcodereview.appspot.com/10824242

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150921 0039d316-1c4b-4281-b951-d872f2087c98
parent 97dfa13b
......@@ -680,6 +680,12 @@ bool CrosRemoveIPConfig(const std::string& ipconfig_path) {
CallRemoveAndBlock(dbus::ObjectPath(ipconfig_path));
}
void CrosRequestIPConfigRefresh(const std::string& ipconfig_path) {
DBusThreadManager::Get()->GetFlimflamIPConfigClient()->Refresh(
dbus::ObjectPath(ipconfig_path),
base::Bind(&DoNothing));
}
bool CrosGetWifiAccessPoints(WifiAccessPointVector* result) {
scoped_ptr<base::DictionaryValue> manager_properties(
DBusThreadManager::Get()->GetFlimflamManagerClient()->
......
......@@ -278,6 +278,10 @@ bool CrosAddIPConfig(const std::string& device_path, IPConfigType type);
// Removes an existing IP Config
bool CrosRemoveIPConfig(const std::string& ipconfig_path);
// Refreshes the IP config |ipconfig_path| to pick up changes in
// configuration, and renew the DHCP lease, if any.
void CrosRequestIPConfigRefresh(const std::string& ipconfig_path);
// Reads out the results of the last wifi scan. These results are not
// pre-cached in the library, so the call may block whilst the results are
// read over IPC.
......
......@@ -119,6 +119,7 @@ class MockNetworkLibrary : public NetworkLibrary {
MOCK_CONST_METHOD1(HasProfileType, bool(NetworkProfileType));
MOCK_METHOD1(GetWifiAccessPoints, bool(WifiAccessPointVector*));
MOCK_CONST_METHOD1(CanConnectToNetwork, bool(const Network*));
MOCK_METHOD1(RefreshIPConfig, void(Network*));
MOCK_METHOD1(ConnectToWifiNetwork, void(WifiNetwork*));
MOCK_METHOD2(ConnectToWifiNetwork, void(WifiNetwork*, bool));
MOCK_METHOD1(ConnectToWimaxNetwork, void(WimaxNetwork*));
......
......@@ -1558,6 +1558,10 @@ class NetworkLibrary {
// user input (e.g. it requires a user profile but none is available).
virtual bool CanConnectToNetwork(const Network* network) const = 0;
// Refresh the IP configuration of the given network after changes. Puts
// newly configured properties into effect and renews DHCP lease.
virtual void RefreshIPConfig(Network* network) = 0;
// Connect to the specified wireless network.
virtual void ConnectToWifiNetwork(WifiNetwork* network) = 0;
......
......@@ -5,9 +5,11 @@
#include "chrome/browser/chromeos/cros/network_library_impl_cros.h"
#include <dbus/dbus-glib.h>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/json/json_writer.h" // for debug output only.
#include "base/metrics/histogram.h"
#include "base/values.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/native_network_constants.h"
#include "chrome/browser/chromeos/cros/native_network_parser.h"
......@@ -456,6 +458,30 @@ bool NetworkLibraryImplCros::GetWifiAccessPoints(
return CrosGetWifiAccessPoints(result);
}
void NetworkLibraryImplCros::RefreshIPConfig(Network* network) {
DCHECK(network);
CrosRequestNetworkDeviceProperties(
network->device_path(),
base::Bind(&NetworkLibraryImplCros::RefreshIPConfigCallback,
weak_ptr_factory_.GetWeakPtr()));
}
void NetworkLibraryImplCros::RefreshIPConfigCallback(
const std::string& device_path,
const base::DictionaryValue* properties) {
const ListValue* ips = NULL;
if (!properties->GetListWithoutPathExpansion(
flimflam::kIPConfigsProperty, &ips))
return;
for (size_t i = 0; i < ips->GetSize(); i++) {
std::string ipconfig_path;
if (!ips->GetString(i, &ipconfig_path))
continue;
CrosRequestIPConfigRefresh(ipconfig_path);
}
}
void NetworkLibraryImplCros::DisconnectFromNetwork(const Network* network) {
DCHECK(network);
// Asynchronous disconnect request. Network state will be updated through
......
......@@ -60,6 +60,8 @@ class NetworkLibraryImplCros : public NetworkLibraryImplBase {
virtual void RequestNetworkScan() OVERRIDE;
virtual bool GetWifiAccessPoints(WifiAccessPointVector* result) OVERRIDE;
virtual void RefreshIPConfig(Network* network) OVERRIDE;
virtual void DisconnectFromNetwork(const Network* network) OVERRIDE;
virtual void CallEnableNetworkDeviceType(
ConnectionType device, bool enable) OVERRIDE;
......@@ -74,7 +76,7 @@ class NetworkLibraryImplCros : public NetworkLibraryImplBase {
virtual void SetIPConfig(const NetworkIPConfig& ipconfig) OVERRIDE;
//////////////////////////////////////////////////////////////////////////////
// Calbacks.
// Callbacks.
void UpdateNetworkStatus(
const std::string& path, const std::string& key, const Value& value);
......@@ -114,6 +116,11 @@ class NetworkLibraryImplCros : public NetworkLibraryImplBase {
void NetworkDeviceUpdate(const std::string& device_path,
const base::DictionaryValue* properties);
// Second half of refreshing IPConfig for a network. Refreshes all IP config
// paths found in properties.
void RefreshIPConfigCallback(const std::string& device_path,
const base::DictionaryValue* properties);
private:
// This processes all Manager update messages.
bool NetworkManagerStatusChanged(const std::string& key, const Value* value);
......
......@@ -641,6 +641,9 @@ bool NetworkLibraryImplStub::GetWifiAccessPoints(
return true;
}
void NetworkLibraryImplStub::RefreshIPConfig(Network* network) {
}
void NetworkLibraryImplStub::DisconnectFromNetwork(const Network* network) {
// Update the network state here since no network manager in stub impl.
Network* modify_network = const_cast<Network*>(network);
......
......@@ -67,6 +67,8 @@ class NetworkLibraryImplStub : public NetworkLibraryImplBase {
virtual bool GetWifiAccessPoints(WifiAccessPointVector* result) OVERRIDE;
virtual void RefreshIPConfig(Network* network) OVERRIDE;
virtual void DisconnectFromNetwork(const Network* network) OVERRIDE;
virtual void EnableOfflineMode(bool enable) OVERRIDE;
......
......@@ -27,20 +27,19 @@ class FlimflamDeviceClientImpl : public FlimflamDeviceClient {
helpers_deleter_(&helpers_) {
}
// FlimflamProfileClient override.
///////////////////////////////////////
// FlimflamDeviceClient overrides.
virtual void SetPropertyChangedHandler(
const dbus::ObjectPath& device_path,
const PropertyChangedHandler& handler) OVERRIDE {
GetHelper(device_path)->SetPropertyChangedHandler(handler);
}
// FlimflamProfileClient override.
virtual void ResetPropertyChangedHandler(
const dbus::ObjectPath& device_path) OVERRIDE {
GetHelper(device_path)->ResetPropertyChangedHandler();
}
// FlimflamProfileClient override.
virtual void GetProperties(const dbus::ObjectPath& device_path,
const DictionaryValueCallback& callback) OVERRIDE {
dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
......@@ -48,7 +47,6 @@ class FlimflamDeviceClientImpl : public FlimflamDeviceClient {
GetHelper(device_path)->CallDictionaryValueMethod(&method_call, callback);
}
// FlimflamProfileClient override.
virtual base::DictionaryValue* CallGetPropertiesAndBlock(
const dbus::ObjectPath& device_path) OVERRIDE {
dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
......@@ -57,7 +55,6 @@ class FlimflamDeviceClientImpl : public FlimflamDeviceClient {
&method_call);
}
// FlimflamProfileClient override.
virtual void ProposeScan(const dbus::ObjectPath& device_path,
const VoidDBusMethodCallback& callback) OVERRIDE {
dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
......@@ -65,7 +62,6 @@ class FlimflamDeviceClientImpl : public FlimflamDeviceClient {
GetHelper(device_path)->CallVoidMethod(&method_call, callback);
}
// FlimflamProfileClient override.
virtual void SetProperty(const dbus::ObjectPath& device_path,
const std::string& name,
const base::Value& value,
......@@ -78,7 +74,6 @@ class FlimflamDeviceClientImpl : public FlimflamDeviceClient {
GetHelper(device_path)->CallVoidMethod(&method_call, callback);
}
// FlimflamProfileClient override.
virtual void ClearProperty(const dbus::ObjectPath& device_path,
const std::string& name,
const VoidDBusMethodCallback& callback) OVERRIDE {
......@@ -89,7 +84,6 @@ class FlimflamDeviceClientImpl : public FlimflamDeviceClient {
GetHelper(device_path)->CallVoidMethod(&method_call, callback);
}
// FlimflamProfileClient override.
virtual void AddIPConfig(
const dbus::ObjectPath& device_path,
const std::string& method,
......@@ -101,7 +95,6 @@ class FlimflamDeviceClientImpl : public FlimflamDeviceClient {
GetHelper(device_path)->CallObjectPathMethod(&method_call, callback);
}
// FlimflamProfileClient override.
virtual dbus::ObjectPath CallAddIPConfigAndBlock(
const dbus::ObjectPath& device_path,
const std::string& method) OVERRIDE {
......@@ -112,7 +105,6 @@ class FlimflamDeviceClientImpl : public FlimflamDeviceClient {
return GetHelper(device_path)->CallObjectPathMethodAndBlock(&method_call);
}
// FlimflamProfileClient override.
virtual void RequirePin(const dbus::ObjectPath& device_path,
const std::string& pin,
bool require,
......@@ -127,7 +119,6 @@ class FlimflamDeviceClientImpl : public FlimflamDeviceClient {
&method_call, callback, error_callback);
}
// FlimflamProfileClient override.
virtual void EnterPin(const dbus::ObjectPath& device_path,
const std::string& pin,
const base::Closure& callback,
......@@ -140,7 +131,6 @@ class FlimflamDeviceClientImpl : public FlimflamDeviceClient {
&method_call, callback, error_callback);
}
// FlimflamProfileClient override.
virtual void UnblockPin(const dbus::ObjectPath& device_path,
const std::string& puk,
const std::string& pin,
......@@ -155,7 +145,6 @@ class FlimflamDeviceClientImpl : public FlimflamDeviceClient {
&method_call, callback, error_callback);
}
// FlimflamProfileClient override.
virtual void ChangePin(const dbus::ObjectPath& device_path,
const std::string& old_pin,
const std::string& new_pin,
......@@ -170,7 +159,6 @@ class FlimflamDeviceClientImpl : public FlimflamDeviceClient {
&method_call, callback, error_callback);
}
// FlimflamProfileClient override.
virtual void Register(const dbus::ObjectPath& device_path,
const std::string& network_id,
const base::Closure& callback,
......
......@@ -30,6 +30,8 @@ class FlimflamIPConfigClientImpl : public FlimflamIPConfigClient {
const PropertyChangedHandler& handler) OVERRIDE;
virtual void ResetPropertyChangedHandler(
const dbus::ObjectPath& ipconfig_path) OVERRIDE;
virtual void Refresh(const dbus::ObjectPath& ipconfig_path,
const VoidDBusMethodCallback& callback) OVERRIDE;
virtual void GetProperties(const dbus::ObjectPath& ipconfig_path,
const DictionaryValueCallback& callback) OVERRIDE;
virtual base::DictionaryValue* CallGetPropertiesAndBlock(
......@@ -103,6 +105,14 @@ base::DictionaryValue* FlimflamIPConfigClientImpl::CallGetPropertiesAndBlock(
&method_call);
}
void FlimflamIPConfigClientImpl::Refresh(
const dbus::ObjectPath& ipconfig_path,
const VoidDBusMethodCallback& callback) {
dbus::MethodCall method_call(flimflam::kFlimflamIPConfigInterface,
shill::kRefreshFunction);
GetHelper(ipconfig_path)->CallVoidMethod(&method_call, callback);
}
void FlimflamIPConfigClientImpl::SetProperty(
const dbus::ObjectPath& ipconfig_path,
const std::string& name,
......@@ -178,16 +188,18 @@ class FlimflamIPConfigClientStubImpl : public FlimflamIPConfigClient {
virtual ~FlimflamIPConfigClientStubImpl() {}
// FlimflamIPConfigClient override.
///////////////////////////////////////////////
// FlimflamIPConfigClient overrides:
virtual void SetPropertyChangedHandler(
const dbus::ObjectPath& ipconfig_path,
const PropertyChangedHandler& handler) OVERRIDE {}
// FlimflamIPConfigClient override.
virtual void ResetPropertyChangedHandler(
const dbus::ObjectPath& ipconfig_path) OVERRIDE {}
// FlimflamIPConfigClient override.
virtual void Refresh(const dbus::ObjectPath& ipconfig_path,
const VoidDBusMethodCallback& callback) OVERRIDE {}
virtual void GetProperties(const dbus::ObjectPath& ipconfig_path,
const DictionaryValueCallback& callback) OVERRIDE {
MessageLoop::current()->PostTask(
......@@ -196,13 +208,11 @@ class FlimflamIPConfigClientStubImpl : public FlimflamIPConfigClient {
callback));
}
// FlimflamIPConfigClient override.
virtual base::DictionaryValue* CallGetPropertiesAndBlock(
const dbus::ObjectPath& ipconfig_path) OVERRIDE {
return new base::DictionaryValue;
}
// FlimflamIPConfigClient override.
virtual void SetProperty(const dbus::ObjectPath& ipconfig_path,
const std::string& name,
const base::Value& value,
......@@ -211,7 +221,6 @@ class FlimflamIPConfigClientStubImpl : public FlimflamIPConfigClient {
FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS));
}
// FlimflamIPConfigClient override.
virtual void ClearProperty(const dbus::ObjectPath& ipconfig_path,
const std::string& name,
const VoidDBusMethodCallback& callback) OVERRIDE {
......@@ -219,14 +228,12 @@ class FlimflamIPConfigClientStubImpl : public FlimflamIPConfigClient {
FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS));
}
// FlimflamIPConfigClient override.
virtual void Remove(const dbus::ObjectPath& ipconfig_path,
const VoidDBusMethodCallback& callback) OVERRIDE {
MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS));
}
// FlimflamIPConfigClient override.
virtual bool CallRemoveAndBlock(
const dbus::ObjectPath& ipconfig_path) OVERRIDE {
return true;
......
......@@ -52,6 +52,11 @@ class CHROMEOS_EXPORT FlimflamIPConfigClient {
virtual void ResetPropertyChangedHandler(
const dbus::ObjectPath& ipconfig_path) = 0;
// Refreshes the active IP configuration after service property changes and
// renews the DHCP lease, if any.
virtual void Refresh(const dbus::ObjectPath& ipconfig_path,
const VoidDBusMethodCallback& callback) = 0;
// Calls GetProperties method.
// |callback| is called after the method call succeeds.
virtual void GetProperties(const dbus::ObjectPath& ipconfig_path,
......
......@@ -22,6 +22,8 @@ class MockFlimflamIPConfigClient : public FlimflamIPConfigClient {
const PropertyChangedHandler& handler));
MOCK_METHOD1(ResetPropertyChangedHandler,
void(const dbus::ObjectPath& ipconfig_path));
MOCK_METHOD2(Refresh, void(const dbus::ObjectPath& ipconfig_path,
const VoidDBusMethodCallback& callback));
MOCK_METHOD2(GetProperties, void(const dbus::ObjectPath& ipconfig_path,
const DictionaryValueCallback& callback));
MOCK_METHOD1(CallGetPropertiesAndBlock,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment