Skip to content

Commit

Permalink
This converts the Shill clients to allow propagation of shill errors
Browse files Browse the repository at this point in the history
back from the function calls.  The existing implentation completely ignores most shill errors, and the javascript implementation will want to be able to receive them to aid in diagnosis.

BUG=chromium:147620,chromium:146616
TEST=Ran unit tests, ran on device.


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@159325 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
gspencer@chromium.org committed Sep 28, 2012
1 parent 2a74ed6 commit d690ba4
Show file tree
Hide file tree
Showing 23 changed files with 523 additions and 207 deletions.
99 changes: 71 additions & 28 deletions chrome/browser/chromeos/cros/cros_network_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/cros/cros_network_functions.h"

#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_tokenizer.h"
#include "base/stringprintf.h"
Expand All @@ -22,6 +23,8 @@
#include "dbus/object_path.h"
#include "third_party/cros_system_api/dbus/service_constants.h"

using base::DoNothing;

namespace chromeos {

namespace {
Expand Down Expand Up @@ -209,7 +212,11 @@ class DataPlanUpdateWatcher : public CrosNetworkWatcher {
};

// Does nothing. Used as a callback.
void DoNothing(DBusMethodCallStatus call_status) {}
void DoNothingWithCallStatus(DBusMethodCallStatus call_status) {}

// Ignores errors.
void IgnoreErrors(const std::string& error_name,
const std::string& error_message) {}

// A callback used to implement CrosRequest*Properties functions.
void RunCallbackWithDictionaryValue(const NetworkPropertiesCallback& callback,
Expand All @@ -219,17 +226,32 @@ void RunCallbackWithDictionaryValue(const NetworkPropertiesCallback& callback,
callback.Run(path, call_status == DBUS_METHOD_CALL_SUCCESS ? &value : NULL);
}

// A callback used to implement CrosRequest*Properties functions.
void RunCallbackWithDictionaryValueNoStatus(
const NetworkPropertiesCallback& callback,
const std::string& path,
const base::DictionaryValue& value) {
callback.Run(path, &value);
}

// A callback used to implement the error callback for CrosRequest*Properties
// functions.
void RunCallbackWithDictionaryValueError(
const NetworkPropertiesCallback& callback,
const std::string& path,
const std::string& error_name,
const std::string& error_message) {
callback.Run(path, NULL);
}

// Used as a callback for ShillManagerClient::GetService
void OnGetService(const NetworkPropertiesCallback& callback,
DBusMethodCallStatus call_status,
const dbus::ObjectPath& service_path) {
if (call_status == DBUS_METHOD_CALL_SUCCESS) {
VLOG(1) << "OnGetServiceService: " << service_path.value();
DBusThreadManager::Get()->GetShillServiceClient()->GetProperties(
service_path, base::Bind(&RunCallbackWithDictionaryValue,
callback,
service_path.value()));
}
VLOG(1) << "OnGetServiceService: " << service_path.value();
DBusThreadManager::Get()->GetShillServiceClient()->GetProperties(
service_path, base::Bind(&RunCallbackWithDictionaryValue,
callback,
service_path.value()));
}

// A callback used to call a NetworkOperationCallback on error.
Expand Down Expand Up @@ -345,40 +367,47 @@ void CrosSetNetworkServiceProperty(const std::string& service_path,
const base::Value& value) {
DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
dbus::ObjectPath(service_path), property, value,
base::Bind(&DoNothing));
base::Bind(&DoNothing),
base::Bind(&IgnoreErrors));
}

void CrosClearNetworkServiceProperty(const std::string& service_path,
const std::string& property) {
DBusThreadManager::Get()->GetShillServiceClient()->ClearProperty(
dbus::ObjectPath(service_path), property, base::Bind(&DoNothing));
dbus::ObjectPath(service_path), property, base::Bind(&DoNothing),
base::Bind(&IgnoreErrors));
}

void CrosSetNetworkDeviceProperty(const std::string& device_path,
const std::string& property,
const base::Value& value) {
DBusThreadManager::Get()->GetShillDeviceClient()->SetProperty(
dbus::ObjectPath(device_path), property, value, base::Bind(&DoNothing));
dbus::ObjectPath(device_path), property, value, base::Bind(&DoNothing),
base::Bind(&IgnoreErrors));
}

void CrosSetNetworkIPConfigProperty(const std::string& ipconfig_path,
const std::string& property,
const base::Value& value) {
DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty(
dbus::ObjectPath(ipconfig_path), property, value,
base::Bind(&DoNothing));
base::Bind(&DoNothingWithCallStatus));
}

void CrosSetNetworkManagerProperty(const std::string& property,
const base::Value& value) {
DBusThreadManager::Get()->GetShillManagerClient()->SetProperty(
property, value, base::Bind(&DoNothing));
property, value, base::Bind(&DoNothing),
base::Bind(&IgnoreErrors));
}

void CrosDeleteServiceFromProfile(const std::string& profile_path,
const std::string& service_path) {
DBusThreadManager::Get()->GetShillProfileClient()->DeleteEntry(
dbus::ObjectPath(profile_path), service_path, base::Bind(&DoNothing));
dbus::ObjectPath(profile_path),
service_path,
base::Bind(&DoNothing),
base::Bind(&IgnoreErrors));
}

