Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1165)

Unified Diff: media/midi/midi_manager_alsa.cc

Issue 1027643003: Web MIDI Linux: Omit empty values in JSON, to make id generation more robust (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@h3
Patch Set: Improve use of scoped_ptr in AlsaPortMetadata::Value() Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | media/midi/midi_manager_alsa_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/midi/midi_manager_alsa.cc
diff --git a/media/midi/midi_manager_alsa.cc b/media/midi/midi_manager_alsa.cc
index 2050780f5ebfb2ce000693aabf54346e57f988f0..01a003841492d0a738c0d228c5e19bed2ac99f1d 100644
--- a/media/midi/midi_manager_alsa.cc
+++ b/media/midi/midi_manager_alsa.cc
@@ -91,6 +91,13 @@ const std::string UdevDeviceGetPropertyOrSysattr(
}
#endif // defined(USE_UDEV)
+void SetStringIfNonEmpty(base::DictionaryValue* value,
+ const std::string& path,
+ const std::string& in_value) {
+ if (!in_value.empty())
+ value->SetString(path, in_value);
+}
+
} // namespace
MidiManagerAlsa::MidiManagerAlsa()
@@ -395,16 +402,16 @@ MidiManagerAlsa::AlsaPortMetadata::~AlsaPortMetadata() {
}
scoped_ptr<base::Value> MidiManagerAlsa::AlsaPortMetadata::Value() const {
- base::DictionaryValue* value = new base::DictionaryValue();
- value->SetString("path", path_);
- value->SetString("bus", bus_);
- value->SetString("id", id_);
+ scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue);
+ SetStringIfNonEmpty(value.get(), "path", path_);
+ SetStringIfNonEmpty(value.get(), "bus", bus_);
+ SetStringIfNonEmpty(value.get(), "id", id_);
value->SetInteger("clientAddr", client_addr_);
value->SetInteger("portAddr", port_addr_);
- value->SetString("clientName", client_name_);
- value->SetString("portName", port_name_);
- value->SetString("cardName", card_name_);
- value->SetString("cardLongname", card_longname_);
+ SetStringIfNonEmpty(value.get(), "clientName", client_name_);
+ SetStringIfNonEmpty(value.get(), "portName", port_name_);
+ SetStringIfNonEmpty(value.get(), "cardName", card_name_);
+ SetStringIfNonEmpty(value.get(), "cardLongname", card_longname_);
std::string type;
switch (type_) {
case Type::kInput:
@@ -415,9 +422,9 @@ scoped_ptr<base::Value> MidiManagerAlsa::AlsaPortMetadata::Value() const {
type = "output";
break;
}
- value->SetString("type", type);
+ SetStringIfNonEmpty(value.get(), "type", type);
- return scoped_ptr<base::Value>(value).Pass();
+ return value.Pass();
}
std::string MidiManagerAlsa::AlsaPortMetadata::JSONValue() const {
« no previous file with comments | « no previous file | media/midi/midi_manager_alsa_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698