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
3 // found in the LICENSE file.
5 #include "remoting/signaling/log_to_server.h"
7 #include "remoting/base/constants.h"
8 #include "remoting/signaling/iq_sender.h"
9 #include "remoting/signaling/signal_strategy.h"
10 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
11 #include "third_party/libjingle/source/talk/xmpp/constants.h"
14 using buzz::XmlElement
;
18 LogToServer::LogToServer(ServerLogEntry::Mode mode
,
19 SignalStrategy
* signal_strategy
,
20 const std::string
& directory_bot_jid
)
22 signal_strategy_(signal_strategy
),
23 directory_bot_jid_(directory_bot_jid
) {
24 signal_strategy_
->AddListener(this);
27 LogToServer::~LogToServer() {
28 signal_strategy_
->RemoveListener(this);
31 void LogToServer::OnSignalStrategyStateChange(SignalStrategy::State state
) {
32 DCHECK(CalledOnValidThread());
34 if (state
== SignalStrategy::CONNECTED
) {
35 iq_sender_
.reset(new IqSender(signal_strategy_
));
37 } else if (state
== SignalStrategy::DISCONNECTED
) {
42 bool LogToServer::OnSignalStrategyIncomingStanza(
43 const buzz::XmlElement
* stanza
) {
47 void LogToServer::Log(const ServerLogEntry
& entry
) {
48 pending_entries_
.push_back(entry
);
52 void LogToServer::SendPendingEntries() {
53 if (iq_sender_
== NULL
) {
56 if (pending_entries_
.empty()) {
59 // Make one stanza containing all the pending entries.
60 scoped_ptr
<XmlElement
> stanza(ServerLogEntry::MakeStanza());
61 while (!pending_entries_
.empty()) {
62 ServerLogEntry
& entry
= pending_entries_
.front();
63 stanza
->AddElement(entry
.ToStanza().release());
64 pending_entries_
.pop_front();
66 // Send the stanza to the server.
67 scoped_ptr
<IqRequest
> req
= iq_sender_
->SendIq(
68 buzz::STR_SET
, directory_bot_jid_
, stanza
.Pass(),
69 IqSender::ReplyCallback());
70 // We ignore any response, so let the IqRequest be destroyed.
74 } // namespace remoting