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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | media/midi/midi_manager_alsa_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/midi/midi_manager_alsa.h" 5 #include "media/midi/midi_manager_alsa.h"
6 6
7 #include <alsa/asoundlib.h> 7 #include <alsa/asoundlib.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 // If no property, look for sysattrs and walk up the parent devices too. 85 // If no property, look for sysattrs and walk up the parent devices too.
86 while (value.empty() && udev_device) { 86 while (value.empty() && udev_device) {
87 value = device::UdevDeviceGetSysattrValue(udev_device, sysattr_key); 87 value = device::UdevDeviceGetSysattrValue(udev_device, sysattr_key);
88 udev_device = device::udev_device_get_parent(udev_device); 88 udev_device = device::udev_device_get_parent(udev_device);
89 } 89 }
90 return value; 90 return value;
91 } 91 }
92 #endif // defined(USE_UDEV) 92 #endif // defined(USE_UDEV)
93 93
94 void SetStringIfNonEmpty(base::DictionaryValue* value,
95 const std::string& path,
96 const std::string& in_value) {
97 if (!in_value.empty())
98 value->SetString(path, in_value);
99 }
100
94 } // namespace 101 } // namespace
95 102
96 MidiManagerAlsa::MidiManagerAlsa() 103 MidiManagerAlsa::MidiManagerAlsa()
97 : in_client_(NULL), 104 : in_client_(NULL),
98 out_client_(NULL), 105 out_client_(NULL),
99 out_client_id_(-1), 106 out_client_id_(-1),
100 in_port_(-1), 107 in_port_(-1),
101 decoder_(NULL), 108 decoder_(NULL),
102 #if defined(USE_UDEV) 109 #if defined(USE_UDEV)
103 udev_(device::udev_new()), 110 udev_(device::udev_new()),
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 port_name_(port_name), 395 port_name_(port_name),
389 card_name_(card_name), 396 card_name_(card_name),
390 card_longname_(card_longname), 397 card_longname_(card_longname),
391 type_(type) { 398 type_(type) {
392 } 399 }
393 400
394 MidiManagerAlsa::AlsaPortMetadata::~AlsaPortMetadata() { 401 MidiManagerAlsa::AlsaPortMetadata::~AlsaPortMetadata() {
395 } 402 }
396 403
397 scoped_ptr<base::Value> MidiManagerAlsa::AlsaPortMetadata::Value() const { 404 scoped_ptr<base::Value> MidiManagerAlsa::AlsaPortMetadata::Value() const {
398 base::DictionaryValue* value = new base::DictionaryValue(); 405 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue);
399 value->SetString("path", path_); 406 SetStringIfNonEmpty(value.get(), "path", path_);
400 value->SetString("bus", bus_); 407 SetStringIfNonEmpty(value.get(), "bus", bus_);
401 value->SetString("id", id_); 408 SetStringIfNonEmpty(value.get(), "id", id_);
402 value->SetInteger("clientAddr", client_addr_); 409 value->SetInteger("clientAddr", client_addr_);
403 value->SetInteger("portAddr", port_addr_); 410 value->SetInteger("portAddr", port_addr_);
404 value->SetString("clientName", client_name_); 411 SetStringIfNonEmpty(value.get(), "clientName", client_name_);
405 value->SetString("portName", port_name_); 412 SetStringIfNonEmpty(value.get(), "portName", port_name_);
406 value->SetString("cardName", card_name_); 413 SetStringIfNonEmpty(value.get(), "cardName", card_name_);
407 value->SetString("cardLongname", card_longname_); 414 SetStringIfNonEmpty(value.get(), "cardLongname", card_longname_);
408 std::string type; 415 std::string type;
409 switch (type_) { 416 switch (type_) {
410 case Type::kInput: 417 case Type::kInput:
411 type = "input"; 418 type = "input";
412 break; 419 break;
413 420
414 case Type::kOutput: 421 case Type::kOutput:
415 type = "output"; 422 type = "output";
416 break; 423 break;
417 } 424 }
418 value->SetString("type", type); 425 SetStringIfNonEmpty(value.get(), "type", type);
419 426
420 return scoped_ptr<base::Value>(value).Pass(); 427 return value.Pass();
421 } 428 }
422 429
423 std::string MidiManagerAlsa::AlsaPortMetadata::JSONValue() const { 430 std::string MidiManagerAlsa::AlsaPortMetadata::JSONValue() const {
424 std::string json; 431 std::string json;
425 JSONStringValueSerializer serializer(&json); 432 JSONStringValueSerializer serializer(&json);
426 serializer.Serialize(*Value().get()); 433 serializer.Serialize(*Value().get());
427 return json; 434 return json;
428 } 435 }
429 436
430 // TODO(agoode): Do not use SHA256 here. Instead store a persistent 437 // TODO(agoode): Do not use SHA256 here. Instead store a persistent
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 } 730 }
724 } 731 }
725 } 732 }
726 } 733 }
727 734
728 MidiManager* MidiManager::Create() { 735 MidiManager* MidiManager::Create() {
729 return new MidiManagerAlsa(); 736 return new MidiManagerAlsa();
730 } 737 }
731 738
732 } // namespace media 739 } // namespace media
OLDNEW
« 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