summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorkxing@chromium.org <kxing@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-26 00:20:48 +0000
committerkxing@chromium.org <kxing@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-26 00:20:48 +0000
commit2c3eaaf90eb2cb35c60272307540b2c2ea335f82 (patch)
tree1abd79cbfef010f5c04d6d9b235be2d9b1d9953a /remoting
parent4c0d1f72ed8f8ad47a042ac31c7a64a340da33b5 (diff)
downloadchromium_src-2c3eaaf90eb2cb35c60272307540b2c2ea335f82.zip
chromium_src-2c3eaaf90eb2cb35c60272307540b2c2ea335f82.tar.gz
chromium_src-2c3eaaf90eb2cb35c60272307540b2c2ea335f82.tar.bz2
Refactored similar code in ContentDescription::ParseXml()
BUG=134222 Review URL: https://chromiumcodereview.appspot.com/10657031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144069 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/protocol/content_description.cc88
-rw-r--r--remoting/protocol/content_description.h6
2 files changed, 47 insertions, 47 deletions
diff --git a/remoting/protocol/content_description.cc b/remoting/protocol/content_description.cc
index d55163f..0cd7ce4 100644
--- a/remoting/protocol/content_description.cc
+++ b/remoting/protocol/content_description.cc
@@ -222,6 +222,35 @@ XmlElement* ContentDescription::ToXml() const {
}
// static
+// Adds the channel configs corresponding to |tag_name|,
+// found in |element|, to |configs|.
+bool ContentDescription::ParseChannelConfigs(
+ const XmlElement* const element,
+ const char tag_name[],
+ bool codec_required,
+ bool optional,
+ std::vector<ChannelConfig>* const configs) {
+
+ QName tag(kChromotingXmlNamespace, tag_name);
+ const XmlElement* child = element->FirstNamed(tag);
+ while (child) {
+ ChannelConfig channel_config;
+ if (!ParseChannelConfig(child, codec_required, &channel_config))
+ return false;
+ configs->push_back(channel_config);
+ child = child->NextNamed(tag);
+ }
+ if (optional && configs->empty()) {
+ // If there's no mention of the tag, implicitly assume
+ // TRANSPORT_NONE for the channel.
+ configs->push_back(ChannelConfig(ChannelConfig::TRANSPORT_NONE,
+ kDefaultStreamVersion,
+ ChannelConfig::CODEC_VERBATIM));
+ }
+ return true;
+}
+
+// static
ContentDescription* ContentDescription::ParseXml(
const XmlElement* element) {
if (element->Name() == QName(kChromotingXmlNamespace, kDescriptionTag)) {
@@ -229,56 +258,21 @@ ContentDescription* ContentDescription::ParseXml(
CandidateSessionConfig::CreateEmpty());
const XmlElement* child = NULL;
- // <control> tags.
- QName control_tag(kChromotingXmlNamespace, kControlTag);
- child = element->FirstNamed(control_tag);
- while (child) {
- ChannelConfig channel_config;
- if (!ParseChannelConfig(child, false, &channel_config))
- return NULL;
- config->mutable_control_configs()->push_back(channel_config);
- child = child->NextNamed(control_tag);
+ if (!ParseChannelConfigs(element, kControlTag, false, false,
+ config->mutable_control_configs())) {
+ return NULL;
}
-
- // <event> tags.
- QName event_tag(kChromotingXmlNamespace, kEventTag);
- child = element->FirstNamed(event_tag);
- while (child) {
- ChannelConfig channel_config;
- if (!ParseChannelConfig(child, false, &channel_config))
- return NULL;
- config->mutable_event_configs()->push_back(channel_config);
- child = child->NextNamed(event_tag);
+ if (!ParseChannelConfigs(element, kEventTag, false, false,
+ config->mutable_event_configs())) {
+ return NULL;
}
-
- // <video> tags.
- QName video_tag(kChromotingXmlNamespace, kVideoTag);
- child = element->FirstNamed(video_tag);
- while (child) {
- ChannelConfig channel_config;
- if (!ParseChannelConfig(child, true, &channel_config))
- return NULL;
- config->mutable_video_configs()->push_back(channel_config);
- child = child->NextNamed(video_tag);
- }
-
- // <audio> tags.
- QName audio_tag(kChromotingXmlNamespace, kAudioTag);
- child = element->FirstNamed(audio_tag);
- if (!child) {
- // If there's no mention of audio, implicitly assume
- // TRANSPORT_NONE for the audio_channel.
- ChannelConfig no_audio(ChannelConfig::TRANSPORT_NONE,
- kDefaultStreamVersion,
- ChannelConfig::CODEC_VERBATIM);
- config->mutable_audio_configs()->push_back(no_audio);
+ if (!ParseChannelConfigs(element, kVideoTag, true, false,
+ config->mutable_video_configs())) {
+ return NULL;
}
- while (child) {
- ChannelConfig channel_config;
- if (!ParseChannelConfig(child, true, &channel_config))
- return NULL;
- config->mutable_audio_configs()->push_back(channel_config);
- child = child->NextNamed(audio_tag);
+ if (!ParseChannelConfigs(element, kAudioTag, true, true,
+ config->mutable_audio_configs())) {
+ return NULL;
}
scoped_ptr<XmlElement> authenticator_message;
diff --git a/remoting/protocol/content_description.h b/remoting/protocol/content_description.h
index 2eed505..fe4ad3a 100644
--- a/remoting/protocol/content_description.h
+++ b/remoting/protocol/content_description.h
@@ -49,6 +49,12 @@ class ContentDescription : public cricket::ContentDescription {
private:
scoped_ptr<const CandidateSessionConfig> candidate_config_;
scoped_ptr<const buzz::XmlElement> authenticator_message_;
+
+ static bool ParseChannelConfigs(const buzz::XmlElement* const element,
+ const char tag_name[],
+ bool codec_required,
+ bool optional,
+ std::vector<ChannelConfig>* const configs);
};
} // namespace protocol