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