summaryrefslogtreecommitdiffstats
path: root/chromeos/network
diff options
context:
space:
mode:
authorstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-11 20:10:36 +0000
committerstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-11 20:10:36 +0000
commit1c641e27988557e60163be111275db567fddda6b (patch)
treefaffdf918da644eac02da6e87c784f764761c2ae /chromeos/network
parent165bae7dac7c4e05eca691c58aa8eafe07b1fcc4 (diff)
downloadchromium_src-1c641e27988557e60163be111275db567fddda6b.zip
chromium_src-1c641e27988557e60163be111275db567fddda6b.tar.gz
chromium_src-1c641e27988557e60163be111275db567fddda6b.tar.bz2
Eliminate NetworkLibrary!
There should be no functionality changes with this CL, it should only eliminate unused code. It also removes cros_network_functions and all Shill blocking dbus calls (now unused). BUG=245494 Review URL: https://chromiumcodereview.appspot.com/23477058 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222615 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/network')
-rw-r--r--chromeos/network/cros_network_functions.cc629
-rw-r--r--chromeos/network/cros_network_functions.h253
-rw-r--r--chromeos/network/cros_network_functions_unittest.cc790
-rw-r--r--chromeos/network/sms_watcher.cc409
-rw-r--r--chromeos/network/sms_watcher.h68
5 files changed, 0 insertions, 2149 deletions
diff --git a/chromeos/network/cros_network_functions.cc b/chromeos/network/cros_network_functions.cc
deleted file mode 100644
index ea3ba01..0000000
--- a/chromeos/network/cros_network_functions.cc
+++ /dev/null
@@ -1,629 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chromeos/network/cros_network_functions.h"
-
-#include "base/bind.h"
-#include "base/bind_helpers.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/values.h"
-#include "chromeos/dbus/dbus_thread_manager.h"
-#include "chromeos/dbus/shill_device_client.h"
-#include "chromeos/dbus/shill_ipconfig_client.h"
-#include "chromeos/dbus/shill_manager_client.h"
-#include "chromeos/dbus/shill_profile_client.h"
-#include "chromeos/dbus/shill_property_changed_observer.h"
-#include "chromeos/dbus/shill_service_client.h"
-#include "chromeos/network/network_util.h"
-#include "chromeos/network/sms_watcher.h"
-#include "dbus/object_path.h"
-#include "third_party/cros_system_api/dbus/service_constants.h"
-
-using base::DoNothing;
-
-namespace chromeos {
-
-namespace {
-
-// Class to watch network manager's properties without Libcros.
-class NetworkManagerPropertiesWatcher
- : public CrosNetworkWatcher,
- public ShillPropertyChangedObserver {
- public:
- NetworkManagerPropertiesWatcher(
- const NetworkPropertiesWatcherCallback& callback)
- : callback_(callback) {
- DBusThreadManager::Get()->GetShillManagerClient()->
- AddPropertyChangedObserver(this);
- }
-
- virtual ~NetworkManagerPropertiesWatcher() {
- DBusThreadManager::Get()->GetShillManagerClient()->
- RemovePropertyChangedObserver(this);
- }
-
- virtual void OnPropertyChanged(const std::string& name,
- const base::Value& value) OVERRIDE {
- callback_.Run(flimflam::kFlimflamServicePath, name, value);
- }
- private:
- NetworkPropertiesWatcherCallback callback_;
-};
-
-// Class to watch network service's properties without Libcros.
-class NetworkServicePropertiesWatcher
- : public CrosNetworkWatcher,
- public ShillPropertyChangedObserver {
- public:
- NetworkServicePropertiesWatcher(
- const NetworkPropertiesWatcherCallback& callback,
- const std::string& service_path) : service_path_(service_path),
- callback_(callback) {
- DBusThreadManager::Get()->GetShillServiceClient()->
- AddPropertyChangedObserver(dbus::ObjectPath(service_path), this);
- }
-
- virtual ~NetworkServicePropertiesWatcher() {
- DBusThreadManager::Get()->GetShillServiceClient()->
- RemovePropertyChangedObserver(dbus::ObjectPath(service_path_), this);
- }
-
- virtual void OnPropertyChanged(const std::string& name,
- const base::Value& value) OVERRIDE {
- callback_.Run(service_path_, name, value);
- }
-
- private:
- std::string service_path_;
- NetworkPropertiesWatcherCallback callback_;
-};
-
-// Class to watch network device's properties without Libcros.
-class NetworkDevicePropertiesWatcher
- : public CrosNetworkWatcher,
- public ShillPropertyChangedObserver {
- public:
- NetworkDevicePropertiesWatcher(
- const NetworkPropertiesWatcherCallback& callback,
- const std::string& device_path) : device_path_(device_path),
- callback_(callback) {
- DBusThreadManager::Get()->GetShillDeviceClient()->
- AddPropertyChangedObserver(dbus::ObjectPath(device_path), this);
- }
-
- virtual ~NetworkDevicePropertiesWatcher() {
- DBusThreadManager::Get()->GetShillDeviceClient()->
- RemovePropertyChangedObserver(dbus::ObjectPath(device_path_), this);
- }
-
- virtual void OnPropertyChanged(const std::string& name,
- const base::Value& value) OVERRIDE {
- callback_.Run(device_path_, name, value);
- }
-
- private:
- std::string device_path_;
- NetworkPropertiesWatcherCallback callback_;
-};
-
-// Gets a string property from dictionary.
-bool GetStringProperty(const base::DictionaryValue& dictionary,
- const std::string& key,
- std::string* out) {
- const bool result = dictionary.GetStringWithoutPathExpansion(key, out);
- LOG_IF(WARNING, !result) << "Cannnot get property " << key;
- return result;
-}
-
-// Gets an int64 property from dictionary.
-bool GetInt64Property(const base::DictionaryValue& dictionary,
- const std::string& key,
- int64* out) {
- // Int64 value is stored as a double because it cannot be fitted in int32.
- double value_double = 0;
- const bool result = dictionary.GetDoubleWithoutPathExpansion(key,
- &value_double);
- if (result)
- *out = value_double;
- else
- LOG(WARNING) << "Cannnot get property " << key;
- return result;
-}
-
-// Gets a base::Time property from dictionary.
-bool GetTimeProperty(const base::DictionaryValue& dictionary,
- const std::string& key,
- base::Time* out) {
- int64 value_int64 = 0;
- if (!GetInt64Property(dictionary, key, &value_int64))
- return false;
- *out = base::Time::FromInternalValue(value_int64);
- return true;
-}
-
-// Does nothing. Used as a callback.
-void DoNothingWithCallStatus(DBusMethodCallStatus call_status) {}
-
-// Does nothing. Used as a callback.
-void DoNothingWithObjectPath(const dbus::ObjectPath& object_path) {}
-
-// 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,
- const std::string& path,
- DBusMethodCallStatus call_status,
- const base::DictionaryValue& value) {
- 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,
- const dbus::ObjectPath& service_path) {
- 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.
-void OnNetworkActionError(const NetworkOperationCallback& callback,
- const std::string& path,
- const std::string& error_name,
- const std::string& error_message) {
- if (error_name.empty())
- callback.Run(path, NETWORK_METHOD_ERROR_LOCAL, "");
- else
- callback.Run(path, NETWORK_METHOD_ERROR_REMOTE, error_message);
-}
-
-IPConfigType ParseIPConfigType(const std::string& type) {
- if (type == flimflam::kTypeIPv4)
- return IPCONFIG_TYPE_IPV4;
- if (type == flimflam::kTypeIPv6)
- return IPCONFIG_TYPE_IPV6;
- if (type == flimflam::kTypeDHCP)
- return IPCONFIG_TYPE_DHCP;
- if (type == flimflam::kTypeBOOTP)
- return IPCONFIG_TYPE_BOOTP;
- if (type == flimflam::kTypeZeroConf)
- return IPCONFIG_TYPE_ZEROCONF;
- if (type == flimflam::kTypeDHCP6)
- return IPCONFIG_TYPE_DHCP6;
- if (type == flimflam::kTypePPP)
- return IPCONFIG_TYPE_PPP;
- return IPCONFIG_TYPE_UNKNOWN;
-}
-
-// Converts a list of name servers to a string.
-std::string ConvertNameSerersListToString(const base::ListValue& name_servers) {
- std::string result;
- for (size_t i = 0; i != name_servers.GetSize(); ++i) {
- std::string name_server;
- if (!name_servers.GetString(i, &name_server)) {
- LOG(ERROR) << "name_servers[" << i << "] is not a string.";
- continue;
- }
- if (!result.empty())
- result += ",";
- result += name_server;
- }
- return result;
-}
-
-// Gets NetworkIPConfigVector populated with data from a
-// given DBus object path.
-//
-// returns true on success.
-bool ParseIPConfig(const std::string& device_path,
- const std::string& ipconfig_path,
- NetworkIPConfigVector* ipconfig_vector) {
- ShillIPConfigClient* ipconfig_client =
- DBusThreadManager::Get()->GetShillIPConfigClient();
- // TODO(hashimoto): Remove this blocking D-Bus method call. crosbug.com/29902
- scoped_ptr<base::DictionaryValue> properties(
- ipconfig_client->CallGetPropertiesAndBlock(
- dbus::ObjectPath(ipconfig_path)));
- if (!properties.get())
- return false;
-
- std::string type_string;
- properties->GetStringWithoutPathExpansion(flimflam::kMethodProperty,
- &type_string);
- std::string address;
- properties->GetStringWithoutPathExpansion(flimflam::kAddressProperty,
- &address);
- int32 prefix_len = 0;
- properties->GetIntegerWithoutPathExpansion(flimflam::kPrefixlenProperty,
- &prefix_len);
- std::string gateway;
- properties->GetStringWithoutPathExpansion(flimflam::kGatewayProperty,
- &gateway);
- base::ListValue* name_servers = NULL;
- std::string name_servers_string;
- // store nameservers as a comma delimited list
- if (properties->GetListWithoutPathExpansion(flimflam::kNameServersProperty,
- &name_servers)) {
- name_servers_string = ConvertNameSerersListToString(*name_servers);
- } else {
- LOG(ERROR) << "Cannot get name servers.";
- }
- ipconfig_vector->push_back(
- NetworkIPConfig(device_path,
- ParseIPConfigType(type_string),
- address,
- network_util::PrefixLengthToNetmask(prefix_len),
- gateway,
- name_servers_string));
- return true;
-}
-
-void ListIPConfigsCallback(const NetworkGetIPConfigsCallback& callback,
- const std::string& device_path,
- DBusMethodCallStatus call_status,
- const base::DictionaryValue& properties) {
- NetworkIPConfigVector ipconfig_vector;
- std::string hardware_address;
- const base::ListValue* ips = NULL;
- if (call_status != DBUS_METHOD_CALL_SUCCESS ||
- !properties.GetListWithoutPathExpansion(flimflam::kIPConfigsProperty,
- &ips)) {
- callback.Run(ipconfig_vector, hardware_address);
- return;
- }
-
- for (size_t i = 0; i < ips->GetSize(); i++) {
- std::string ipconfig_path;
- if (!ips->GetString(i, &ipconfig_path)) {
- LOG(WARNING) << "Found NULL ip for device " << device_path;
- continue;
- }
- ParseIPConfig(device_path, ipconfig_path, &ipconfig_vector);
- }
- // Get the hardware address as well.
- properties.GetStringWithoutPathExpansion(flimflam::kAddressProperty,
- &hardware_address);
-
- callback.Run(ipconfig_vector, hardware_address);
-}
-
-} // namespace
-
-bool CrosActivateCellularModem(const std::string& service_path,
- const std::string& carrier) {
- return DBusThreadManager::Get()->GetShillServiceClient()->
- CallActivateCellularModemAndBlock(dbus::ObjectPath(service_path),
- carrier);
-}
-
-void CrosCompleteCellularActivation(const std::string& service_path) {
- return DBusThreadManager::Get()->GetShillServiceClient()->
- CompleteCellularActivation(dbus::ObjectPath(service_path),
- base::Bind(&DoNothing),
- base::Bind(&IgnoreErrors));
-}
-
-void CrosSetNetworkServiceProperty(const std::string& service_path,
- const std::string& property,
- const base::Value& value) {
- DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
- dbus::ObjectPath(service_path), property, value,
- 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),
- 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),
- 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(&DoNothingWithCallStatus));
-}
-
-void CrosSetNetworkManagerProperty(const std::string& property,
- const base::Value& value) {
- DBusThreadManager::Get()->GetShillManagerClient()->SetProperty(
- 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),
- base::Bind(&IgnoreErrors));
-}
-
-CrosNetworkWatcher* CrosMonitorNetworkManagerProperties(
- const NetworkPropertiesWatcherCallback& callback) {
- return new NetworkManagerPropertiesWatcher(callback);
-}
-
-CrosNetworkWatcher* CrosMonitorNetworkServiceProperties(
- const NetworkPropertiesWatcherCallback& callback,
- const std::string& service_path) {
- return new NetworkServicePropertiesWatcher(callback, service_path);
-}
-
-CrosNetworkWatcher* CrosMonitorNetworkDeviceProperties(
- const NetworkPropertiesWatcherCallback& callback,
- const std::string& device_path) {
- return new NetworkDevicePropertiesWatcher(callback, device_path);
-}
-
-CrosNetworkWatcher* CrosMonitorSMS(const std::string& modem_device_path,
- MonitorSMSCallback callback) {
- return new SMSWatcher(modem_device_path, callback);
-}
-
-void CrosRequestNetworkServiceConnect(
- const std::string& service_path,
- const NetworkOperationCallback& callback) {
- DBusThreadManager::Get()->GetShillServiceClient()->Connect(
- dbus::ObjectPath(service_path),
- base::Bind(callback, service_path, NETWORK_METHOD_ERROR_NONE,
- std::string()),
- base::Bind(&OnNetworkActionError, callback, service_path));
-}
-
-void CrosRequestNetworkManagerProperties(
- const NetworkPropertiesCallback& callback) {
- DBusThreadManager::Get()->GetShillManagerClient()->GetProperties(
- base::Bind(&RunCallbackWithDictionaryValue,
- callback,
- flimflam::kFlimflamServicePath));
-}
-
-void CrosRequestNetworkServiceProperties(
- const std::string& service_path,
- const NetworkPropertiesCallback& callback) {
- DBusThreadManager::Get()->GetShillServiceClient()->GetProperties(
- dbus::ObjectPath(service_path),
- base::Bind(&RunCallbackWithDictionaryValue, callback, service_path));
-}
-
-void CrosRequestNetworkDeviceProperties(
- const std::string& device_path,
- const NetworkPropertiesCallback& callback) {
- DBusThreadManager::Get()->GetShillDeviceClient()->GetProperties(
- dbus::ObjectPath(device_path),
- base::Bind(&RunCallbackWithDictionaryValue, callback, device_path));
-}
-
-void CrosRequestNetworkProfileProperties(
- const std::string& profile_path,
- const NetworkPropertiesCallback& callback) {
- DBusThreadManager::Get()->GetShillProfileClient()->GetProperties(
- dbus::ObjectPath(profile_path),
- base::Bind(&RunCallbackWithDictionaryValueNoStatus,
- callback, profile_path),
- base::Bind(&RunCallbackWithDictionaryValueError, callback, profile_path));
-}
-
-void CrosRequestNetworkProfileEntryProperties(
- const std::string& profile_path,
- const std::string& profile_entry_path,
- const NetworkPropertiesCallback& callback) {
- DBusThreadManager::Get()->GetShillProfileClient()->GetEntry(
- dbus::ObjectPath(profile_path),
- profile_entry_path,
- base::Bind(&RunCallbackWithDictionaryValueNoStatus,
- callback,
- profile_entry_path),
- base::Bind(&RunCallbackWithDictionaryValueError,
- callback,
- profile_entry_path));
-}
-
-void CrosRequestHiddenWifiNetworkProperties(
- const std::string& ssid,
- const std::string& security,
- const NetworkPropertiesCallback& callback) {
- base::DictionaryValue properties;
- properties.SetWithoutPathExpansion(
- flimflam::kModeProperty,
- new base::StringValue(flimflam::kModeManaged));
- properties.SetWithoutPathExpansion(
- flimflam::kTypeProperty,
- new base::StringValue(flimflam::kTypeWifi));
- properties.SetWithoutPathExpansion(
- flimflam::kSSIDProperty,
- new base::StringValue(ssid));
- properties.SetWithoutPathExpansion(
- flimflam::kSecurityProperty,
- new base::StringValue(security));
- // shill.Manger.GetService() will apply the property changes in
- // |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),
- base::Bind(&IgnoreErrors));
-}
-
-void CrosRequestVirtualNetworkProperties(
- const std::string& service_name,
- const std::string& server_hostname,
- const std::string& provider_type,
- const NetworkPropertiesCallback& callback) {
- base::DictionaryValue properties;
- properties.SetWithoutPathExpansion(
- flimflam::kTypeProperty,
- new base::StringValue(flimflam::kTypeVPN));
- properties.SetWithoutPathExpansion(
- flimflam::kNameProperty,
- new base::StringValue(service_name));
- properties.SetWithoutPathExpansion(
- flimflam::kProviderHostProperty,
- new base::StringValue(server_hostname));
- properties.SetWithoutPathExpansion(
- flimflam::kProviderTypeProperty,
- new base::StringValue(provider_type));
-
- // shill.Manger.ConfigureService() will apply the property changes in
- // |properties| and pass a new or existing service to OnGetService().
- // OnGetService will then call GetProperties which will then call callback.
- DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService(
- 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),
- base::Bind(&IgnoreErrors));
-}
-
-void CrosRequestRemoveNetworkService(const std::string& service_path) {
- DBusThreadManager::Get()->GetShillServiceClient()->Remove(
- 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),
- base::Bind(&IgnoreErrors));
-}
-
-void CrosRequestNetworkDeviceEnable(const std::string& network_type,
- bool enable) {
- if (enable) {
- DBusThreadManager::Get()->GetShillManagerClient()->EnableTechnology(
- network_type, base::Bind(&DoNothing),
- base::Bind(&IgnoreErrors));
- } else {
- DBusThreadManager::Get()->GetShillManagerClient()->DisableTechnology(
- network_type, base::Bind(&DoNothing),
- base::Bind(&IgnoreErrors));
- }
-}
-
-void CrosRequestRequirePin(const std::string& device_path,
- const std::string& pin,
- bool enable,
- const NetworkOperationCallback& callback) {
- DBusThreadManager::Get()->GetShillDeviceClient()->RequirePin(
- dbus::ObjectPath(device_path), pin, enable,
- base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE,
- std::string()),
- base::Bind(&OnNetworkActionError, callback, device_path));
-}
-
-void CrosRequestEnterPin(const std::string& device_path,
- const std::string& pin,
- const NetworkOperationCallback& callback) {
- DBusThreadManager::Get()->GetShillDeviceClient()->EnterPin(
- dbus::ObjectPath(device_path), pin,
- base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE,
- std::string()),
- base::Bind(&OnNetworkActionError, callback, device_path));
-}
-
-void CrosRequestUnblockPin(const std::string& device_path,
- const std::string& unblock_code,
- const std::string& pin,
- const NetworkOperationCallback& callback) {
- DBusThreadManager::Get()->GetShillDeviceClient()->UnblockPin(
- dbus::ObjectPath(device_path), unblock_code, pin,
- base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE,
- std::string()),
- base::Bind(&OnNetworkActionError, callback, device_path));
-}
-
-void CrosRequestChangePin(const std::string& device_path,
- const std::string& old_pin,
- const std::string& new_pin,
- const NetworkOperationCallback& callback) {
- DBusThreadManager::Get()->GetShillDeviceClient()->ChangePin(
- dbus::ObjectPath(device_path), old_pin, new_pin,
- base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE,
- std::string()),
- base::Bind(&OnNetworkActionError, callback, device_path));
-}
-
-void CrosProposeScan(const std::string& device_path) {
- DBusThreadManager::Get()->GetShillDeviceClient()->ProposeScan(
- dbus::ObjectPath(device_path), base::Bind(&DoNothingWithCallStatus));
-}
-
-void CrosRequestCellularRegister(const std::string& device_path,
- const std::string& network_id,
- const NetworkOperationCallback& callback) {
- DBusThreadManager::Get()->GetShillDeviceClient()->Register(
- dbus::ObjectPath(device_path), network_id,
- base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE,
- std::string()),
- base::Bind(&OnNetworkActionError, callback, device_path));
-}
-
-void CrosListIPConfigs(const std::string& device_path,
- const NetworkGetIPConfigsCallback& callback) {
- const dbus::ObjectPath device_object_path(device_path);
- DBusThreadManager::Get()->GetShillDeviceClient()->GetProperties(
- device_object_path,
- base::Bind(&ListIPConfigsCallback, callback, device_path));
-}
-
-void CrosRequestIPConfigRefresh(const std::string& ipconfig_path) {
- DBusThreadManager::Get()->GetShillIPConfigClient()->Refresh(
- dbus::ObjectPath(ipconfig_path),
- base::Bind(&DoNothingWithCallStatus));
-}
-
-void CrosConfigureService(const base::DictionaryValue& properties) {
- DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService(
- properties, base::Bind(&DoNothingWithObjectPath),
- base::Bind(&IgnoreErrors));
-}
-
-// Changes the active cellular carrier.
-void CrosSetCarrier(const std::string& device_path,
- const std::string& carrier,
- const NetworkOperationCallback& callback) {
- DBusThreadManager::Get()->GetShillDeviceClient()->SetCarrier(
- dbus::ObjectPath(device_path), carrier,
- base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE,
- std::string()),
- base::Bind(&OnNetworkActionError, callback, device_path));
-}
-
-} // namespace chromeos
diff --git a/chromeos/network/cros_network_functions.h b/chromeos/network/cros_network_functions.h
deleted file mode 100644
index e787a3f..0000000
--- a/chromeos/network/cros_network_functions.h
+++ /dev/null
@@ -1,253 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROMEOS_NETWORK_CROS_NETWORK_FUNCTIONS_H_
-#define CHROMEOS_NETWORK_CROS_NETWORK_FUNCTIONS_H_
-
-// This header is introduced to make it easy to switch from chromeos_network.cc
-// to Chrome's own DBus code. crosbug.com/16557
-//
-// All calls to functions in chromeos_network.h should be made through
-// functions provided by this header.
-//
-// DO NOT INCLUDE THIS HEADER DIRECTLY, THESE FUNCTIONS ARE BEING DEPRECATED.
-// Contact stevenjb@chromium.org and/or see crbug.com/154852
-
-#include <vector>
-
-#include "base/callback.h"
-#include "chromeos/chromeos_export.h"
-#include "chromeos/network/network_ip_config.h"
-#include "chromeos/network/network_util.h"
-
-namespace base {
-
-class DictionaryValue;
-class Value;
-
-} // namespace base
-
-namespace chromeos {
-
-// Callback to be called when receiving a SMS.
-typedef base::Callback<void(const std::string& modem_device_path,
- const SMS& message)> MonitorSMSCallback;
-
-// Callback for asynchronous getters.
-typedef base::Callback<void(
- const std::string& path,
- const base::DictionaryValue* properties)> NetworkPropertiesCallback;
-
-// Callback for network properties watchers.
-typedef base::Callback<void(
- const std::string& path,
- const std::string& key,
- const base::Value& value)> NetworkPropertiesWatcherCallback;
-
-// Base class of signal watchers.
-class CHROMEOS_EXPORT CrosNetworkWatcher {
- public:
- virtual ~CrosNetworkWatcher() {}
-
- protected:
- CrosNetworkWatcher() {}
-};
-
-// 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
-// active carrier.
-// Returns false on failure and true on success.
-CHROMEOS_EXPORT bool CrosActivateCellularModem(const std::string& service_path,
- const std::string& carrier);
-
-// Completes the activation for the cellular modem specified by |service_path|.
-CHROMEOS_EXPORT void CrosCompleteCellularActivation(
- const std::string& service_path);
-
-// Sets a property of a service to the provided value.
-// Success is indicated by the receipt of a matching PropertyChanged signal.
-CHROMEOS_EXPORT void CrosSetNetworkServiceProperty(
- const std::string& service_path,
- const std::string& property,
- const base::Value& value);
-
-// Clears a property of a service.
-CHROMEOS_EXPORT void CrosClearNetworkServiceProperty(
- const std::string& service_path,
- const std::string& property);
-
-// Sets a property of a device to the provided value.
-// Success is indicated by the receipt of a matching PropertyChanged signal.
-CHROMEOS_EXPORT void CrosSetNetworkDeviceProperty(
- const std::string& device_path,
- const std::string& property,
- const base::Value& value);
-
-// Sets a property of an ip config to the provided value.
-// Success is indicated by the receipt of a matching PropertyChanged signal.
-CHROMEOS_EXPORT void CrosSetNetworkIPConfigProperty(
- const std::string& ipconfig_path,
- const std::string& property,
- const base::Value& value);
-
-// Sets a property of a manager to the provided value.
-// Success is indicated by the receipt of a matching PropertyChanged signal.
-CHROMEOS_EXPORT void CrosSetNetworkManagerProperty(const std::string& property,
- const base::Value& value);
-
-// Deletes a remembered service from a profile.
-CHROMEOS_EXPORT void CrosDeleteServiceFromProfile(
- const std::string& profile_path,
- const std::string& service_path);
-
-// Sets up monitoring of the PropertyChanged signal on the shill manager.
-// The provided |callback| will be called whenever a manager property changes.
-CHROMEOS_EXPORT CrosNetworkWatcher* CrosMonitorNetworkManagerProperties(
- const NetworkPropertiesWatcherCallback& callback);
-
-// Similar to MonitorNetworkManagerProperties for a specified network service.
-CHROMEOS_EXPORT CrosNetworkWatcher* CrosMonitorNetworkServiceProperties(
- const NetworkPropertiesWatcherCallback& callback,
- const std::string& service_path);
-
-// Similar to MonitorNetworkManagerProperties for a specified network device.
-CHROMEOS_EXPORT CrosNetworkWatcher* CrosMonitorNetworkDeviceProperties(
- const NetworkPropertiesWatcherCallback& callback,
- const std::string& device_path);
-
-// Similar to MonitorNetworkManagerProperties for a specified network device.
-CHROMEOS_EXPORT CrosNetworkWatcher* CrosMonitorSMS(
- const std::string& modem_device_path,
- MonitorSMSCallback callback);
-
-// Connects to the service with the |service_path|.
-// Service parameters such as authentication must already be configured.
-// Note, a successful invocation of the callback only indicates that
-// the connection process has started. You will have to query the
-// connection state to determine if the connection was established
-// successfully.
-CHROMEOS_EXPORT void CrosRequestNetworkServiceConnect(
- const std::string& service_path,
- const NetworkOperationCallback& callback);
-
-// Retrieves the latest info for the manager.
-CHROMEOS_EXPORT void CrosRequestNetworkManagerProperties(
- const NetworkPropertiesCallback& callback);
-
-// Retrieves the latest info for a service.
-CHROMEOS_EXPORT void CrosRequestNetworkServiceProperties(
- const std::string& service_path,
- const NetworkPropertiesCallback& callback);
-
-// Retrieves the latest info for a particular device.
-CHROMEOS_EXPORT void CrosRequestNetworkDeviceProperties(
- const std::string& device_path,
- const NetworkPropertiesCallback& callback);
-
-// Retrieves the list of remembered services for a profile.
-CHROMEOS_EXPORT void CrosRequestNetworkProfileProperties(
- const std::string& profile_path,
- const NetworkPropertiesCallback& callback);
-
-// Retrieves the latest info for a profile service entry.
-CHROMEOS_EXPORT void CrosRequestNetworkProfileEntryProperties(
- const std::string& profile_path,
- const std::string& profile_entry_path,
- const NetworkPropertiesCallback& callback);
-
-// Requests a wifi service not in the network list (i.e. hidden).
-CHROMEOS_EXPORT void CrosRequestHiddenWifiNetworkProperties(
- const std::string& ssid,
- const std::string& security,
- const NetworkPropertiesCallback& callback);
-
-// Requests a new VPN service.
-CHROMEOS_EXPORT void CrosRequestVirtualNetworkProperties(
- const std::string& service_name,
- const std::string& server_hostname,
- const std::string& provider_type,
- const NetworkPropertiesCallback& callback);
-
-// Disconnects from network service asynchronously.
-CHROMEOS_EXPORT void CrosRequestNetworkServiceDisconnect(
- const std::string& service_path);
-
-// Removes an exisiting network service (e.g. after forgetting a VPN).
-CHROMEOS_EXPORT void CrosRequestRemoveNetworkService(
- const std::string& service_path);
-
-// Requests a scan of services of |type|.
-// |type| should be is a string recognized by shill's Manager API.
-CHROMEOS_EXPORT void CrosRequestNetworkScan(const std::string& network_type);
-
-// Requests enabling or disabling a device.
-CHROMEOS_EXPORT void CrosRequestNetworkDeviceEnable(
- const std::string& network_type,
- bool enable);
-
-// Enables or disables PIN protection for a SIM card.
-CHROMEOS_EXPORT void CrosRequestRequirePin(
- const std::string& device_path,
- const std::string& pin,
- bool enable,
- const NetworkOperationCallback& callback);
-
-// Enters a PIN to unlock a SIM card.
-CHROMEOS_EXPORT void CrosRequestEnterPin(
- const std::string& device_path,
- const std::string& pin,
- const NetworkOperationCallback& callback);
-
-// Enters a PUK to unlock a SIM card whose PIN has been entered
-// incorrectly too many times. A new |pin| must be supplied
-// along with the |unblock_code| (PUK).
-CHROMEOS_EXPORT void CrosRequestUnblockPin(
- const std::string& device_path,
- const std::string& unblock_code,
- const std::string& pin,
- const NetworkOperationCallback& callback);
-
-// Changes the PIN used to unlock a SIM card.
-CHROMEOS_EXPORT void CrosRequestChangePin(
- const std::string& device_path,
- const std::string& old_pin,
- const std::string& new_pin,
- const NetworkOperationCallback& callback);
-
-// Proposes to trigger a scan transaction. For cellular networks scan result
-// is set in the property Cellular.FoundNetworks.
-CHROMEOS_EXPORT void CrosProposeScan(const std::string& device_path);
-
-// Initiates registration on the network specified by network_id, which is in
-// the form MCCMNC. If the network ID is the empty string, then switch back to
-// automatic registration mode before initiating registration.
-CHROMEOS_EXPORT void CrosRequestCellularRegister(
- const std::string& device_path,
- const std::string& network_id,
- const NetworkOperationCallback& callback);
-
-// Gets a list of all the NetworkIPConfigs using a given device path,
-// and returns the information via callback.
-CHROMEOS_EXPORT void CrosListIPConfigs(
- const std::string& device_path,
- const NetworkGetIPConfigsCallback& callback);
-
-// Refreshes the IP config |ipconfig_path| to pick up changes in
-// configuration, and renew the DHCP lease, if any.
-CHROMEOS_EXPORT void CrosRequestIPConfigRefresh(
- const std::string& ipconfig_path);
-
-// Configures the network service specified by |properties|.
-CHROMEOS_EXPORT void CrosConfigureService(
- const base::DictionaryValue& properties);
-
-// Changes the active cellular carrier.
-CHROMEOS_EXPORT void CrosSetCarrier(const std::string& device_path,
- const std::string& carrier,
- const NetworkOperationCallback& callback);
-
-} // namespace chromeos
-
-#endif // CHROMEOS_NETWORK_CROS_NETWORK_FUNCTIONS_H_
diff --git a/chromeos/network/cros_network_functions_unittest.cc b/chromeos/network/cros_network_functions_unittest.cc
deleted file mode 100644
index 3138a29..0000000
--- a/chromeos/network/cros_network_functions_unittest.cc
+++ /dev/null
@@ -1,790 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/bind.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/values.h"
-#include "chromeos/dbus/mock_dbus_thread_manager.h"
-#include "chromeos/dbus/mock_gsm_sms_client.h"
-#include "chromeos/dbus/mock_shill_device_client.h"
-#include "chromeos/dbus/mock_shill_ipconfig_client.h"
-#include "chromeos/dbus/mock_shill_manager_client.h"
-#include "chromeos/dbus/mock_shill_profile_client.h"
-#include "chromeos/dbus/mock_shill_service_client.h"
-#include "chromeos/network/cros_network_functions.h"
-#include "chromeos/network/sms_watcher.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/cros_system_api/dbus/service_constants.h"
-
-using ::testing::_;
-using ::testing::Invoke;
-using ::testing::Pointee;
-using ::testing::Return;
-using ::testing::SaveArg;
-using ::testing::StrEq;
-
-// Matcher to match base::Value.
-MATCHER_P(IsEqualTo, value, "") { return arg.Equals(value); }
-
-// Matcher to match SMS.
-MATCHER_P(IsSMSEqualTo, sms, "") {
- return sms.timestamp == arg.timestamp &&
- std::string(sms.number) == arg.number &&
- std::string(sms.text) == arg.text &&
- sms.validity == arg.validity &&
- sms.msgclass == arg.msgclass;
-}
-
-// Matcher to match IPConfig::path
-MATCHER_P(IsIPConfigPathEqualTo, str, "") { return str == arg.path; }
-
-namespace chromeos {
-
-namespace {
-
-const char kExamplePath[] = "/foo/bar/baz";
-
-// 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 std::string& expected_path,
- const base::DictionaryValue& expected_result) {
- MockNetworkPropertiesCallback* mock_callback =
- new MockNetworkPropertiesCallback;
-
- EXPECT_CALL(*mock_callback,
- Run(expected_path, Pointee(IsEqualTo(&expected_result))))
- .Times(1);
-
- return base::Bind(&MockNetworkPropertiesCallback::Run,
- base::Owned(mock_callback));
- }
-
- MOCK_METHOD2(Run, void(const std::string& path,
- const base::DictionaryValue* result));
-};
-
-// A mock to check arguments of NetworkPropertiesWatcherCallback and ensure that
-// the callback is called exactly once.
-class MockNetworkPropertiesWatcherCallback {
- public:
- // Creates a NetworkPropertiesWatcherCallback with expectations.
- static NetworkPropertiesWatcherCallback CreateCallback(
- const std::string& expected_path,
- const std::string& expected_key,
- const base::Value& expected_value) {
- MockNetworkPropertiesWatcherCallback* mock_callback =
- new MockNetworkPropertiesWatcherCallback;
-
- EXPECT_CALL(*mock_callback,
- Run(expected_path, expected_key, IsEqualTo(&expected_value)))
- .Times(1);
-
- return base::Bind(&MockNetworkPropertiesWatcherCallback::Run,
- base::Owned(mock_callback));
- }
-
- MOCK_METHOD3(Run, void(const std::string& expected_path,
- const std::string& expected_key,
- const base::Value& value));
-};
-
-} // namespace
-
-// 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;
- EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus())
- .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL)));
- DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
- mock_device_client_ =
- mock_dbus_thread_manager->mock_shill_device_client();
- mock_ipconfig_client_ =
- mock_dbus_thread_manager->mock_shill_ipconfig_client();
- mock_manager_client_ =
- mock_dbus_thread_manager->mock_shill_manager_client();
- mock_profile_client_ =
- mock_dbus_thread_manager->mock_shill_profile_client();
- mock_service_client_ =
- mock_dbus_thread_manager->mock_shill_service_client();
- mock_gsm_sms_client_ = mock_dbus_thread_manager->mock_gsm_sms_client();
- }
-
- virtual void TearDown() {
- DBusThreadManager::Shutdown();
- mock_profile_client_ = NULL;
- }
-
- // Handles responses for GetProperties method calls for ShillManagerClient.
- void OnGetManagerProperties(
- const ShillClientHelper::DictionaryValueCallback& callback) {
- callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_);
- }
-
- // Handles responses for GetProperties method calls.
- void OnGetProperties(
- const dbus::ObjectPath& path,
- const ShillClientHelper::DictionaryValueCallback& callback) {
- callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_);
- }
-
- // Handles responses for GetProperties method calls that return
- // errors in an error callback.
- void OnGetPropertiesWithoutStatus(
- const dbus::ObjectPath& path,
- const ShillClientHelper::DictionaryValueCallbackWithoutStatus& callback,
- const ShillClientHelper::ErrorCallback& error_callback) {
- callback.Run(*dictionary_value_result_);
- }
-
- // Handles responses for GetEntry method calls.
- void OnGetEntry(
- const dbus::ObjectPath& profile_path,
- const std::string& entry_path,
- const ShillClientHelper::DictionaryValueCallbackWithoutStatus& callback,
- const ShillClientHelper::ErrorCallback& error_callback) {
- callback.Run(*dictionary_value_result_);
- }
-
- // Mock NetworkOperationCallback.
- MOCK_METHOD3(MockNetworkOperationCallback,
- void(const std::string& path,
- NetworkMethodErrorType error,
- const std::string& error_message));
-
- // Mock MonitorSMSCallback.
- MOCK_METHOD2(MockMonitorSMSCallback,
- void(const std::string& modem_device_path, const SMS& message));
-
- protected:
- MockShillDeviceClient* mock_device_client_;
- MockShillIPConfigClient* mock_ipconfig_client_;
- MockShillManagerClient* mock_manager_client_;
- MockShillProfileClient* mock_profile_client_;
- MockShillServiceClient* mock_service_client_;
- MockGsmSMSClient* mock_gsm_sms_client_;
- const base::DictionaryValue* dictionary_value_result_;
-};
-
-TEST_F(CrosNetworkFunctionsTest, CrosActivateCellularModem) {
- const std::string service_path = "/";
- const std::string carrier = "carrier";
- EXPECT_CALL(*mock_service_client_,
- CallActivateCellularModemAndBlock(dbus::ObjectPath(service_path),
- carrier))
- .WillOnce(Return(true));
- EXPECT_TRUE(CrosActivateCellularModem(service_path, carrier));
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosCompleteCellularActivation) {
- const std::string service_path = "/";
- EXPECT_CALL(*mock_service_client_,
- CompleteCellularActivation(dbus::ObjectPath(service_path), _, _))
- .Times(1);
-
- CrosCompleteCellularActivation(service_path);
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosSetNetworkServiceProperty) {
- const std::string service_path = "/";
- const std::string property = "property";
- const std::string key1 = "key1";
- const std::string string1 = "string1";
- const std::string key2 = "key2";
- const std::string string2 = "string2";
- base::DictionaryValue value;
- value.SetString(key1, string1);
- value.SetString(key2, string2);
- EXPECT_CALL(*mock_service_client_,
- SetProperty(dbus::ObjectPath(service_path), property,
- IsEqualTo(&value), _, _)).Times(1);
-
- CrosSetNetworkServiceProperty(service_path, property, value);
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosClearNetworkServiceProperty) {
- const std::string service_path = "/";
- const std::string property = "property";
- EXPECT_CALL(*mock_service_client_,
- ClearProperty(dbus::ObjectPath(service_path), property, _, _))
- .Times(1);
-
- CrosClearNetworkServiceProperty(service_path, property);
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosSetNetworkDeviceProperty) {
- const std::string device_path = "/";
- const std::string property = "property";
- const bool kBool = true;
- const base::FundamentalValue value(kBool);
- EXPECT_CALL(*mock_device_client_,
- SetProperty(dbus::ObjectPath(device_path), StrEq(property),
- IsEqualTo(&value), _, _)).Times(1);
-
- CrosSetNetworkDeviceProperty(device_path, property, value);
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosSetNetworkIPConfigProperty) {
- const std::string ipconfig_path = "/";
- const std::string property = "property";
- const int kInt = 1234;
- const base::FundamentalValue value(kInt);
- EXPECT_CALL(*mock_ipconfig_client_,
- SetProperty(dbus::ObjectPath(ipconfig_path), property,
- IsEqualTo(&value), _)).Times(1);
- CrosSetNetworkIPConfigProperty(ipconfig_path, property, value);
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosSetNetworkManagerProperty) {
- const std::string property = "property";
- const base::StringValue value("string");
- EXPECT_CALL(*mock_manager_client_,
- SetProperty(property, IsEqualTo(&value), _, _)).Times(1);
-
- CrosSetNetworkManagerProperty(property, value);
-}
-
-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, service_path);
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosMonitorNetworkManagerProperties) {
- const std::string key = "key";
- const int kValue = 42;
- const base::FundamentalValue value(kValue);
-
- // Start monitoring.
- ShillPropertyChangedObserver* observer = NULL;
- EXPECT_CALL(*mock_manager_client_, AddPropertyChangedObserver(_))
- .WillOnce(SaveArg<0>(&observer));
- CrosNetworkWatcher* watcher = CrosMonitorNetworkManagerProperties(
- MockNetworkPropertiesWatcherCallback::CreateCallback(
- flimflam::kFlimflamServicePath, key, value));
- // Call callback.
- observer->OnPropertyChanged(key, value);
- // Stop monitoring.
- EXPECT_CALL(*mock_manager_client_,
- RemovePropertyChangedObserver(_)).Times(1);
- delete watcher;
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosMonitorNetworkServiceProperties) {
- const dbus::ObjectPath path("/path");
- const std::string key = "key";
- const int kValue = 42;
- const base::FundamentalValue value(kValue);
- // Start monitoring.
- ShillPropertyChangedObserver* observer = NULL;
- EXPECT_CALL(*mock_service_client_, AddPropertyChangedObserver(path, _))
- .WillOnce(SaveArg<1>(&observer));
- NetworkPropertiesWatcherCallback callback =
- MockNetworkPropertiesWatcherCallback::CreateCallback(path.value(),
- key, value);
- CrosNetworkWatcher* watcher = CrosMonitorNetworkServiceProperties(
- callback, path.value());
- // Call callback.
- observer->OnPropertyChanged(key, value);
- // Stop monitoring.
- EXPECT_CALL(*mock_service_client_,
- RemovePropertyChangedObserver(path, _)).Times(1);
- delete watcher;
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosMonitorNetworkDeviceProperties) {
- const dbus::ObjectPath path("/path");
- const std::string key = "key";
- const int kValue = 42;
- const base::FundamentalValue value(kValue);
- // Start monitoring.
- ShillPropertyChangedObserver* observer = NULL;
- EXPECT_CALL(*mock_device_client_, AddPropertyChangedObserver(path, _))
- .WillOnce(SaveArg<1>(&observer));
- NetworkPropertiesWatcherCallback callback =
- MockNetworkPropertiesWatcherCallback::CreateCallback(path.value(),
- key, value);
- CrosNetworkWatcher* watcher = CrosMonitorNetworkDeviceProperties(
- callback, path.value());
- // Call callback.
- observer->OnPropertyChanged(key, value);
- // Stop monitoring.
- EXPECT_CALL(*mock_device_client_,
- RemovePropertyChangedObserver(path, _)).Times(1);
- delete watcher;
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosMonitorSMS) {
- const std::string dbus_connection = ":1.1";
- const dbus::ObjectPath object_path("/object/path");
- base::DictionaryValue device_properties;
- device_properties.SetWithoutPathExpansion(
- flimflam::kDBusConnectionProperty,
- new base::StringValue(dbus_connection));
- device_properties.SetWithoutPathExpansion(
- flimflam::kDBusObjectProperty,
- new base::StringValue(object_path.value()));
-
- const std::string number = "0123456789";
- const std::string text = "Hello.";
- const std::string timestamp_string =
- "120424123456+00"; // 2012-04-24 12:34:56
- base::Time::Exploded timestamp_exploded = {};
- timestamp_exploded.year = 2012;
- timestamp_exploded.month = 4;
- timestamp_exploded.day_of_month = 24;
- timestamp_exploded.hour = 12;
- timestamp_exploded.minute = 34;
- timestamp_exploded.second = 56;
- const base::Time timestamp = base::Time::FromUTCExploded(timestamp_exploded);
- const std::string smsc = "9876543210";
- const uint32 kValidity = 1;
- const uint32 kMsgclass = 2;
- const uint32 kIndex = 0;
- const bool kComplete = true;
- base::DictionaryValue* sms_dictionary = new base::DictionaryValue;
- sms_dictionary->SetWithoutPathExpansion(
- SMSWatcher::kNumberKey, new base::StringValue(number));
- sms_dictionary->SetWithoutPathExpansion(
- SMSWatcher::kTextKey, new base::StringValue(text));
- sms_dictionary->SetWithoutPathExpansion(
- SMSWatcher::kTimestampKey,
- new base::StringValue(timestamp_string));
- sms_dictionary->SetWithoutPathExpansion(SMSWatcher::kSmscKey,
- new base::StringValue(smsc));
- sms_dictionary->SetWithoutPathExpansion(
- SMSWatcher::kValidityKey, base::Value::CreateDoubleValue(kValidity));
- sms_dictionary->SetWithoutPathExpansion(
- SMSWatcher::kClassKey, base::Value::CreateDoubleValue(kMsgclass));
- sms_dictionary->SetWithoutPathExpansion(
- SMSWatcher::kIndexKey, base::Value::CreateDoubleValue(kIndex));
-
- base::ListValue sms_list;
- sms_list.Append(sms_dictionary);
-
- SMS sms;
- sms.timestamp = timestamp;
- sms.number = number.c_str();
- sms.text = text.c_str();
- sms.smsc = smsc.c_str();
- sms.validity = kValidity;
- sms.msgclass = kMsgclass;
-
- const std::string modem_device_path = "/modem/device/path";
-
- // Set expectations.
- ShillDeviceClient::DictionaryValueCallback get_properties_callback;
- EXPECT_CALL(*mock_device_client_,
- GetProperties(dbus::ObjectPath(modem_device_path), _))
- .WillOnce(SaveArg<1>(&get_properties_callback));
- GsmSMSClient::SmsReceivedHandler sms_received_handler;
- EXPECT_CALL(*mock_gsm_sms_client_,
- SetSmsReceivedHandler(dbus_connection, object_path, _))
- .WillOnce(SaveArg<2>(&sms_received_handler));
-
- GsmSMSClient::ListCallback list_callback;
- EXPECT_CALL(*mock_gsm_sms_client_, List(dbus_connection, object_path, _))
- .WillOnce(SaveArg<2>(&list_callback));
-
- EXPECT_CALL(*this, MockMonitorSMSCallback(
- modem_device_path, IsSMSEqualTo(sms))).Times(2);
-
- GsmSMSClient::DeleteCallback delete_callback;
- EXPECT_CALL(*mock_gsm_sms_client_,
- Delete(dbus_connection, object_path, kIndex, _))
- .WillRepeatedly(SaveArg<3>(&delete_callback));
-
- GsmSMSClient::GetCallback get_callback;
- EXPECT_CALL(*mock_gsm_sms_client_,
- Get(dbus_connection, object_path, kIndex, _))
- .WillOnce(SaveArg<3>(&get_callback));
-
- // Start monitoring.
- CrosNetworkWatcher* watcher = CrosMonitorSMS(
- modem_device_path,
- base::Bind(&CrosNetworkFunctionsTest::MockMonitorSMSCallback,
- base::Unretained(this)));
- // Return GetProperties() result.
- get_properties_callback.Run(DBUS_METHOD_CALL_SUCCESS, device_properties);
- // Return List() result.
- ASSERT_FALSE(list_callback.is_null());
- list_callback.Run(sms_list);
- // Return Delete() result.
- ASSERT_FALSE(delete_callback.is_null());
- delete_callback.Run();
- // Send fake signal.
- ASSERT_FALSE(sms_received_handler.is_null());
- sms_received_handler.Run(kIndex, kComplete);
- // Return Get() result.
- ASSERT_FALSE(get_callback.is_null());
- get_callback.Run(*sms_dictionary);
- // Return Delete() result.
- ASSERT_FALSE(delete_callback.is_null());
- delete_callback.Run();
- // Stop monitoring.
- EXPECT_CALL(*mock_gsm_sms_client_,
- ResetSmsReceivedHandler(dbus_connection, object_path)).Times(1);
- delete watcher;
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkManagerProperties) {
- 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, new base::StringValue(value1));
- result.SetWithoutPathExpansion(key2, new base::StringValue(value2));
- // Set expectations.
- dictionary_value_result_ = &result;
- EXPECT_CALL(*mock_manager_client_,
- GetProperties(_)).WillOnce(
- Invoke(this,
- &CrosNetworkFunctionsTest::OnGetManagerProperties));
-
- CrosRequestNetworkManagerProperties(
- MockNetworkPropertiesCallback::CreateCallback(
- flimflam::kFlimflamServicePath, result));
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkServiceProperties) {
- const std::string service_path = "/service/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, new base::StringValue(value1));
- result.SetWithoutPathExpansion(key2, new base::StringValue(value2));
- // Set expectations.
- dictionary_value_result_ = &result;
- EXPECT_CALL(*mock_service_client_,
- GetProperties(dbus::ObjectPath(service_path), _)).WillOnce(
- Invoke(this, &CrosNetworkFunctionsTest::OnGetProperties));
-
- CrosRequestNetworkServiceProperties(
- service_path,
- MockNetworkPropertiesCallback::CreateCallback(service_path, result));
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkDeviceProperties) {
- const std::string device_path = "/device/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, new base::StringValue(value1));
- result.SetWithoutPathExpansion(key2, new base::StringValue(value2));
- // Set expectations.
- dictionary_value_result_ = &result;
- EXPECT_CALL(*mock_device_client_,
- GetProperties(dbus::ObjectPath(device_path), _)).WillOnce(
- Invoke(this, &CrosNetworkFunctionsTest::OnGetProperties));
-
- CrosRequestNetworkDeviceProperties(
- device_path,
- MockNetworkPropertiesCallback::CreateCallback(device_path, result));
-}
-
-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, new base::StringValue(value1));
- result.SetWithoutPathExpansion(key2, new base::StringValue(value2));
- // Set expectations.
- dictionary_value_result_ = &result;
- EXPECT_CALL(
- *mock_profile_client_,
- GetProperties(dbus::ObjectPath(profile_path), _, _)).WillOnce(
- Invoke(this,
- &CrosNetworkFunctionsTest::OnGetPropertiesWithoutStatus));
-
- CrosRequestNetworkProfileProperties(
- profile_path,
- MockNetworkPropertiesCallback::CreateCallback(profile_path, 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, new base::StringValue(value1));
- result.SetWithoutPathExpansion(key2, new base::StringValue(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, profile_entry_path,
- MockNetworkPropertiesCallback::CreateCallback(profile_entry_path,
- result));
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosRequestHiddenWifiNetworkProperties) {
- const std::string ssid = "ssid";
- const std::string security = "security";
- 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, new base::StringValue(value1));
- result.SetWithoutPathExpansion(key2, new base::StringValue(value2));
- dictionary_value_result_ = &result;
- // Create expected argument to ShillManagerClient::GetService.
- base::DictionaryValue properties;
- properties.SetWithoutPathExpansion(
- flimflam::kModeProperty,
- new base::StringValue(flimflam::kModeManaged));
- properties.SetWithoutPathExpansion(
- flimflam::kTypeProperty,
- new base::StringValue(flimflam::kTypeWifi));
- properties.SetWithoutPathExpansion(
- flimflam::kSSIDProperty,
- new base::StringValue(ssid));
- properties.SetWithoutPathExpansion(
- flimflam::kSecurityProperty,
- new base::StringValue(security));
- // Set expectations.
- const dbus::ObjectPath service_path("/service/path");
- ObjectPathCallback callback;
- EXPECT_CALL(*mock_manager_client_, GetService(IsEqualTo(&properties), _, _))
- .WillOnce(SaveArg<1>(&callback));
- EXPECT_CALL(*mock_service_client_,
- GetProperties(service_path, _)).WillOnce(
- Invoke(this, &CrosNetworkFunctionsTest::OnGetProperties));
-
- // Call function.
- CrosRequestHiddenWifiNetworkProperties(
- ssid, security,
- MockNetworkPropertiesCallback::CreateCallback(service_path.value(),
- result));
- // Run callback to invoke GetProperties.
- callback.Run(service_path);
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosRequestVirtualNetworkProperties) {
- const std::string service_name = "service name";
- const std::string server_hostname = "server hostname";
- const std::string provider_type = "provider type";
- 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, new base::StringValue(value1));
- result.SetWithoutPathExpansion(key2, new base::StringValue(value2));
- dictionary_value_result_ = &result;
- // Create expected argument to ShillManagerClient::ConfigureService.
- base::DictionaryValue properties;
- properties.SetWithoutPathExpansion(
- flimflam::kTypeProperty, new base::StringValue("vpn"));
- properties.SetWithoutPathExpansion(
- flimflam::kNameProperty,
- new base::StringValue(service_name));
- properties.SetWithoutPathExpansion(
- flimflam::kProviderHostProperty,
- new base::StringValue(server_hostname));
- properties.SetWithoutPathExpansion(
- flimflam::kProviderTypeProperty,
- new base::StringValue(provider_type));
-
- // Set expectations.
- const dbus::ObjectPath service_path("/service/path");
- ObjectPathCallback callback;
- EXPECT_CALL(*mock_manager_client_,
- ConfigureService(IsEqualTo(&properties), _, _))
- .WillOnce(SaveArg<1>(&callback));
- EXPECT_CALL(*mock_service_client_,
- GetProperties(service_path, _)).WillOnce(
- Invoke(this, &CrosNetworkFunctionsTest::OnGetProperties));
-
- // Call function.
- CrosRequestVirtualNetworkProperties(
- service_name, server_hostname, provider_type,
- MockNetworkPropertiesCallback::CreateCallback(service_path.value(),
- result));
- // Run callback to invoke GetProperties.
- callback.Run(service_path);
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkServiceDisconnect) {
- const std::string service_path = "/service/path";
- EXPECT_CALL(*mock_service_client_,
- Disconnect(dbus::ObjectPath(service_path), _, _)).Times(1);
- CrosRequestNetworkServiceDisconnect(service_path);
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosRequestRemoveNetworkService) {
- const std::string service_path = "/service/path";
- EXPECT_CALL(*mock_service_client_,
- Remove(dbus::ObjectPath(service_path), _, _)).Times(1);
- CrosRequestRemoveNetworkService(service_path);
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkScan) {
- EXPECT_CALL(*mock_manager_client_,
- RequestScan(flimflam::kTypeWifi, _, _)).Times(1);
- CrosRequestNetworkScan(flimflam::kTypeWifi);
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkDeviceEnable) {
- const bool kEnable = true;
- EXPECT_CALL(*mock_manager_client_,
- EnableTechnology(flimflam::kTypeWifi, _, _)).Times(1);
- CrosRequestNetworkDeviceEnable(flimflam::kTypeWifi, kEnable);
-
- const bool kDisable = false;
- EXPECT_CALL(*mock_manager_client_,
- DisableTechnology(flimflam::kTypeWifi, _, _)).Times(1);
- CrosRequestNetworkDeviceEnable(flimflam::kTypeWifi, kDisable);
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosRequestRequirePin) {
- const std::string device_path = "/device/path";
- const std::string pin = "123456";
- const bool kRequire = true;
-
- // Set expectations.
- base::Closure callback;
- EXPECT_CALL(*mock_device_client_,
- RequirePin(dbus::ObjectPath(device_path), pin, kRequire, _, _))
- .WillOnce(SaveArg<3>(&callback));
- EXPECT_CALL(*this, MockNetworkOperationCallback(
- device_path, NETWORK_METHOD_ERROR_NONE, _)).Times(1);
- CrosRequestRequirePin(
- device_path, pin, kRequire,
- base::Bind(&CrosNetworkFunctionsTest::MockNetworkOperationCallback,
- base::Unretained(this)));
- // Run saved callback.
- callback.Run();
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosRequestEnterPin) {
- const std::string device_path = "/device/path";
- const std::string pin = "123456";
-
- // Set expectations.
- base::Closure callback;
- EXPECT_CALL(*mock_device_client_,
- EnterPin(dbus::ObjectPath(device_path), pin, _, _))
- .WillOnce(SaveArg<2>(&callback));
- EXPECT_CALL(*this, MockNetworkOperationCallback(
- device_path, NETWORK_METHOD_ERROR_NONE, _)).Times(1);
- CrosRequestEnterPin(
- device_path, pin,
- base::Bind(&CrosNetworkFunctionsTest::MockNetworkOperationCallback,
- base::Unretained(this)));
- // Run saved callback.
- callback.Run();
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosRequestUnblockPin) {
- const std::string device_path = "/device/path";
- const std::string unblock_code = "987654";
- const std::string pin = "123456";
-
- // Set expectations.
- base::Closure callback;
- EXPECT_CALL(
- *mock_device_client_,
- UnblockPin(dbus::ObjectPath(device_path), unblock_code, pin, _, _))
- .WillOnce(SaveArg<3>(&callback));
- EXPECT_CALL(*this, MockNetworkOperationCallback(
- device_path, NETWORK_METHOD_ERROR_NONE, _)).Times(1);
- CrosRequestUnblockPin(device_path, unblock_code, pin,
- base::Bind(&CrosNetworkFunctionsTest::MockNetworkOperationCallback,
- base::Unretained(this)));
- // Run saved callback.
- callback.Run();
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosRequestChangePin) {
- const std::string device_path = "/device/path";
- const std::string old_pin = "123456";
- const std::string new_pin = "234567";
-
- // Set expectations.
- base::Closure callback;
- EXPECT_CALL(*mock_device_client_,
- ChangePin(dbus::ObjectPath(device_path), old_pin, new_pin, _, _))
- .WillOnce(SaveArg<3>(&callback));
- EXPECT_CALL(*this, MockNetworkOperationCallback(
- device_path, NETWORK_METHOD_ERROR_NONE, _)).Times(1);
- CrosRequestChangePin(device_path, old_pin, new_pin,
- base::Bind(&CrosNetworkFunctionsTest::MockNetworkOperationCallback,
- base::Unretained(this)));
- // Run saved callback.
- callback.Run();
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosProposeScan) {
- const std::string device_path = "/device/path";
- EXPECT_CALL(*mock_device_client_,
- ProposeScan(dbus::ObjectPath(device_path), _)).Times(1);
- CrosProposeScan(device_path);
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosRequestCellularRegister) {
- const std::string device_path = "/device/path";
- const std::string network_id = "networkid";
-
- // Set expectations.
- base::Closure callback;
- EXPECT_CALL(*mock_device_client_,
- Register(dbus::ObjectPath(device_path), network_id, _, _))
- .WillOnce(SaveArg<2>(&callback));
- EXPECT_CALL(*this, MockNetworkOperationCallback(
- device_path, NETWORK_METHOD_ERROR_NONE, _)).Times(1);
- CrosRequestCellularRegister(device_path, network_id,
- base::Bind(&CrosNetworkFunctionsTest::MockNetworkOperationCallback,
- base::Unretained(this)));
- // Run saved callback.
- callback.Run();
-}
-
-TEST_F(CrosNetworkFunctionsTest, CrosConfigureService) {
- const std::string key1 = "key1";
- const std::string string1 = "string1";
- const std::string key2 = "key2";
- const std::string string2 = "string2";
- base::DictionaryValue value;
- value.SetString(key1, string1);
- value.SetString(key2, string2);
- EXPECT_CALL(*mock_manager_client_, ConfigureService(IsEqualTo(&value), _, _))
- .Times(1);
- CrosConfigureService(value);
-}
-
-} // namespace chromeos
diff --git a/chromeos/network/sms_watcher.cc b/chromeos/network/sms_watcher.cc
deleted file mode 100644
index ee3127e..0000000
--- a/chromeos/network/sms_watcher.cc
+++ /dev/null
@@ -1,409 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chromeos/network/sms_watcher.h"
-
-#include <algorithm>
-#include <deque>
-#include <string>
-#include <vector>
-
-#include "base/bind.h"
-#include "base/values.h"
-#include "chromeos/dbus/dbus_thread_manager.h"
-#include "chromeos/dbus/gsm_sms_client.h"
-#include "chromeos/dbus/modem_messaging_client.h"
-#include "chromeos/dbus/shill_device_client.h"
-#include "chromeos/dbus/sms_client.h"
-#include "third_party/cros_system_api/dbus/service_constants.h"
-
-namespace chromeos {
-
-namespace {
-
-int decode_bcd(const char *s) {
- return (s[0] - '0') * 10 + s[1] - '0';
-}
-
-void decode_timestamp(const std::string& sms_timestamp, SMS *sms) {
- base::Time::Exploded exp;
- exp.year = decode_bcd(&sms_timestamp[0]);
- if (exp.year > 95)
- exp.year += 1900;
- else
- exp.year += 2000;
- exp.month = decode_bcd(&sms_timestamp[2]);
- exp.day_of_month = decode_bcd(&sms_timestamp[4]);
- exp.hour = decode_bcd(&sms_timestamp[6]);
- exp.minute = decode_bcd(&sms_timestamp[8]);
- exp.second = decode_bcd(&sms_timestamp[10]);
- exp.millisecond = 0;
- sms->timestamp = base::Time::FromUTCExploded(exp);
- int hours = decode_bcd(&sms_timestamp[13]);
- if (sms_timestamp[12] == '-')
- hours = -hours;
- sms->timestamp -= base::TimeDelta::FromHours(hours);
-}
-
-// Callback for Delete() method. This method does nothing.
-void DeleteSMSCallback() {}
-
-} // namespace
-
-const char SMSWatcher::kNumberKey[] = "number";
-const char SMSWatcher::kTextKey[] = "text";
-const char SMSWatcher::kTimestampKey[] = "timestamp";
-const char SMSWatcher::kSmscKey[] = "smsc";
-const char SMSWatcher::kValidityKey[] = "validity";
-const char SMSWatcher::kClassKey[] = "class";
-const char SMSWatcher::kIndexKey[] = "index";
-
-const char SMSWatcher::kModemManager1NumberKey[] = "Number";
-const char SMSWatcher::kModemManager1TextKey[] = "Text";
-const char SMSWatcher::kModemManager1TimestampKey[] = "Timestamp";
-const char SMSWatcher::kModemManager1SmscKey[] = "Smsc";
-const char SMSWatcher::kModemManager1ValidityKey[] = "Validity";
-const char SMSWatcher::kModemManager1ClassKey[] = "Class";
-const char SMSWatcher::kModemManager1IndexKey[] = "Index";
-
-class SMSWatcher::WatcherBase {
- public:
- WatcherBase(const std::string& device_path,
- MonitorSMSCallback callback,
- const std::string& dbus_connection,
- const dbus::ObjectPath& object_path) :
- device_path_(device_path),
- callback_(callback),
- dbus_connection_(dbus_connection),
- object_path_(object_path) {}
-
- virtual ~WatcherBase() {}
-
- protected:
- const std::string device_path_;
- MonitorSMSCallback callback_;
- const std::string dbus_connection_;
- const dbus::ObjectPath object_path_;
-
- DISALLOW_COPY_AND_ASSIGN(WatcherBase);
-};
-
-namespace {
-
-class GsmWatcher : public SMSWatcher::WatcherBase {
- public:
- GsmWatcher(const std::string& device_path,
- MonitorSMSCallback callback,
- const std::string& dbus_connection,
- const dbus::ObjectPath& object_path)
- : WatcherBase(device_path, callback, dbus_connection, object_path),
- weak_ptr_factory_(this) {
- DBusThreadManager::Get()->GetGsmSMSClient()->SetSmsReceivedHandler(
- dbus_connection_,
- object_path_,
- base::Bind(&GsmWatcher::OnSmsReceived, weak_ptr_factory_.GetWeakPtr()));
-
- DBusThreadManager::Get()->GetGsmSMSClient()->List(
- dbus_connection_, object_path_,
- base::Bind(&GsmWatcher::ListSMSCallback,
- weak_ptr_factory_.GetWeakPtr()));
- }
-
- virtual ~GsmWatcher() {
- DBusThreadManager::Get()->GetGsmSMSClient()->ResetSmsReceivedHandler(
- dbus_connection_, object_path_);
- }
-
- private:
- // Callback for SmsReceived signal from ModemManager.Modem.Gsm.SMS
- void OnSmsReceived(uint32 index, bool complete) {
- // Only handle complete messages.
- if (!complete)
- return;
- DBusThreadManager::Get()->GetGsmSMSClient()->Get(
- dbus_connection_, object_path_, index,
- base::Bind(&GsmWatcher::GetSMSCallback,
- weak_ptr_factory_.GetWeakPtr(),
- index));
- }
-
- // Runs |callback_| with a SMS.
- void RunCallbackWithSMS(const base::DictionaryValue& sms_dictionary) {
- SMS sms;
-
- if (!sms_dictionary.GetStringWithoutPathExpansion(SMSWatcher::kNumberKey,
- &sms.number))
- LOG(WARNING) << "SMS did not contain a number";
-
- if (!sms_dictionary.GetStringWithoutPathExpansion(SMSWatcher::kTextKey,
- &sms.text))
- LOG(WARNING) << "SMS did not contain message text";
-
- std::string sms_timestamp;
- if (sms_dictionary.GetStringWithoutPathExpansion(SMSWatcher::kTimestampKey,
- &sms_timestamp)) {
- decode_timestamp(sms_timestamp, &sms);
- } else {
- LOG(WARNING) << "SMS did not contain a timestamp";
- sms.timestamp = base::Time();
- }
-
- sms_dictionary.GetStringWithoutPathExpansion(SMSWatcher::kSmscKey,
- &sms.smsc);
-
- double validity = 0;
- if (!sms_dictionary.GetDoubleWithoutPathExpansion(SMSWatcher::kValidityKey,
- &validity)) {
- validity = -1;
- }
- sms.validity = validity;
-
- double msgclass = 0;
- if (!sms_dictionary.GetDoubleWithoutPathExpansion(SMSWatcher::kClassKey,
- &msgclass)) {
- msgclass = -1;
- }
- sms.msgclass = msgclass;
-
- callback_.Run(device_path_, sms);
- }
-
- // Callback for Get() method from ModemManager.Modem.Gsm.SMS
- void GetSMSCallback(uint32 index,
- const base::DictionaryValue& sms_dictionary) {
- RunCallbackWithSMS(sms_dictionary);
-
- DBusThreadManager::Get()->GetGsmSMSClient()->Delete(
- dbus_connection_, object_path_, index, base::Bind(&DeleteSMSCallback));
- }
-
- // Callback for List() method.
- void ListSMSCallback(const base::ListValue& result) {
- // List() is called only once; no one touches delete_queue_ before List().
- CHECK(delete_queue_.empty());
- for (size_t i = 0; i != result.GetSize(); ++i) {
- const base::DictionaryValue* sms_dictionary = NULL;
- if (!result.GetDictionary(i, &sms_dictionary)) {
- LOG(ERROR) << "result[" << i << "] is not a dictionary.";
- continue;
- }
- RunCallbackWithSMS(*sms_dictionary);
- double index = 0;
- if (sms_dictionary->GetDoubleWithoutPathExpansion(SMSWatcher::kIndexKey,
- &index)) {
- delete_queue_.push_back(index);
- }
- }
- DeleteSMSInChain();
- }
-
- // Deletes SMSs in the queue.
- void DeleteSMSInChain() {
- if (!delete_queue_.empty()) {
- DBusThreadManager::Get()->GetGsmSMSClient()->Delete(
- dbus_connection_, object_path_, delete_queue_.back(),
- base::Bind(&GsmWatcher::DeleteSMSInChain,
- weak_ptr_factory_.GetWeakPtr()));
- delete_queue_.pop_back();
- }
- }
-
- base::WeakPtrFactory<GsmWatcher> weak_ptr_factory_;
- std::vector<uint32> delete_queue_;
-
- DISALLOW_COPY_AND_ASSIGN(GsmWatcher);
-};
-
-class ModemManager1Watcher : public SMSWatcher::WatcherBase {
- public:
- ModemManager1Watcher(const std::string& device_path,
- MonitorSMSCallback callback,
- const std::string& dbus_connection,
- const dbus::ObjectPath& object_path)
- : WatcherBase(device_path, callback, dbus_connection, object_path),
- weak_ptr_factory_(this),
- deleting_messages_(false),
- retrieving_messages_(false) {
- DBusThreadManager::Get()->GetModemMessagingClient()->SetSmsReceivedHandler(
- dbus_connection_,
- object_path_,
- base::Bind(&ModemManager1Watcher::OnSmsReceived,
- weak_ptr_factory_.GetWeakPtr()));
-
- DBusThreadManager::Get()->GetModemMessagingClient()->List(
- dbus_connection_, object_path_,
- base::Bind(&ModemManager1Watcher::ListSMSCallback,
- weak_ptr_factory_.GetWeakPtr()));
- }
-
- virtual ~ModemManager1Watcher() {
- DBusThreadManager::Get()->GetModemMessagingClient()
- ->ResetSmsReceivedHandler(dbus_connection_, object_path_);
- }
-
- private:
- void ListSMSCallback(
- const std::vector<dbus::ObjectPath>& paths) {
- // This receives all messages, so clear any pending gets and deletes.
- retrieval_queue_.clear();
- delete_queue_.clear();
-
- retrieval_queue_.resize(paths.size());
- std::copy(paths.begin(), paths.end(), retrieval_queue_.begin());
- if (!retrieving_messages_)
- GetMessages();
- }
-
- // Messages must be deleted one at a time, since we can not
- // guarantee the order the deletion will be executed in. Delete
- // messages from the back of the list so that the indices are
- // valid.
- void DeleteMessages() {
- if (delete_queue_.empty()) {
- deleting_messages_ = false;
- return;
- }
- deleting_messages_ = true;
- dbus::ObjectPath sms_path = delete_queue_.back();
- delete_queue_.pop_back();
- DBusThreadManager::Get()->GetModemMessagingClient()->Delete(
- dbus_connection_, object_path_, sms_path,
- base::Bind(&ModemManager1Watcher::DeleteMessages,
- weak_ptr_factory_.GetWeakPtr()));
- }
-
- // Messages must be fetched one at a time, so that we do not queue too
- // many requests to a single threaded server.
- void GetMessages() {
- if (retrieval_queue_.empty()) {
- retrieving_messages_ = false;
- if (!deleting_messages_)
- DeleteMessages();
- return;
- }
- retrieving_messages_ = true;
- dbus::ObjectPath sms_path = retrieval_queue_.front();
- retrieval_queue_.pop_front();
- DBusThreadManager::Get()->GetSMSClient()->GetAll(
- dbus_connection_, sms_path,
- base::Bind(&ModemManager1Watcher::GetCallback,
- weak_ptr_factory_.GetWeakPtr()));
- delete_queue_.push_back(sms_path);
- }
-
- // Handles arrival of a new SMS message.
- void OnSmsReceived(const dbus::ObjectPath& sms_path, bool complete) {
- // Only handle complete messages.
- if (!complete)
- return;
- retrieval_queue_.push_back(sms_path);
- if (!retrieving_messages_)
- GetMessages();
- }
-
- // Runs |callback_| with a SMS.
- void RunCallbackWithSMS(const base::DictionaryValue& sms_dictionary) {
- SMS sms;
-
- if (!sms_dictionary.GetStringWithoutPathExpansion(
- SMSWatcher::kModemManager1NumberKey, &sms.number))
- LOG(WARNING) << "SMS did not contain a number";
-
- if (!sms_dictionary.GetStringWithoutPathExpansion(
- SMSWatcher::kModemManager1TextKey, &sms.text))
- LOG(WARNING) << "SMS did not contain message text";
-
- std::string sms_timestamp;
- if (sms_dictionary.GetStringWithoutPathExpansion(
- SMSWatcher::kModemManager1TimestampKey, &sms_timestamp)) {
- decode_timestamp(sms_timestamp, &sms);
- } else {
- LOG(WARNING) << "SMS did not contain a timestamp";
- sms.timestamp = base::Time();
- }
-
- sms_dictionary.GetStringWithoutPathExpansion(
- SMSWatcher::kModemManager1SmscKey, &sms.smsc);
-
- double validity = 0;
- if (!sms_dictionary.GetDoubleWithoutPathExpansion(
- SMSWatcher::kModemManager1ValidityKey, &validity)) {
- validity = -1;
- }
- sms.validity = validity;
-
- double msgclass = 0;
- if (!sms_dictionary.GetDoubleWithoutPathExpansion(
- SMSWatcher::kModemManager1ClassKey, &msgclass)) {
- msgclass = -1;
- }
- sms.msgclass = msgclass;
-
- callback_.Run(device_path_, sms);
- }
-
- void GetCallback(const base::DictionaryValue& dictionary) {
- RunCallbackWithSMS(dictionary);
- GetMessages();
- }
-
- base::WeakPtrFactory<ModemManager1Watcher> weak_ptr_factory_;
- bool deleting_messages_;
- bool retrieving_messages_;
- std::vector<dbus::ObjectPath> delete_queue_;
- std::deque<dbus::ObjectPath> retrieval_queue_;
-
- DISALLOW_COPY_AND_ASSIGN(ModemManager1Watcher);
-};
-
-} // namespace
-
-SMSWatcher::SMSWatcher(const std::string& modem_device_path,
- MonitorSMSCallback callback)
- : weak_ptr_factory_(this),
- device_path_(modem_device_path),
- callback_(callback) {
- DBusThreadManager::Get()->GetShillDeviceClient()->GetProperties(
- dbus::ObjectPath(modem_device_path),
- base::Bind(&SMSWatcher::DevicePropertiesCallback,
- weak_ptr_factory_.GetWeakPtr()));
-}
-
-SMSWatcher::~SMSWatcher() {
-}
-
-void SMSWatcher::DevicePropertiesCallback(
- DBusMethodCallStatus call_status,
- const base::DictionaryValue& properties) {
- if (call_status != DBUS_METHOD_CALL_SUCCESS)
- return;
-
- std::string dbus_connection;
- if (!properties.GetStringWithoutPathExpansion(
- flimflam::kDBusConnectionProperty, &dbus_connection)) {
- LOG(WARNING) << "Modem device properties do not include DBus connection.";
- return;
- }
-
- std::string object_path_string;
- if (!properties.GetStringWithoutPathExpansion(
- flimflam::kDBusObjectProperty, &object_path_string)) {
- LOG(WARNING) << "Modem device properties do not include DBus object.";
- return;
- }
-
- if (object_path_string.compare(
- 0, sizeof(modemmanager::kModemManager1ServicePath) - 1,
- modemmanager::kModemManager1ServicePath) == 0) {
- watcher_.reset(
- new ModemManager1Watcher(device_path_, callback_, dbus_connection,
- dbus::ObjectPath(object_path_string)));
- } else {
- watcher_.reset(
- new GsmWatcher(device_path_, callback_, dbus_connection,
- dbus::ObjectPath(object_path_string)));
- }
-}
-
-} // namespace chromeos
diff --git a/chromeos/network/sms_watcher.h b/chromeos/network/sms_watcher.h
deleted file mode 100644
index 6e2bc27..0000000
--- a/chromeos/network/sms_watcher.h
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROMEOS_NETWORK_SMS_WATCHER_H_
-#define CHROMEOS_NETWORK_SMS_WATCHER_H_
-
-#include <string>
-#include <vector>
-
-#include "base/memory/weak_ptr.h"
-#include "chromeos/chromeos_export.h"
-#include "chromeos/dbus/dbus_method_call_status.h"
-#include "chromeos/network/cros_network_functions.h"
-#include "dbus/object_path.h"
-
-namespace base {
-
-class DictionaryValue;
-
-} // namespace base
-
-namespace chromeos {
-
-// Class to watch sms without Libcros.
-class CHROMEOS_EXPORT SMSWatcher : public CrosNetworkWatcher {
- public:
- // Dictionary key constants.
- static const char kNumberKey[];
- static const char kTextKey[];
- static const char kTimestampKey[];
- static const char kSmscKey[];
- static const char kValidityKey[];
- static const char kClassKey[];
- static const char kIndexKey[];
-
- static const char kModemManager1NumberKey[];
- static const char kModemManager1TextKey[];
- static const char kModemManager1TimestampKey[];
- static const char kModemManager1SmscKey[];
- static const char kModemManager1ValidityKey[];
- static const char kModemManager1ClassKey[];
- static const char kModemManager1IndexKey[];
-
- // Base class of watcher implementation classes. Public to allow
- // derived classes in the anonymous namespace to inherit from it.
- class WatcherBase;
-
- SMSWatcher(const std::string& modem_device_path,
- MonitorSMSCallback callback);
- virtual ~SMSWatcher();
-
- private:
- // Callback for shill device's GetProperties() method.
- void DevicePropertiesCallback(DBusMethodCallStatus call_status,
- const base::DictionaryValue& properties);
-
- base::WeakPtrFactory<SMSWatcher> weak_ptr_factory_;
- std::string device_path_;
- MonitorSMSCallback callback_;
- scoped_ptr<WatcherBase> watcher_;
-
- DISALLOW_COPY_AND_ASSIGN(SMSWatcher);
-};
-
-} // namespace
-
-#endif // CHROMEOS_NETWORK_SMS_WATCHER_H_