Reimplement Libcros fucntions using FlimflamProfileClient

Change FlimflamProfileClient's interface to deal with multiple profile objects
Change FlimflamProfileClient's interface to send an entry's path as a string, not an ObjectPath
Add non-Libcros implementations of CrosDeleteServiceFromProfile, CrosRequestNetworkProfileProperties and CrosRequestNetworkProfileEntryProperties
Add EnableNonLibcrosNetworkFunctions
Add --enable-non-libcros-network-functions commandline option
Rename existing CrosNetworkFunctionsTest to CrosNetworkFunctionsLibcrosTest
Add new CrosNetworkFunctionsTest which tests the non Libcros implementation

BUG=chromium-os:16557
TEST=unit_tests --gtest_filter="CrosNetworkFunctions*"

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132502 0039d316-1c4b-4281-b951-d872f2087c98
parent 8737cec4
......@@ -8,11 +8,17 @@
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "chrome/browser/chromeos/cros/gvalue_util.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/flimflam_profile_client.h"
#include "dbus/object_path.h"
namespace chromeos {
namespace {
// Does nothing. Used as a callback.
void DoNothing(DBusMethodCallStatus call_status) {}
// Callback used by OnRequestNetworkProperties.
typedef base::Callback<void(const char* path,
const base::DictionaryValue* properties)
......@@ -37,8 +43,23 @@ void OnRequestNetworkProperties(void* object,
callback->Run(path, properties_dictionary);
}
// A callback used to implement CrosRequest*Properties functions.
void RunCallbackWithDictionaryValue(const NetworkPropertiesCallback& callback,
const char* path,
DBusMethodCallStatus call_status,
const base::DictionaryValue& value) {
callback.Run(path, call_status == DBUS_METHOD_CALL_SUCCESS ? &value : NULL);
}
// A bool to remember whether we are using Libcros network functions or not.
bool g_libcros_network_functions_enabled = true;
} // namespace
void SetLibcrosNetworkFunctionsEnabled(bool enabled) {
g_libcros_network_functions_enabled = enabled;
}
bool CrosActivateCellularModem(const char* service_path, const char* carrier) {
return chromeos::ActivateCellularModem(service_path, carrier);
}
......@@ -79,7 +100,12 @@ void CrosSetNetworkManagerProperty(const char* property,
void CrosDeleteServiceFromProfile(const char* profile_path,
const char* service_path) {
chromeos::DeleteServiceFromProfile(profile_path, service_path);
if (g_libcros_network_functions_enabled) {
chromeos::DeleteServiceFromProfile(profile_path, service_path);
} else {
DBusThreadManager::Get()->GetFlimflamProfileClient()->DeleteEntry(
dbus::ObjectPath(profile_path), service_path, base::Bind(&DoNothing));
}
}
void CrosRequestCellularDataPlanUpdate(const char* modem_service_path) {
......@@ -170,23 +196,40 @@ void CrosRequestNetworkDeviceProperties(
void CrosRequestNetworkProfileProperties(
const char* profile_path,
const NetworkPropertiesCallback& callback) {
// The newly allocated callback will be deleted in OnRequestNetworkProperties.
chromeos::RequestNetworkProfileProperties(
profile_path,
&OnRequestNetworkProperties,
new OnRequestNetworkPropertiesCallback(callback));
if (g_libcros_network_functions_enabled) {
// The newly allocated callback will be deleted in
// OnRequestNetworkProperties.
chromeos::RequestNetworkProfileProperties(
profile_path,
&OnRequestNetworkProperties,
new OnRequestNetworkPropertiesCallback(callback));
} else {
DBusThreadManager::Get()->GetFlimflamProfileClient()->GetProperties(
dbus::ObjectPath(profile_path),
base::Bind(&RunCallbackWithDictionaryValue, callback, profile_path));
}
}
void CrosRequestNetworkProfileEntryProperties(
const char* profile_path,
const char* profile_entry_path,
const NetworkPropertiesCallback& callback) {
// The newly allocated callback will be deleted in OnRequestNetworkProperties.
chromeos::RequestNetworkProfileEntryProperties(
profile_path,
profile_entry_path,
&OnRequestNetworkProperties,
new OnRequestNetworkPropertiesCallback(callback));
if (g_libcros_network_functions_enabled) {
// The newly allocated callback will be deleted in
// OnRequestNetworkProperties.
chromeos::RequestNetworkProfileEntryProperties(
profile_path,
profile_entry_path,
&OnRequestNetworkProperties,
new OnRequestNetworkPropertiesCallback(callback));
} else {
DBusThreadManager::Get()->GetFlimflamProfileClient()->GetEntry(
dbus::ObjectPath(profile_path),
profile_entry_path,
base::Bind(&RunCallbackWithDictionaryValue,
callback,
profile_entry_path));
}
}
void CrosRequestHiddenWifiNetworkProperties(
......
......@@ -28,6 +28,9 @@ typedef base::Callback<void(
const char* path,
const base::DictionaryValue* properties)> NetworkPropertiesCallback;
// Enables/Disables Libcros network functions.
void SetLibcrosNetworkFunctionsEnabled(bool enabled);
// Activates the cellular modem specified by |service_path| with carrier
// specified by |carrier|.
// |carrier| is NULL or an empty string, this will activate with the currently
......
......@@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/cros/network_library_impl_cros.h"
#include <dbus/dbus-glib.h>
#include "base/command_line.h"
#include "base/json/json_writer.h" // for debug output only.
#include "base/metrics/histogram.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
......@@ -12,6 +13,7 @@
#include "chrome/browser/chromeos/cros/native_network_constants.h"
#include "chrome/browser/chromeos/cros/native_network_parser.h"
#include "chrome/browser/chromeos/cros_settings.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/browser_thread.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
......@@ -44,6 +46,10 @@ NetworkLibraryImplCros::NetworkLibraryImplCros()
: NetworkLibraryImplBase(),
network_manager_monitor_(NULL),
data_plan_monitor_(NULL) {
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableLibcros)) {
LOG(INFO) << "Using non Libcros network fucntions.";
SetLibcrosNetworkFunctionsEnabled(false);
}
}
NetworkLibraryImplCros::~NetworkLibraryImplCros() {
......
......@@ -1205,6 +1205,9 @@ const char kMemoryWidget[] = "memory-widget";
// Disables gdata content provider.
const char kDisableGData[] = "disable-gdata";
// Disables Libcros.
const char kDisableLibcros[] = "disable-libcros";
// Skips OAuth part of ChromeOS login process.
const char kSkipOAuthLogin[] = "skip-oauth-login";
......
......@@ -330,6 +330,7 @@ extern const char kWinHttpProxyResolver[];
#if defined(OS_CHROMEOS)
extern const char kDisableGData[];
extern const char kDisableLibcros[];
extern const char kSkipOAuthLogin[];
extern const char kEnableDevicePolicy[];
extern const char kEnableGView[];
......
......@@ -6,11 +6,11 @@
#include "base/bind.h"
#include "base/message_loop.h"
#include "base/stl_util.h"
#include "base/values.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_path.h"
#include "dbus/object_proxy.h"
#include "dbus/values_util.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
......@@ -25,74 +25,91 @@ class FlimflamProfileClientImpl : public FlimflamProfileClient {
// FlimflamProfileClient overrides:
virtual void SetPropertyChangedHandler(
const dbus::ObjectPath& profile_path,
const PropertyChangedHandler& handler) OVERRIDE;
virtual void ResetPropertyChangedHandler() OVERRIDE;
virtual void GetProperties(const DictionaryValueCallback& callback) OVERRIDE;
virtual void GetEntry(const dbus::ObjectPath& path,
virtual void ResetPropertyChangedHandler(
const dbus::ObjectPath& profile_path) OVERRIDE;
virtual void GetProperties(const dbus::ObjectPath& profile_path,
const DictionaryValueCallback& callback) OVERRIDE;
virtual void GetEntry(const dbus::ObjectPath& profile_path,
const std::string& entry_path,
const DictionaryValueCallback& callback) OVERRIDE;
virtual void DeleteEntry(const dbus::ObjectPath& path,
virtual void DeleteEntry(const dbus::ObjectPath& profile_path,
const std::string& entry_path,
const VoidCallback& callback) OVERRIDE;
private:
// Handles the result of signal connection setup.
void OnSignalConnected(const std::string& interface,
const std::string& signal,
bool success);
// Handles PropertyChanged signal.
void OnPropertyChanged(dbus::Signal* signal);
// Handles responses for methods without results.
void OnVoidMethod(const VoidCallback& callback, dbus::Response* response);
// Handles responses for methods with DictionaryValue results.
void OnDictionaryValueMethod(const DictionaryValueCallback& callback,
dbus::Response* response);
dbus::ObjectProxy* proxy_;
FlimflamClientHelper helper_;
typedef std::map<std::string, FlimflamClientHelper*> HelperMap;
// Returns the corresponding FlimflamClientHelper for the profile.
FlimflamClientHelper* GetHelper(const dbus::ObjectPath& profile_path);
dbus::Bus* bus_;
HelperMap helpers_;
STLValueDeleter<HelperMap> helpers_deleter_;
DISALLOW_COPY_AND_ASSIGN(FlimflamProfileClientImpl);
};
FlimflamProfileClientImpl::FlimflamProfileClientImpl(dbus::Bus* bus)
: proxy_(bus->GetObjectProxy(
flimflam::kFlimflamServiceName,
dbus::ObjectPath(flimflam::kFlimflamServicePath))),
helper_(proxy_) {
helper_.MonitorPropertyChanged(flimflam::kFlimflamProfileInterface);
: bus_(bus),
helpers_deleter_(&helpers_) {
}
FlimflamClientHelper* FlimflamProfileClientImpl::GetHelper(
const dbus::ObjectPath& profile_path) {
HelperMap::iterator it = helpers_.find(profile_path.value());
if (it != helpers_.end())
return it->second;
// There is no helper for the profile, create it.
dbus::ObjectProxy* object_proxy =
bus_->GetObjectProxy(flimflam::kFlimflamServiceName, profile_path);
FlimflamClientHelper* helper = new FlimflamClientHelper(object_proxy);
helper->MonitorPropertyChanged(flimflam::kFlimflamProfileInterface);
helpers_.insert(HelperMap::value_type(profile_path.value(), helper));
return helper;
}
void FlimflamProfileClientImpl::SetPropertyChangedHandler(
const dbus::ObjectPath& profile_path,
const PropertyChangedHandler& handler) {
helper_.SetPropertyChangedHandler(handler);
GetHelper(profile_path)->SetPropertyChangedHandler(handler);
}
void FlimflamProfileClientImpl::ResetPropertyChangedHandler() {
helper_.ResetPropertyChangedHandler();
void FlimflamProfileClientImpl::ResetPropertyChangedHandler(
const dbus::ObjectPath& profile_path) {
GetHelper(profile_path)->ResetPropertyChangedHandler();
}
void FlimflamProfileClientImpl::GetProperties(
const dbus::ObjectPath& profile_path,
const DictionaryValueCallback& callback) {
dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface,
flimflam::kGetPropertiesFunction);
helper_.CallDictionaryValueMethod(&method_call, callback);
GetHelper(profile_path)->CallDictionaryValueMethod(&method_call, callback);
}
void FlimflamProfileClientImpl::GetEntry(
const dbus::ObjectPath& path,
const dbus::ObjectPath& profile_path,
const std::string& entry_path,
const DictionaryValueCallback& callback) {
dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface,
flimflam::kGetEntryFunction);
dbus::MessageWriter writer(&method_call);
writer.AppendObjectPath(path);
helper_.CallDictionaryValueMethod(&method_call, callback);
writer.AppendString(entry_path);
GetHelper(profile_path)->CallDictionaryValueMethod(&method_call, callback);
}
void FlimflamProfileClientImpl::DeleteEntry(const dbus::ObjectPath& path,
const VoidCallback& callback) {
void FlimflamProfileClientImpl::DeleteEntry(
const dbus::ObjectPath& profile_path,
const std::string& entry_path,
const VoidCallback& callback) {
dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface,
flimflam::kDeleteEntryFunction);
dbus::MessageWriter writer(&method_call);
writer.AppendObjectPath(path);
helper_.CallVoidMethod(&method_call, callback);
writer.AppendString(entry_path);
GetHelper(profile_path)->CallVoidMethod(&method_call, callback);
}
// A stub implementation of FlimflamProfileClient.
......@@ -104,13 +121,16 @@ class FlimflamProfileClientStubImpl : public FlimflamProfileClient {
// FlimflamProfileClient override.
virtual void SetPropertyChangedHandler(
const dbus::ObjectPath& profile_path,
const PropertyChangedHandler& handler) OVERRIDE {}
// FlimflamProfileClient override.
virtual void ResetPropertyChangedHandler() OVERRIDE {}
virtual void ResetPropertyChangedHandler(
const dbus::ObjectPath& profile_path) OVERRIDE {}
// FlimflamProfileClient override.
virtual void GetProperties(const DictionaryValueCallback& callback) OVERRIDE {
virtual void GetProperties(const dbus::ObjectPath& profile_path,
const DictionaryValueCallback& callback) OVERRIDE {
MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&FlimflamProfileClientStubImpl::PassEmptyDictionaryValue,
......@@ -119,7 +139,8 @@ class FlimflamProfileClientStubImpl : public FlimflamProfileClient {
}
// FlimflamProfileClient override.
virtual void GetEntry(const dbus::ObjectPath& path,
virtual void GetEntry(const dbus::ObjectPath& profile_path,
const std::string& entry_path,
const DictionaryValueCallback& callback) OVERRIDE {
MessageLoop::current()->PostTask(
FROM_HERE,
......@@ -129,7 +150,8 @@ class FlimflamProfileClientStubImpl : public FlimflamProfileClient {
}
// FlimflamProfileClient override.
virtual void DeleteEntry(const dbus::ObjectPath& path,
virtual void DeleteEntry(const dbus::ObjectPath& profile_path,
const std::string& entry_path,
const VoidCallback& callback) OVERRIDE {
MessageLoop::current()->PostTask(FROM_HERE,
base::Bind(callback,
......
......@@ -47,23 +47,28 @@ class CHROMEOS_EXPORT FlimflamProfileClient {
// Sets PropertyChanged signal handler.
virtual void SetPropertyChangedHandler(
const dbus::ObjectPath& profile_path,
const PropertyChangedHandler& handler) = 0;
// Resets PropertyChanged signal handler.
virtual void ResetPropertyChangedHandler() = 0;
virtual void ResetPropertyChangedHandler(
const dbus::ObjectPath& profile_path) = 0;
// Calls GetProperties method.
// |callback| is called after the method call succeeds.
virtual void GetProperties(const DictionaryValueCallback& callback) = 0;
virtual void GetProperties(const dbus::ObjectPath& profile_path,
const DictionaryValueCallback& callback) = 0;
// Calls GetEntry method.
// |callback| is called after the method call succeeds.
virtual void GetEntry(const dbus::ObjectPath& path,
virtual void GetEntry(const dbus::ObjectPath& profile_path,
const std::string& entry_path,
const DictionaryValueCallback& callback) = 0;
// Calls DeleteEntry method.
// |callback| is called after the method call succeeds.
virtual void DeleteEntry(const dbus::ObjectPath& path,
virtual void DeleteEntry(const dbus::ObjectPath& profile_path,
const std::string& entry_path,
const VoidCallback& callback) = 0;
protected:
......
......@@ -17,13 +17,18 @@ class MockFlimflamProfileClient : public FlimflamProfileClient {
MockFlimflamProfileClient();
virtual ~MockFlimflamProfileClient();
MOCK_METHOD1(SetPropertyChangedHandler,
void(const PropertyChangedHandler& handler));
MOCK_METHOD0(ResetPropertyChangedHandler, void());
MOCK_METHOD1(GetProperties, void(const DictionaryValueCallback& callback));
MOCK_METHOD2(GetEntry, void(const dbus::ObjectPath& path,
MOCK_METHOD2(SetPropertyChangedHandler,
void(const dbus::ObjectPath& profile_path,
const PropertyChangedHandler& handler));
MOCK_METHOD1(ResetPropertyChangedHandler,
void(const dbus::ObjectPath& profile_path));
MOCK_METHOD2(GetProperties, void(const dbus::ObjectPath& profile_path,
const DictionaryValueCallback& callback));
MOCK_METHOD3(GetEntry, void(const dbus::ObjectPath& profile_path,
const std::string& entry_path,
const DictionaryValueCallback& callback));
MOCK_METHOD2(DeleteEntry, void(const dbus::ObjectPath& path,
MOCK_METHOD3(DeleteEntry, void(const dbus::ObjectPath& profile_path,
const std::string& entry_path,
const VoidCallback& callback));
};
......
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