OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "remoting/signaling/xmpp_stream_parser.h" | 5 #include "remoting/signaling/xmpp_stream_parser.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
11 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
12 #include "third_party/webrtc/libjingle/xmllite/xmlbuilder.h" | 13 #include "third_party/webrtc/libjingle/xmllite/xmlbuilder.h" |
13 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 14 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
14 #include "third_party/webrtc/libjingle/xmllite/xmlparser.h" | 15 #include "third_party/webrtc/libjingle/xmllite/xmlparser.h" |
15 | 16 |
16 namespace remoting { | 17 namespace remoting { |
17 | 18 |
18 class XmppStreamParser::Core : public buzz::XmlParseHandler { | 19 class XmppStreamParser::Core : public buzz::XmlParseHandler { |
19 public: | 20 public: |
20 typedef base::Callback<void(scoped_ptr<buzz::XmlElement> stanza)> | 21 typedef base::Callback<void(std::unique_ptr<buzz::XmlElement> stanza)> |
21 OnStanzaCallback; | 22 OnStanzaCallback; |
22 | 23 |
23 Core(); | 24 Core(); |
24 ~Core() override; | 25 ~Core() override; |
25 | 26 |
26 void SetCallbacks(const OnStanzaCallback& on_stanza_callback, | 27 void SetCallbacks(const OnStanzaCallback& on_stanza_callback, |
27 const base::Closure& on_error_callback); | 28 const base::Closure& on_error_callback); |
28 | 29 |
29 void AppendData(const std::string& data); | 30 void AppendData(const std::string& data); |
30 | 31 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 parser_.Parse(data.data(), data.size(), false); | 76 parser_.Parse(data.data(), data.size(), false); |
76 } | 77 } |
77 | 78 |
78 void XmppStreamParser::Core::StartElement(buzz::XmlParseContext* context, | 79 void XmppStreamParser::Core::StartElement(buzz::XmlParseContext* context, |
79 const char* name, | 80 const char* name, |
80 const char** atts) { | 81 const char** atts) { |
81 DCHECK(!error_); | 82 DCHECK(!error_); |
82 | 83 |
83 ++depth_; | 84 ++depth_; |
84 if (depth_ == 1) { | 85 if (depth_ == 1) { |
85 scoped_ptr<buzz::XmlElement> header( | 86 std::unique_ptr<buzz::XmlElement> header( |
86 buzz::XmlBuilder::BuildElement(context, name, atts)); | 87 buzz::XmlBuilder::BuildElement(context, name, atts)); |
87 if (!header) { | 88 if (!header) { |
88 LOG(ERROR) << "Failed to parse XMPP stream header."; | 89 LOG(ERROR) << "Failed to parse XMPP stream header."; |
89 ProcessError(); | 90 ProcessError(); |
90 } | 91 } |
91 return; | 92 return; |
92 } | 93 } |
93 | 94 |
94 builder_.StartElement(context, name, atts); | 95 builder_.StartElement(context, name, atts); |
95 } | 96 } |
96 | 97 |
97 void XmppStreamParser::Core::EndElement(buzz::XmlParseContext* context, | 98 void XmppStreamParser::Core::EndElement(buzz::XmlParseContext* context, |
98 const char* name) { | 99 const char* name) { |
99 DCHECK(!error_); | 100 DCHECK(!error_); |
100 | 101 |
101 --depth_; | 102 --depth_; |
102 if (depth_ == 0) { | 103 if (depth_ == 0) { |
103 LOG(ERROR) << "XMPP stream ended unexpectedly."; | 104 LOG(ERROR) << "XMPP stream ended unexpectedly."; |
104 ProcessError(); | 105 ProcessError(); |
105 return; | 106 return; |
106 } | 107 } |
107 | 108 |
108 builder_.EndElement(context, name); | 109 builder_.EndElement(context, name); |
109 | 110 |
110 if (depth_ == 1) { | 111 if (depth_ == 1) { |
111 if (!on_stanza_callback_.is_null()) | 112 if (!on_stanza_callback_.is_null()) |
112 on_stanza_callback_.Run(make_scoped_ptr(builder_.CreateElement())); | 113 on_stanza_callback_.Run(base::WrapUnique(builder_.CreateElement())); |
113 } | 114 } |
114 } | 115 } |
115 | 116 |
116 void XmppStreamParser::Core::CharacterData(buzz::XmlParseContext* context, | 117 void XmppStreamParser::Core::CharacterData(buzz::XmlParseContext* context, |
117 const char* text, | 118 const char* text, |
118 int len) { | 119 int len) { |
119 DCHECK(!error_); | 120 DCHECK(!error_); |
120 | 121 |
121 // Ignore data between stanzas. | 122 // Ignore data between stanzas. |
122 if (depth_ <= 1) { | 123 if (depth_ <= 1) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 void XmppStreamParser::SetCallbacks(const OnStanzaCallback& on_stanza_callback, | 164 void XmppStreamParser::SetCallbacks(const OnStanzaCallback& on_stanza_callback, |
164 const base::Closure& on_error_callback) { | 165 const base::Closure& on_error_callback) { |
165 core_->SetCallbacks(on_stanza_callback, on_error_callback); | 166 core_->SetCallbacks(on_stanza_callback, on_error_callback); |
166 } | 167 } |
167 | 168 |
168 void XmppStreamParser::AppendData(const std::string& data) { | 169 void XmppStreamParser::AppendData(const std::string& data) { |
169 core_->AppendData(data); | 170 core_->AppendData(data); |
170 } | 171 } |
171 | 172 |
172 } // namespace remoting | 173 } // namespace remoting |
OLD | NEW |