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
......
......@@ -8,6 +8,8 @@
#include "chrome/browser/chromeos/cros/cros_network_functions.h"
#include "chrome/browser/chromeos/cros/gvalue_util.h"
#include "chrome/browser/chromeos/cros/mock_chromeos_network.h"
#include "chromeos/dbus/mock_dbus_thread_manager.h"
#include "chromeos/dbus/mock_flimflam_profile_client.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::_;
......@@ -19,23 +21,50 @@ namespace {
const char kExamplePath[] = "/foo/bar/baz";
// Expects path and a dictionary value result.
void ExpectPathAndDictionaryValue(const base::DictionaryValue* expected,
const char* path,
const base::DictionaryValue* result) {
EXPECT_STREQ(kExamplePath, path);
EXPECT_TRUE(expected->Equals(result));
}
// A mock to check arguments of NetworkPropertiesCallback and ensure that the
// callback is called exactly once.
class MockNetworkPropertiesCallback {
public:
// Creates a NetworkPropertiesCallback with expectations.
static NetworkPropertiesCallback CreateCallback(
const char* expected_path,
const base::DictionaryValue& expected_result) {
MockNetworkPropertiesCallback* mock_callback =
new MockNetworkPropertiesCallback(expected_result);
EXPECT_CALL(*mock_callback, Run(expected_path, _)).WillOnce(
Invoke(mock_callback, &MockNetworkPropertiesCallback::CheckResult));
return base::Bind(&MockNetworkPropertiesCallback::Run,
base::Owned(mock_callback));
}
private:
explicit MockNetworkPropertiesCallback(
const base::DictionaryValue& expected_result)
: expected_result_(expected_result) {}
MOCK_METHOD2(Run, void(const char* path,
const base::DictionaryValue* result));
void CheckResult(const char* path, const base::DictionaryValue* result) {
EXPECT_TRUE(expected_result_.Equals(result));
}
const base::DictionaryValue& expected_result_;
};
} // namespace
class CrosNetworkFunctionsTest : public testing::Test {
// Test for cros_network_functions.cc with Libcros.
class CrosNetworkFunctionsLibcrosTest : public testing::Test {
public:
CrosNetworkFunctionsTest() : argument_ghash_table_(NULL) {}
CrosNetworkFunctionsLibcrosTest() : argument_ghash_table_(NULL) {}
virtual void SetUp() {
::g_type_init();
MockChromeOSNetwork::Initialize();
SetLibcrosNetworkFunctionsEnabled(true);
}
virtual void TearDown() {
......@@ -111,13 +140,14 @@ class CrosNetworkFunctionsTest : public testing::Test {
ScopedGHashTable result_ghash_table_;
};
TEST_F(CrosNetworkFunctionsTest, CrosSetNetworkServiceProperty) {
TEST_F(CrosNetworkFunctionsLibcrosTest, CrosSetNetworkServiceProperty) {
const char service_path[] = "/";
const char property[] = "property";
EXPECT_CALL(*MockChromeOSNetwork::Get(),
SetNetworkServicePropertyGValue(service_path, property, _))
.WillOnce(Invoke(
this, &CrosNetworkFunctionsTest::OnSetNetworkPropertyGValue));
EXPECT_CALL(
*MockChromeOSNetwork::Get(),
SetNetworkServicePropertyGValue(service_path, property, _))
.WillOnce(Invoke(
this, &CrosNetworkFunctionsLibcrosTest::OnSetNetworkPropertyGValue));
const char key1[] = "key1";
const std::string string1 = "string1";
const char key2[] = "key2";
......@@ -137,47 +167,49 @@ TEST_F(CrosNetworkFunctionsTest, CrosSetNetworkServiceProperty) {
g_hash_table_lookup(ghash_table, key2)));
}
TEST_F(CrosNetworkFunctionsTest, CrosSetNetworkDeviceProperty) {
TEST_F(CrosNetworkFunctionsLibcrosTest, CrosSetNetworkDeviceProperty) {
const char device_path[] = "/";
const char property[] = "property";
EXPECT_CALL(*MockChromeOSNetwork::Get(),
SetNetworkDevicePropertyGValue(device_path, property, _))
.WillOnce(Invoke(
this, &CrosNetworkFunctionsTest::OnSetNetworkPropertyGValue));
EXPECT_CALL(
*MockChromeOSNetwork::Get(),
SetNetworkDevicePropertyGValue(device_path, property, _))
.WillOnce(Invoke(
this, &CrosNetworkFunctionsLibcrosTest::OnSetNetworkPropertyGValue));
const bool kBool = true;
const base::FundamentalValue value(kBool);
CrosSetNetworkDeviceProperty(device_path, property, value);
EXPECT_EQ(kBool, g_value_get_boolean(argument_gvalue_.get()));
}
TEST_F(CrosNetworkFunctionsTest, CrosSetNetworkIPConfigProperty) {
TEST_F(CrosNetworkFunctionsLibcrosTest, CrosSetNetworkIPConfigProperty) {
const char ipconfig_path[] = "/";
const char property[] = "property";
EXPECT_CALL(*MockChromeOSNetwork::Get(),
SetNetworkIPConfigPropertyGValue(ipconfig_path, property, _))
.WillOnce(Invoke(
this, &CrosNetworkFunctionsTest::OnSetNetworkPropertyGValue));
EXPECT_CALL(
*MockChromeOSNetwork::Get(),
SetNetworkIPConfigPropertyGValue(ipconfig_path, property, _))
.WillOnce(Invoke(
this, &CrosNetworkFunctionsLibcrosTest::OnSetNetworkPropertyGValue));
const int kInt = 1234;
const base::FundamentalValue value(kInt);
CrosSetNetworkIPConfigProperty(ipconfig_path, property, value);
EXPECT_EQ(kInt, g_value_get_int(argument_gvalue_.get()));
}
TEST_F(CrosNetworkFunctionsTest, CrosSetNetworkManagerProperty) {
TEST_F(CrosNetworkFunctionsLibcrosTest, CrosSetNetworkManagerProperty) {
const char property[] = "property";
EXPECT_CALL(
*MockChromeOSNetwork::Get(),
SetNetworkManagerPropertyGValue(property, _))
.WillOnce(Invoke(
this,
&CrosNetworkFunctionsTest::OnSetNetworkManagerPropertyGValue));
&CrosNetworkFunctionsLibcrosTest::OnSetNetworkManagerPropertyGValue));
const std::string kString = "string";
const base::StringValue value(kString);
CrosSetNetworkManagerProperty(property, value);
EXPECT_EQ(kString, g_value_get_string(argument_gvalue_.get()));
}
TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkManagerProperties) {
TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkManagerProperties) {
const std::string key1 = "key1";
const std::string value1 = "value1";
const std::string key2 = "key.2.";
......@@ -193,13 +225,13 @@ TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkManagerProperties) {
*MockChromeOSNetwork::Get(),
RequestNetworkManagerProperties(_, _))
.WillOnce(Invoke(
this, &CrosNetworkFunctionsTest::OnRequestNetworkProperties2));
this, &CrosNetworkFunctionsLibcrosTest::OnRequestNetworkProperties2));
CrosRequestNetworkManagerProperties(
base::Bind(&ExpectPathAndDictionaryValue, &result));
MockNetworkPropertiesCallback::CreateCallback(kExamplePath, result));
}
TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkServiceProperties) {
TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkServiceProperties) {
const std::string service_path = "service path";
const std::string key1 = "key1";
const std::string value1 = "value1";
......@@ -216,13 +248,14 @@ TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkServiceProperties) {
*MockChromeOSNetwork::Get(),
RequestNetworkServiceProperties(service_path.c_str(), _, _))
.WillOnce(Invoke(
this, &CrosNetworkFunctionsTest::OnRequestNetworkProperties3));
this, &CrosNetworkFunctionsLibcrosTest::OnRequestNetworkProperties3));
CrosRequestNetworkServiceProperties(
service_path.c_str(), base::Bind(&ExpectPathAndDictionaryValue, &result));
service_path.c_str(),
MockNetworkPropertiesCallback::CreateCallback(kExamplePath, result));
}
TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkDeviceProperties) {
TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkDeviceProperties) {
const std::string device_path = "device path";
const std::string key1 = "key1";
const std::string value1 = "value1";
......@@ -239,13 +272,14 @@ TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkDeviceProperties) {
*MockChromeOSNetwork::Get(),
RequestNetworkDeviceProperties(device_path.c_str(), _, _))
.WillOnce(Invoke(
this, &CrosNetworkFunctionsTest::OnRequestNetworkProperties3));
this, &CrosNetworkFunctionsLibcrosTest::OnRequestNetworkProperties3));
CrosRequestNetworkDeviceProperties(
device_path.c_str(), base::Bind(&ExpectPathAndDictionaryValue, &result));
device_path.c_str(),
MockNetworkPropertiesCallback::CreateCallback(kExamplePath, result));
}
TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkProfileProperties) {
TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkProfileProperties) {
const std::string profile_path = "profile path";
const std::string key1 = "key1";
const std::string value1 = "value1";
......@@ -262,14 +296,15 @@ TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkProfileProperties) {
*MockChromeOSNetwork::Get(),
RequestNetworkProfileProperties(profile_path.c_str(), _, _))
.WillOnce(Invoke(
this, &CrosNetworkFunctionsTest::OnRequestNetworkProperties3));
this, &CrosNetworkFunctionsLibcrosTest::OnRequestNetworkProperties3));
CrosRequestNetworkProfileProperties(
profile_path.c_str(),
base::Bind(&ExpectPathAndDictionaryValue, &result));
MockNetworkPropertiesCallback::CreateCallback(kExamplePath, result));
}
TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkProfileEntryProperties) {
TEST_F(CrosNetworkFunctionsLibcrosTest,
CrosRequestNetworkProfileEntryProperties) {
const std::string profile_path = "profile path";
const std::string profile_entry_path = "profile entry path";
const std::string key1 = "key1";
......@@ -288,14 +323,16 @@ TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkProfileEntryProperties) {
RequestNetworkProfileEntryProperties(profile_path.c_str(),
profile_entry_path.c_str(), _, _))
.WillOnce(Invoke(
this, &CrosNetworkFunctionsTest::OnRequestNetworkProperties4));
this, &CrosNetworkFunctionsLibcrosTest::OnRequestNetworkProperties4));
CrosRequestNetworkProfileEntryProperties(
profile_path.c_str(), profile_entry_path.c_str(),
base::Bind(&ExpectPathAndDictionaryValue, &result));
profile_path.c_str(),
profile_entry_path.c_str(),
MockNetworkPropertiesCallback::CreateCallback(kExamplePath, result));
}
TEST_F(CrosNetworkFunctionsTest, CrosRequestHiddenWifiNetworkProperties) {
TEST_F(CrosNetworkFunctionsLibcrosTest,
CrosRequestHiddenWifiNetworkProperties) {
const std::string ssid = "ssid";
const std::string security = "security";
const std::string key1 = "key1";
......@@ -313,14 +350,14 @@ TEST_F(CrosNetworkFunctionsTest, CrosRequestHiddenWifiNetworkProperties) {
*MockChromeOSNetwork::Get(),
RequestHiddenWifiNetworkProperties(ssid.c_str(), security.c_str(), _, _))
.WillOnce(Invoke(
this, &CrosNetworkFunctionsTest::OnRequestNetworkProperties4));
this, &CrosNetworkFunctionsLibcrosTest::OnRequestNetworkProperties4));
CrosRequestHiddenWifiNetworkProperties(
ssid.c_str(), security.c_str(),
base::Bind(&ExpectPathAndDictionaryValue, &result));
MockNetworkPropertiesCallback::CreateCallback(kExamplePath, result));
}
TEST_F(CrosNetworkFunctionsTest, CrosRequestVirtualNetworkProperties) {
TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestVirtualNetworkProperties) {
const std::string service_name = "service name";
const std::string server_hostname = "server hostname";
const std::string provider_name = "provider name";
......@@ -340,21 +377,21 @@ TEST_F(CrosNetworkFunctionsTest, CrosRequestVirtualNetworkProperties) {
server_hostname.c_str(),
provider_name.c_str(), _, _))
.WillOnce(Invoke(
this, &CrosNetworkFunctionsTest::OnRequestNetworkProperties5));
this, &CrosNetworkFunctionsLibcrosTest::OnRequestNetworkProperties5));
CrosRequestVirtualNetworkProperties(
service_name.c_str(),
server_hostname.c_str(),
provider_name.c_str(),
base::Bind(&ExpectPathAndDictionaryValue, &result));
MockNetworkPropertiesCallback::CreateCallback(kExamplePath, result));
}
TEST_F(CrosNetworkFunctionsTest, CrosConfigureService) {
TEST_F(CrosNetworkFunctionsLibcrosTest, CrosConfigureService) {
const char identifier[] = "identifier";
EXPECT_CALL(*MockChromeOSNetwork::Get(),
ConfigureService(identifier, _, &OnNetworkAction, this))
.WillOnce(Invoke(
this, &CrosNetworkFunctionsTest::OnConfigureService));
this, &CrosNetworkFunctionsLibcrosTest::OnConfigureService));
const char key1[] = "key1";
const std::string string1 = "string1";
const char key2[] = "key2";
......@@ -373,4 +410,97 @@ TEST_F(CrosNetworkFunctionsTest, CrosConfigureService) {
EXPECT_EQ(string2, g_value_get_string(string2_gvalue));
}
// Test for cros_network_functions.cc without Libcros.
class CrosNetworkFunctionsTest : public testing::Test {
public:
CrosNetworkFunctionsTest() : mock_profile_client_(NULL),
dictionary_value_result_(NULL) {}
virtual void SetUp() {
MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager;
DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
mock_profile_client_ =
mock_dbus_thread_manager->mock_flimflam_profile_client();
SetLibcrosNetworkFunctionsEnabled(false);
}
virtual void TearDown() {
DBusThreadManager::Shutdown();
mock_profile_client_ = NULL;
}
// Handles responses for GetProperties method calls.
void OnGetProperties(
const dbus::ObjectPath& profile_path,
const FlimflamClientHelper::DictionaryValueCallback& callback) {
callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_);
}
// Handles responses for GetEntry method calls.
void OnGetEntry(
const dbus::ObjectPath& profile_path,
const std::string& entry_path,
const FlimflamClientHelper::DictionaryValueCallback& callback) {
callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_);
}
protected:
MockFlimflamProfileClient* mock_profile_client_;
const base::DictionaryValue* dictionary_value_result_;
};
TEST_F(CrosNetworkFunctionsTest, CrosDeleteServiceFromProfile) {
const std::string profile_path("/profile/path");
const std::string service_path("/service/path");
EXPECT_CALL(*mock_profile_client_,
DeleteEntry(dbus::ObjectPath(profile_path), service_path, _))
.Times(1);
CrosDeleteServiceFromProfile(profile_path.c_str(), service_path.c_str());
}
TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkProfileProperties) {
const std::string profile_path = "profile path";
const std::string key1 = "key1";
const std::string value1 = "value1";
const std::string key2 = "key.2.";
const std::string value2 = "value2";
// Create result value.
base::DictionaryValue result;
result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1));
result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2));
// Set expectations.
dictionary_value_result_ = &result;
EXPECT_CALL(*mock_profile_client_,
GetProperties(dbus::ObjectPath(profile_path), _)).WillOnce(
Invoke(this, &CrosNetworkFunctionsTest::OnGetProperties));
CrosRequestNetworkProfileProperties(
profile_path.c_str(),
MockNetworkPropertiesCallback::CreateCallback(profile_path.c_str(),
result));
}
TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkProfileEntryProperties) {
const std::string profile_path = "profile path";
const std::string profile_entry_path = "profile entry path";
const std::string key1 = "key1";
const std::string value1 = "value1";
const std::string key2 = "key.2.";
const std::string value2 = "value2";
// Create result value.
base::DictionaryValue result;
result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1));
result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2));
// Set expectations.
dictionary_value_result_ = &result;
EXPECT_CALL(*mock_profile_client_,
GetEntry(dbus::ObjectPath(profile_path), profile_entry_path, _))
.WillOnce(Invoke(this, &CrosNetworkFunctionsTest::OnGetEntry));
CrosRequestNetworkProfileEntryProperties(
profile_path.c_str(), profile_entry_path.c_str(),
MockNetworkPropertiesCallback::CreateCallback(profile_entry_path.c_str(),
result));
}
} // namespace chromeos
......@@ -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