void CrosRequestCellularDataPlanUpdate(const std::string& modem_service_path) {
Expand Down Expand Up @@ -452,7 +481,9 @@ void CrosRequestNetworkProfileProperties(
const NetworkPropertiesCallback& callback) {
DBusThreadManager::Get()->GetShillProfileClient()->GetProperties(
dbus::ObjectPath(profile_path),
base::Bind(&RunCallbackWithDictionaryValue, callback, profile_path));
base::Bind(&RunCallbackWithDictionaryValueNoStatus,
callback, profile_path),
base::Bind(&RunCallbackWithDictionaryValueError, callback, profile_path));
}

void CrosRequestNetworkProfileEntryProperties(
Expand All @@ -462,7 +493,10 @@ void CrosRequestNetworkProfileEntryProperties(
DBusThreadManager::Get()->GetShillProfileClient()->GetEntry(
dbus::ObjectPath(profile_path),
profile_entry_path,
base::Bind(&RunCallbackWithDictionaryValue,
base::Bind(&RunCallbackWithDictionaryValueNoStatus,
callback,
profile_entry_path),
base::Bind(&RunCallbackWithDictionaryValueError,
callback,
profile_entry_path));
}
Expand All @@ -488,7 +522,8 @@ void CrosRequestHiddenWifiNetworkProperties(
// |properties| and return a new or existing service to OnGetService().
// OnGetService will then call GetProperties which will then call callback.
DBusThreadManager::Get()->GetShillManagerClient()->GetService(
properties, base::Bind(&OnGetService, callback));
properties, base::Bind(&OnGetService, callback),
base::Bind(&IgnoreErrors));
}

void CrosRequestVirtualNetworkProperties(
Expand Down Expand Up @@ -518,32 +553,38 @@ void CrosRequestVirtualNetworkProperties(
// |properties| and pass a new or existing service to OnGetService().
// OnGetService will then call GetProperties which will then call callback.
DBusThreadManager::Get()->GetShillManagerClient()->GetService(
properties, base::Bind(&OnGetService, callback));
properties, base::Bind(&OnGetService, callback),
base::Bind(&IgnoreErrors));
}

void CrosRequestNetworkServiceDisconnect(const std::string& service_path) {
DBusThreadManager::Get()->GetShillServiceClient()->Disconnect(
dbus::ObjectPath(service_path), base::Bind(&DoNothing));
dbus::ObjectPath(service_path), base::Bind(&DoNothing),
base::Bind(&IgnoreErrors));
}

void CrosRequestRemoveNetworkService(const std::string& service_path) {
DBusThreadManager::Get()->GetShillServiceClient()->Remove(
dbus::ObjectPath(service_path), base::Bind(&DoNothing));
dbus::ObjectPath(service_path), base::Bind(&DoNothing),
base::Bind(&IgnoreErrors));
}

void CrosRequestNetworkScan(const std::string& network_type) {
DBusThreadManager::Get()->GetShillManagerClient()->RequestScan(
network_type, base::Bind(&DoNothing));
network_type, base::Bind(&DoNothing),
base::Bind(&IgnoreErrors));
}

void CrosRequestNetworkDeviceEnable(const std::string& network_type,
bool enable) {
if (enable) {
DBusThreadManager::Get()->GetShillManagerClient()->EnableTechnology(
network_type, base::Bind(&DoNothing));
network_type, base::Bind(&DoNothing),
base::Bind(&IgnoreErrors));
} else {
DBusThreadManager::Get()->GetShillManagerClient()->DisableTechnology(
network_type, base::Bind(&DoNothing));
network_type, base::Bind(&DoNothing),
base::Bind(&IgnoreErrors));
}
}

Expand Down Expand Up @@ -592,7 +633,7 @@ void CrosRequestChangePin(const std::string& device_path,

void CrosProposeScan(const std::string& device_path) {
DBusThreadManager::Get()->GetShillDeviceClient()->ProposeScan(
dbus::ObjectPath(device_path), base::Bind(&DoNothing));
dbus::ObjectPath(device_path), base::Bind(&DoNothingWithCallStatus));
}

void CrosRequestCellularRegister(const std::string& device_path,
Expand All @@ -608,7 +649,8 @@ void CrosRequestCellularRegister(const std::string& device_path,
bool CrosSetOfflineMode(bool offline) {
base::FundamentalValue value(offline);
DBusThreadManager::Get()->GetShillManagerClient()->SetProperty(
flimflam::kOfflineModeProperty, value, base::Bind(&DoNothing));
flimflam::kOfflineModeProperty, value, base::Bind(&DoNothing),
base::Bind(&IgnoreErrors));
return true;
}

Expand Down Expand Up @@ -696,7 +738,7 @@ bool CrosRemoveIPConfig(const std::string& ipconfig_path) {
void CrosRequestIPConfigRefresh(const std::string& ipconfig_path) {
DBusThreadManager::Get()->GetShillIPConfigClient()->Refresh(
dbus::ObjectPath(ipconfig_path),
base::Bind(&DoNothing));
base::Bind(&DoNothingWithCallStatus));
}

bool CrosGetWifiAccessPoints(WifiAccessPointVector* result) {
Expand Down Expand Up @@ -787,7 +829,8 @@ bool CrosGetWifiAccessPoints(WifiAccessPointVector* result) {

void CrosConfigureService(const base::DictionaryValue& properties) {
DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService(
properties, base::Bind(&DoNothing));
properties, base::Bind(&DoNothing),
base::Bind(&IgnoreErrors));
}

std::string CrosPrefixLengthToNetmask(int32 prefix_length) {
Expand Down
Loading

0 comments on commit d690ba4

Please sign in to comment.