Commit bfe0f65a authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

chromeos/dbus/shill: Additional DictionaryValue cleanup

This removes the remaining DictionaryValue usage from shill client and
fake client classes.

For minor apitest.cc change to c/b/e/api/vpn_provider:
TBR=emaxx@chromium.org

Bug: 1137487
Change-Id: Id3a84f1392f0d1586342b4441ad200f0a41110e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2466931
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarPavol Marko <pmarko@chromium.org>
Reviewed-by: default avatarAzeem Arshad <azeemarshad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818596}
parent c4cbb461
...@@ -26,7 +26,7 @@ const char kNotifierSms[] = "ash.sms"; ...@@ -26,7 +26,7 @@ const char kNotifierSms[] = "ash.sms";
// Send the |message| to notification center to display to users. Note that each // Send the |message| to notification center to display to users. Note that each
// notification will be assigned with different |message_id| as notification id. // notification will be assigned with different |message_id| as notification id.
void ShowNotification(const base::DictionaryValue* message, void ShowNotification(const base::Value* message,
const std::string& message_text, const std::string& message_text,
const std::string& message_number, const std::string& message_number,
int message_id) { int message_id) {
...@@ -69,31 +69,31 @@ SmsObserver::~SmsObserver() { ...@@ -69,31 +69,31 @@ SmsObserver::~SmsObserver() {
} }
} }
void SmsObserver::MessageReceived(const base::DictionaryValue& message) { void SmsObserver::MessageReceived(const base::Value& message) {
std::string message_text; const std::string* message_text =
if (!message.GetStringWithoutPathExpansion( message.FindStringKey(chromeos::NetworkSmsHandler::kTextKey);
chromeos::NetworkSmsHandler::kTextKey, &message_text)) { if (!message_text) {
NET_LOG(ERROR) << "SMS message contains no content."; NET_LOG(ERROR) << "SMS message contains no content.";
return; return;
} }
// TODO(armansito): A message might be due to a special "Message Waiting" // TODO(armansito): A message might be due to a special "Message Waiting"
// state that the message is in. Once SMS handling moves to shill, such // state that the message is in. Once SMS handling moves to shill, such
// messages should be filtered there so that this check becomes unnecessary. // messages should be filtered there so that this check becomes unnecessary.
if (message_text.empty()) { if (message_text->empty()) {
NET_LOG(DEBUG) << "SMS has empty content text. Ignoring."; NET_LOG(DEBUG) << "SMS has empty content text. Ignoring.";
return; return;
} }
std::string message_number; const std::string* message_number =
if (!message.GetStringWithoutPathExpansion( message.FindStringKey(chromeos::NetworkSmsHandler::kNumberKey);
chromeos::NetworkSmsHandler::kNumberKey, &message_number)) { if (!message_number) {
NET_LOG(DEBUG) << "SMS contains no number. Ignoring."; NET_LOG(DEBUG) << "SMS contains no number. Ignoring.";
return; return;
} }
NET_LOG(DEBUG) << "Received SMS from: " << message_number NET_LOG(DEBUG) << "Received SMS from: " << *message_number
<< " with text: " << message_text; << " with text: " << *message_text;
message_id_++; message_id_++;
ShowNotification(&message, message_text, message_number, message_id_); ShowNotification(&message, *message_text, *message_number, message_id_);
} }
} // namespace ash } // namespace ash
...@@ -7,10 +7,6 @@ ...@@ -7,10 +7,6 @@
#include "chromeos/network/network_sms_handler.h" #include "chromeos/network/network_sms_handler.h"
namespace base {
class DictionaryValue;
}
namespace ash { namespace ash {
// SmsObserver is called when a new sms message is received. Then it shows the // SmsObserver is called when a new sms message is received. Then it shows the
...@@ -21,7 +17,7 @@ class SmsObserver : public chromeos::NetworkSmsHandler::Observer { ...@@ -21,7 +17,7 @@ class SmsObserver : public chromeos::NetworkSmsHandler::Observer {
~SmsObserver() override; ~SmsObserver() override;
// chromeos::NetworkSmsHandler::Observer: // chromeos::NetworkSmsHandler::Observer:
void MessageReceived(const base::DictionaryValue& message) override; void MessageReceived(const base::Value& message) override;
private: private:
// Used to create notification identifier. // Used to create notification identifier.
......
...@@ -77,11 +77,11 @@ class TestShillThirdPartyVpnDriverClient ...@@ -77,11 +77,11 @@ class TestShillThirdPartyVpnDriverClient
: public FakeShillThirdPartyVpnDriverClient { : public FakeShillThirdPartyVpnDriverClient {
public: public:
void SetParameters(const std::string& object_path_value, void SetParameters(const std::string& object_path_value,
const base::DictionaryValue& parameters, const base::Value& parameters,
StringCallback callback, StringCallback callback,
ErrorCallback error_callback) override { ErrorCallback error_callback) override {
set_parameters_counter_++; set_parameters_counter_++;
parameters_ = parameters.DeepCopy(); parameters_ = parameters.Clone();
FakeShillThirdPartyVpnDriverClient::SetParameters( FakeShillThirdPartyVpnDriverClient::SetParameters(
object_path_value, parameters, std::move(callback), object_path_value, parameters, std::move(callback),
std::move(error_callback)); std::move(error_callback));
...@@ -110,7 +110,7 @@ class TestShillThirdPartyVpnDriverClient ...@@ -110,7 +110,7 @@ class TestShillThirdPartyVpnDriverClient
} }
int set_parameters_counter_ = 0; int set_parameters_counter_ = 0;
base::DictionaryValue* parameters_ = nullptr; base::Value parameters_;
int update_connection_state_counter_ = 0; int update_connection_state_counter_ = 0;
uint32_t connection_state_; uint32_t connection_state_;
int send_packet_counter_ = 0; int send_packet_counter_ = 0;
...@@ -288,10 +288,10 @@ IN_PROC_BROWSER_TEST_F(VpnProviderApiTest, VpnSuccess) { ...@@ -288,10 +288,10 @@ IN_PROC_BROWSER_TEST_F(VpnProviderApiTest, VpnSuccess) {
EXPECT_EQ(api_vpn::VPN_CONNECTION_STATE_CONNECTED, EXPECT_EQ(api_vpn::VPN_CONNECTION_STATE_CONNECTED,
test_client_->update_connection_state_counter_); test_client_->update_connection_state_counter_);
for (size_t i = 0; i < base::size(kParameterValues); ++i) { for (size_t i = 0; i < base::size(kParameterValues); ++i) {
std::string value; const std::string* value =
EXPECT_TRUE( test_client_->parameters_.FindStringKey(kParameterKeys[i]);
test_client_->parameters_->GetString(kParameterKeys[i], &value)); ASSERT_TRUE(value);
EXPECT_EQ(kParameterValues[i], value); EXPECT_EQ(kParameterValues[i], *value);
} }
const char kPacket[] = "feebdaed"; const char kPacket[] = "feebdaed";
std::vector<char> packet(&kPacket[0], &kPacket[8]); std::vector<char> packet(&kPacket[0], &kPacket[8]);
......
...@@ -26,9 +26,11 @@ ...@@ -26,9 +26,11 @@
namespace chromeos { namespace chromeos {
struct FakeShillProfileClient::ProfileProperties { struct FakeShillProfileClient::ProfileProperties {
std::string path; // Profile path std::string profile_path;
base::DictionaryValue entries; // Dictionary of Service Dictionaries // Dictionary of Service Dictionaries
base::DictionaryValue properties; // Dictionary of Profile properties base::Value entries{base::Value::Type::DICTIONARY};
// Dictionary of Profile properties
base::Value properties{base::Value::Type::DICTIONARY};
}; };
FakeShillProfileClient::FakeShillProfileClient() = default; FakeShillProfileClient::FakeShillProfileClient() = default;
...@@ -141,10 +143,10 @@ void FakeShillProfileClient::AddProfile(const std::string& profile_path, ...@@ -141,10 +143,10 @@ void FakeShillProfileClient::AddProfile(const std::string& profile_path,
CHECK(profile_path != GetSharedProfilePath() || profiles_.empty()) CHECK(profile_path != GetSharedProfilePath() || profiles_.empty())
<< "Shared profile must be added before any user profile."; << "Shared profile must be added before any user profile.";
auto profile = std::make_unique<ProfileProperties>(); ProfileProperties profile;
profile->properties.SetKey(shill::kUserHashProperty, base::Value(userhash)); profile.properties.SetKey(shill::kUserHashProperty, base::Value(userhash));
profile->path = profile_path; profile.profile_path = profile_path;
profiles_.emplace_back(std::move(profile)); profiles_.push_back(std::move(profile));
ShillManagerClient::Get()->GetTestInterface()->AddProfile(profile_path); ShillManagerClient::Get()->GetTestInterface()->AddProfile(profile_path);
} }
...@@ -167,7 +169,7 @@ bool FakeShillProfileClient::AddService(const std::string& profile_path, ...@@ -167,7 +169,7 @@ bool FakeShillProfileClient::AddService(const std::string& profile_path,
<< " for: " << service_path; << " for: " << service_path;
return false; return false;
} }
if (profile->entries.HasKey(service_path)) if (profile->entries.FindKey(service_path))
return false; return false;
return AddOrUpdateServiceImpl(profile_path, service_path, profile); return AddOrUpdateServiceImpl(profile_path, service_path, profile);
} }
...@@ -180,7 +182,7 @@ bool FakeShillProfileClient::UpdateService(const std::string& profile_path, ...@@ -180,7 +182,7 @@ bool FakeShillProfileClient::UpdateService(const std::string& profile_path,
<< " for: " << service_path; << " for: " << service_path;
return false; return false;
} }
if (!profile->entries.HasKey(service_path)) { if (!profile->entries.FindKey(service_path)) {
LOG(ERROR) << "UpdateService: Profile: " << profile_path LOG(ERROR) << "UpdateService: Profile: " << profile_path
<< " does not contain Service: " << service_path; << " does not contain Service: " << service_path;
return false; return false;
...@@ -219,16 +221,16 @@ bool FakeShillProfileClient::AddOrUpdateServiceImpl( ...@@ -219,16 +221,16 @@ bool FakeShillProfileClient::AddOrUpdateServiceImpl(
void FakeShillProfileClient::GetProfilePaths( void FakeShillProfileClient::GetProfilePaths(
std::vector<std::string>* profiles) { std::vector<std::string>* profiles) {
for (const auto& profile : profiles_) for (const auto& profile : profiles_)
profiles->push_back(profile->path); profiles->push_back(profile.profile_path);
} }
void FakeShillProfileClient::GetProfilePathsContainingService( void FakeShillProfileClient::GetProfilePathsContainingService(
const std::string& service_path, const std::string& service_path,
std::vector<std::string>* profiles) { std::vector<std::string>* profiles) {
for (const auto& profile : profiles_) { for (const auto& profile : profiles_) {
if (profile->entries.FindKeyOfType(service_path, if (profile.entries.FindKeyOfType(service_path,
base::Value::Type::DICTIONARY)) { base::Value::Type::DICTIONARY)) {
profiles->push_back(profile->path); profiles->push_back(profile.profile_path);
} }
} }
} }
...@@ -239,10 +241,10 @@ base::Value FakeShillProfileClient::GetService(const std::string& service_path, ...@@ -239,10 +241,10 @@ base::Value FakeShillProfileClient::GetService(const std::string& service_path,
// Returns the entry added latest. // Returns the entry added latest.
for (const auto& profile : base::Reversed(profiles_)) { for (const auto& profile : base::Reversed(profiles_)) {
const base::Value* entry = profile->entries.FindDictKey(service_path); const base::Value* entry = profile.entries.FindDictKey(service_path);
if (!entry) if (!entry)
continue; continue;
*profile_path = profile->path; *profile_path = profile.profile_path;
return entry->Clone(); return entry->Clone();
} }
return base::Value(); return base::Value();
...@@ -250,8 +252,8 @@ base::Value FakeShillProfileClient::GetService(const std::string& service_path, ...@@ -250,8 +252,8 @@ base::Value FakeShillProfileClient::GetService(const std::string& service_path,
bool FakeShillProfileClient::HasService(const std::string& service_path) { bool FakeShillProfileClient::HasService(const std::string& service_path) {
for (const auto& profile : profiles_) { for (const auto& profile : profiles_) {
if (profile->entries.FindKeyOfType(service_path, if (profile.entries.FindKeyOfType(service_path,
base::Value::Type::DICTIONARY)) { base::Value::Type::DICTIONARY)) {
return true; return true;
} }
} }
...@@ -271,8 +273,8 @@ void FakeShillProfileClient::SetSimulateDeleteResult( ...@@ -271,8 +273,8 @@ void FakeShillProfileClient::SetSimulateDeleteResult(
FakeShillProfileClient::ProfileProperties* FakeShillProfileClient::GetProfile( FakeShillProfileClient::ProfileProperties* FakeShillProfileClient::GetProfile(
const dbus::ObjectPath& profile_path) { const dbus::ObjectPath& profile_path) {
for (auto& profile : profiles_) { for (auto& profile : profiles_) {
if (profile->path == profile_path.value()) if (profile.profile_path == profile_path.value())
return profile.get(); return &profile;
} }
return nullptr; return nullptr;
} }
......
...@@ -74,10 +74,9 @@ class COMPONENT_EXPORT(SHILL_CLIENT) FakeShillProfileClient ...@@ -74,10 +74,9 @@ class COMPONENT_EXPORT(SHILL_CLIENT) FakeShillProfileClient
ProfileProperties* GetProfile(const dbus::ObjectPath& profile_path); ProfileProperties* GetProfile(const dbus::ObjectPath& profile_path);
// List of profiles known to the client in order they were added, and in the // List of profiles known to the client in order they were added, and in the
// reverse order of priority. // reverse order of priority. |AddProfile| will ensure that shared profile is
// |AddProfile| will encure that shared profile is never added after a user // never added after a user profile.
// profile. std::vector<ProfileProperties> profiles_;
std::vector<std::unique_ptr<ProfileProperties>> profiles_;
FakeShillSimulatedResult simulate_delete_result_ = FakeShillSimulatedResult simulate_delete_result_ =
FakeShillSimulatedResult::kSuccess; FakeShillSimulatedResult::kSuccess;
......
...@@ -43,7 +43,7 @@ void FakeShillThirdPartyVpnDriverClient::RemoveShillThirdPartyVpnObserver( ...@@ -43,7 +43,7 @@ void FakeShillThirdPartyVpnDriverClient::RemoveShillThirdPartyVpnObserver(
void FakeShillThirdPartyVpnDriverClient::SetParameters( void FakeShillThirdPartyVpnDriverClient::SetParameters(
const std::string& object_path_value, const std::string& object_path_value,
const base::DictionaryValue& parameters, const base::Value& parameters,
StringCallback callback, StringCallback callback,
ErrorCallback error_callback) { ErrorCallback error_callback) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
......
...@@ -35,7 +35,7 @@ class COMPONENT_EXPORT(SHILL_CLIENT) FakeShillThirdPartyVpnDriverClient ...@@ -35,7 +35,7 @@ class COMPONENT_EXPORT(SHILL_CLIENT) FakeShillThirdPartyVpnDriverClient
void RemoveShillThirdPartyVpnObserver( void RemoveShillThirdPartyVpnObserver(
const std::string& object_path_value) override; const std::string& object_path_value) override;
void SetParameters(const std::string& object_path_value, void SetParameters(const std::string& object_path_value,
const base::DictionaryValue& parameters, const base::Value& parameters,
StringCallback callback, StringCallback callback,
ErrorCallback error_callback) override; ErrorCallback error_callback) override;
void UpdateConnectionState(const std::string& object_path_value, void UpdateConnectionState(const std::string& object_path_value,
......
...@@ -27,14 +27,15 @@ void FakeSMSClient::GetAll(const std::string& service_name, ...@@ -27,14 +27,15 @@ void FakeSMSClient::GetAll(const std::string& service_name,
const dbus::ObjectPath& object_path, const dbus::ObjectPath& object_path,
GetAllCallback callback) { GetAllCallback callback) {
if (!base::CommandLine::ForCurrentProcess()->HasSwitch( if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kSmsTestMessages)) chromeos::switches::kSmsTestMessages)) {
return; return;
}
// Ownership passed to callback // Ownership passed to callback
base::DictionaryValue sms; base::Value sms(base::Value::Type::DICTIONARY);
sms.SetString("Number", "000-000-0000"); sms.SetStringKey("Number", "000-000-0000");
sms.SetString("Text", "FakeSMSClient: Test Message: " + object_path.value()); sms.SetStringKey("Text",
sms.SetString("Timestamp", "Fri Jun 8 13:26:04 EDT 2012"); "FakeSMSClient: Test Message: " + object_path.value());
sms.SetStringKey("Timestamp", "Fri Jun 8 13:26:04 EDT 2012");
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), std::move(sms))); FROM_HERE, base::BindOnce(std::move(callback), std::move(sms)));
......
...@@ -55,7 +55,7 @@ class ShillThirdPartyVpnDriverClientImpl ...@@ -55,7 +55,7 @@ class ShillThirdPartyVpnDriverClientImpl
const std::string& object_path_value) override; const std::string& object_path_value) override;
void SetParameters(const std::string& object_path_value, void SetParameters(const std::string& object_path_value,
const base::DictionaryValue& parameters, const base::Value& parameters,
StringCallback callback, StringCallback callback,
ErrorCallback error_callback) override; ErrorCallback error_callback) override;
...@@ -205,7 +205,7 @@ void ShillThirdPartyVpnDriverClientImpl::DeleteHelper( ...@@ -205,7 +205,7 @@ void ShillThirdPartyVpnDriverClientImpl::DeleteHelper(
void ShillThirdPartyVpnDriverClientImpl::SetParameters( void ShillThirdPartyVpnDriverClientImpl::SetParameters(
const std::string& object_path_value, const std::string& object_path_value,
const base::DictionaryValue& parameters, const base::Value& parameters,
StringCallback callback, StringCallback callback,
ErrorCallback error_callback) { ErrorCallback error_callback) {
dbus::MethodCall method_call(shill::kFlimflamThirdPartyVpnInterface, dbus::MethodCall method_call(shill::kFlimflamThirdPartyVpnInterface,
...@@ -213,21 +213,19 @@ void ShillThirdPartyVpnDriverClientImpl::SetParameters( ...@@ -213,21 +213,19 @@ void ShillThirdPartyVpnDriverClientImpl::SetParameters(
dbus::MessageWriter writer(&method_call); dbus::MessageWriter writer(&method_call);
dbus::MessageWriter array_writer(nullptr); dbus::MessageWriter array_writer(nullptr);
writer.OpenArray("{ss}", &array_writer); writer.OpenArray("{ss}", &array_writer);
for (base::DictionaryValue::Iterator it(parameters); !it.IsAtEnd(); for (auto it : parameters.DictItems()) {
it.Advance()) { if (valid_keys_.find(it.first) == valid_keys_.end()) {
if (valid_keys_.find(it.key()) == valid_keys_.end()) { LOG(WARNING) << "Unknown key " << it.first;
LOG(WARNING) << "Unknown key " << it.key();
continue; continue;
} }
std::string value; if (!it.second.is_string()) {
if (!it.value().GetAsString(&value)) { LOG(WARNING) << "Non string value " << it.second;
LOG(WARNING) << "Non string value " << it.value();
continue; continue;
} }
dbus::MessageWriter entry_writer(nullptr); dbus::MessageWriter entry_writer(nullptr);
array_writer.OpenDictEntry(&entry_writer); array_writer.OpenDictEntry(&entry_writer);
entry_writer.AppendString(it.key()); entry_writer.AppendString(it.first);
entry_writer.AppendString(value); entry_writer.AppendString(it.second.GetString());
array_writer.CloseContainer(&entry_writer); array_writer.CloseContainer(&entry_writer);
} }
writer.CloseContainer(&array_writer); writer.CloseContainer(&array_writer);
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
#include "chromeos/dbus/shill/shill_client_helper.h" #include "chromeos/dbus/shill/shill_client_helper.h"
namespace base { namespace base {
class DictionaryValue; class Value;
} // namespace base }
namespace dbus { namespace dbus {
class Bus; class Bus;
...@@ -69,10 +69,11 @@ class COMPONENT_EXPORT(SHILL_CLIENT) ShillThirdPartyVpnDriverClient { ...@@ -69,10 +69,11 @@ class COMPONENT_EXPORT(SHILL_CLIENT) ShillThirdPartyVpnDriverClient {
virtual void RemoveShillThirdPartyVpnObserver( virtual void RemoveShillThirdPartyVpnObserver(
const std::string& object_path_value) = 0; const std::string& object_path_value) = 0;
// Calls SetParameters method. // Calls the SetParameters DBus method for |object_path_value| with
// |callback| is called after the method call succeeds. // |parameters| which must be a dictionary Value. Invokes |callback| on
// success or |error_callback| on failure.
virtual void SetParameters(const std::string& object_path_value, virtual void SetParameters(const std::string& object_path_value,
const base::DictionaryValue& parameters, const base::Value& parameters,
StringCallback callback, StringCallback callback,
ErrorCallback error_callback) = 0; ErrorCallback error_callback) = 0;
......
...@@ -62,10 +62,10 @@ class SMSReceiveHandler { ...@@ -62,10 +62,10 @@ class SMSReceiveHandler {
return; return;
if (number_.is_valid() && text_.is_valid() && timestamp_.is_valid()) { if (number_.is_valid() && text_.is_valid() && timestamp_.is_valid()) {
base::DictionaryValue sms; base::Value sms(base::Value::Type::DICTIONARY);
sms.SetString(SMSClient::kSMSPropertyNumber, number_.value()); sms.SetStringKey(SMSClient::kSMSPropertyNumber, number_.value());
sms.SetString(SMSClient::kSMSPropertyText, text_.value()); sms.SetStringKey(SMSClient::kSMSPropertyText, text_.value());
sms.SetString(SMSClient::kSMSPropertyTimestamp, timestamp_.value()); sms.SetStringKey(SMSClient::kSMSPropertyTimestamp, timestamp_.value());
// Move |callback_| to the task to ensure that |callback_| is only called // Move |callback_| to the task to ensure that |callback_| is only called
// once. Since |callback_| may destruct this object, schedule it to the // once. Since |callback_| may destruct this object, schedule it to the
// task runner to run after this method returns. // task runner to run after this method returns.
...@@ -120,7 +120,7 @@ class SMSClientImpl : public SMSClient { ...@@ -120,7 +120,7 @@ class SMSClientImpl : public SMSClient {
private: private:
void OnSMSReceived(const dbus::ObjectPath& object_path, void OnSMSReceived(const dbus::ObjectPath& object_path,
GetAllCallback callback, GetAllCallback callback,
const base::DictionaryValue& sms) { const base::Value& sms) {
sms_receive_handlers_.erase(object_path); sms_receive_handlers_.erase(object_path);
std::move(callback).Run(sms); std::move(callback).Run(sms);
} }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
namespace base { namespace base {
class Bus; class Bus;
class DictionaryValue; class Value;
} // namespace base } // namespace base
namespace dbus { namespace dbus {
...@@ -29,8 +29,7 @@ namespace chromeos { ...@@ -29,8 +29,7 @@ namespace chromeos {
// DBusThreadManager instance. // DBusThreadManager instance.
class COMPONENT_EXPORT(SHILL_CLIENT) SMSClient { class COMPONENT_EXPORT(SHILL_CLIENT) SMSClient {
public: public:
using GetAllCallback = using GetAllCallback = base::OnceCallback<void(const base::Value& sms)>;
base::OnceCallback<void(const base::DictionaryValue& sms)>;
static const char kSMSPropertyState[]; static const char kSMSPropertyState[];
static const char kSMSPropertyNumber[]; static const char kSMSPropertyNumber[];
......
...@@ -57,11 +57,11 @@ class NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler ...@@ -57,11 +57,11 @@ class NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler
private: private:
void ListCallback(base::Optional<std::vector<dbus::ObjectPath>> paths); void ListCallback(base::Optional<std::vector<dbus::ObjectPath>> paths);
void SmsReceivedCallback(const dbus::ObjectPath& path, bool complete); void SmsReceivedCallback(const dbus::ObjectPath& path, bool complete);
void GetCallback(const base::DictionaryValue& dictionary); void GetCallback(const base::Value& dictionary);
void DeleteMessages(); void DeleteMessages();
void DeleteCallback(bool success); void DeleteCallback(bool success);
void GetMessages(); void GetMessages();
void MessageReceived(const base::DictionaryValue& dictionary); void MessageReceived(const base::Value& dictionary);
NetworkSmsHandler* host_; NetworkSmsHandler* host_;
std::string service_name_; std::string service_name_;
...@@ -172,10 +172,8 @@ void NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler::GetMessages() { ...@@ -172,10 +172,8 @@ void NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler::GetMessages() {
delete_queue_.push_back(sms_path); delete_queue_.push_back(sms_path);
} }
void NetworkSmsHandler:: void NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler::
ModemManager1NetworkSmsDeviceHandler::SmsReceivedCallback( SmsReceivedCallback(const dbus::ObjectPath& sms_path, bool complete) {
const dbus::ObjectPath& sms_path,
bool complete) {
// Only handle complete messages. // Only handle complete messages.
if (!complete) if (!complete)
return; return;
...@@ -185,29 +183,29 @@ ModemManager1NetworkSmsDeviceHandler::SmsReceivedCallback( ...@@ -185,29 +183,29 @@ ModemManager1NetworkSmsDeviceHandler::SmsReceivedCallback(
} }
void NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler::GetCallback( void NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler::GetCallback(
const base::DictionaryValue& dictionary) { const base::Value& dictionary) {
MessageReceived(dictionary); MessageReceived(dictionary);
GetMessages(); GetMessages();
} }
void NetworkSmsHandler:: void NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler::MessageReceived(
ModemManager1NetworkSmsDeviceHandler::MessageReceived( const base::Value& dictionary) {
const base::DictionaryValue& dictionary) {
// The keys of the ModemManager1.SMS interface do not match the // The keys of the ModemManager1.SMS interface do not match the
// exported keys, so a new dictionary is created with the expected // exported keys, so a new dictionary is created with the expected
// key namaes. // key namaes.
base::DictionaryValue new_dictionary; base::Value new_dictionary(base::Value::Type::DICTIONARY);
std::string text, number, timestamp; const std::string* number =
if (dictionary.GetStringWithoutPathExpansion(SMSClient::kSMSPropertyNumber, dictionary.FindStringKey(SMSClient::kSMSPropertyNumber);
&number)) if (number)
new_dictionary.SetString(kNumberKey, number); new_dictionary.SetStringKey(kNumberKey, *number);
if (dictionary.GetStringWithoutPathExpansion(SMSClient::kSMSPropertyText, const std::string* text =
&text)) dictionary.FindStringKey(SMSClient::kSMSPropertyText);
new_dictionary.SetString(kTextKey, text); if (text)
// TODO(jglasgow): consider normalizing timestamp. new_dictionary.SetStringKey(kTextKey, *text);
if (dictionary.GetStringWithoutPathExpansion(SMSClient::kSMSPropertyTimestamp, const std::string* timestamp =
&timestamp)) dictionary.FindStringKey(SMSClient::kSMSPropertyTimestamp);
new_dictionary.SetString(kTimestampKey, timestamp); if (timestamp)
new_dictionary.SetStringKey(kTimestampKey, *timestamp);
host_->MessageReceived(new_dictionary); host_->MessageReceived(new_dictionary);
} }
...@@ -234,7 +232,7 @@ void NetworkSmsHandler::RequestUpdate(bool request_existing) { ...@@ -234,7 +232,7 @@ void NetworkSmsHandler::RequestUpdate(bool request_existing) {
// If we already received messages and |request_existing| is true, send // If we already received messages and |request_existing| is true, send
// updates for existing messages. // updates for existing messages.
for (const auto& message : received_messages_) { for (const auto& message : received_messages_) {
NotifyMessageReceived(*message); NotifyMessageReceived(message);
} }
// Request updates from each device. // Request updates from each device.
for (auto& handler : device_handlers_) { for (auto& handler : device_handlers_) {
...@@ -259,20 +257,18 @@ void NetworkSmsHandler::OnPropertyChanged(const std::string& name, ...@@ -259,20 +257,18 @@ void NetworkSmsHandler::OnPropertyChanged(const std::string& name,
// Private methods // Private methods
void NetworkSmsHandler::AddReceivedMessage( void NetworkSmsHandler::AddReceivedMessage(const base::Value& message) {
const base::DictionaryValue& message) {
if (received_messages_.size() >= kMaxReceivedMessages) if (received_messages_.size() >= kMaxReceivedMessages)
received_messages_.erase(received_messages_.begin()); received_messages_.erase(received_messages_.begin());
received_messages_.push_back(message.CreateDeepCopy()); received_messages_.push_back(message.Clone());
} }
void NetworkSmsHandler::NotifyMessageReceived( void NetworkSmsHandler::NotifyMessageReceived(const base::Value& message) {
const base::DictionaryValue& message) {
for (auto& observer : observers_) for (auto& observer : observers_)
observer.MessageReceived(message); observer.MessageReceived(message);
} }
void NetworkSmsHandler::MessageReceived(const base::DictionaryValue& message) { void NetworkSmsHandler::MessageReceived(const base::Value& message) {
AddReceivedMessage(message); AddReceivedMessage(message);
NotifyMessageReceived(message); NotifyMessageReceived(message);
} }
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "chromeos/dbus/shill/shill_property_changed_observer.h" #include "chromeos/dbus/shill/shill_property_changed_observer.h"
namespace base { namespace base {
class DictionaryValue;
class Value; class Value;
} }
...@@ -36,9 +35,10 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkSmsHandler ...@@ -36,9 +35,10 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkSmsHandler
public: public:
virtual ~Observer() {} virtual ~Observer() {}
// Called when a new message arrives. |message| contains the message. // Called when a new message arrives. |message| contains the message which
// The contents of the dictionary include the keys listed above. // is a dictionary value containing entries for kNumberKey, kTextKey, and
virtual void MessageReceived(const base::DictionaryValue& message) = 0; // kTimestampKey.
virtual void MessageReceived(const base::Value& message) = 0;
}; };
~NetworkSmsHandler() override; ~NetworkSmsHandler() override;
...@@ -71,13 +71,13 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkSmsHandler ...@@ -71,13 +71,13 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkSmsHandler
// Adds |message| to the list of received messages. If the length of the // Adds |message| to the list of received messages. If the length of the
// list exceeds the maximum number of retained messages, erase the least // list exceeds the maximum number of retained messages, erase the least
// recently received message. // recently received message.
void AddReceivedMessage(const base::DictionaryValue& message); void AddReceivedMessage(const base::Value& message);
// Notify observers that |message| was received. // Notify observers that |message| was received.
void NotifyMessageReceived(const base::DictionaryValue& message); void NotifyMessageReceived(const base::Value& message);
// Called from NetworkSmsDeviceHandler when a message is received. // Called from NetworkSmsDeviceHandler when a message is received.
void MessageReceived(const base::DictionaryValue& message); void MessageReceived(const base::Value& message);
// Callback to handle the manager properties with the list of devices. // Callback to handle the manager properties with the list of devices.
void ManagerPropertiesCallback(base::Optional<base::Value> properties); void ManagerPropertiesCallback(base::Optional<base::Value> properties);
...@@ -92,7 +92,7 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkSmsHandler ...@@ -92,7 +92,7 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkSmsHandler
base::ObserverList<Observer, true>::Unchecked observers_; base::ObserverList<Observer, true>::Unchecked observers_;
std::vector<std::unique_ptr<NetworkSmsDeviceHandler>> device_handlers_; std::vector<std::unique_ptr<NetworkSmsDeviceHandler>> device_handlers_;
std::vector<std::unique_ptr<base::DictionaryValue>> received_messages_; std::vector<base::Value> received_messages_;
base::WeakPtrFactory<NetworkSmsHandler> weak_ptr_factory_{this}; base::WeakPtrFactory<NetworkSmsHandler> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(NetworkSmsHandler); DISALLOW_COPY_AND_ASSIGN(NetworkSmsHandler);
......
...@@ -26,12 +26,11 @@ class TestObserver : public NetworkSmsHandler::Observer { ...@@ -26,12 +26,11 @@ class TestObserver : public NetworkSmsHandler::Observer {
TestObserver() = default; TestObserver() = default;
~TestObserver() override = default; ~TestObserver() override = default;
void MessageReceived(const base::DictionaryValue& message) override { void MessageReceived(const base::Value& message) override {
std::string text; const std::string* text =
if (message.GetStringWithoutPathExpansion( message.FindStringKey(NetworkSmsHandler::kTextKey);
NetworkSmsHandler::kTextKey, &text)) { if (text)
messages_.insert(text); messages_.insert(*text);
}
} }
void ClearMessages() { void ClearMessages() {
......
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