Managed bookmarks for supervised users.
[chromium-blink-merge.git] / remoting / signaling / log_to_server.cc
blob731dc5862bfd922d782e015bc14da67fd1ab2a41
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/webrtc/libjingle/xmllite/xmlelement.h"
11 #include "third_party/webrtc/libjingle/xmpp/constants.h"
13 using buzz::QName;
14 using buzz::XmlElement;
16 namespace remoting {
18 LogToServer::LogToServer(ServerLogEntry::Mode mode,
19 SignalStrategy* signal_strategy,
20 const std::string& directory_bot_jid)
21 : mode_(mode),
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_));
36 SendPendingEntries();
37 } else if (state == SignalStrategy::DISCONNECTED) {
38 iq_sender_.reset();
42 bool LogToServer::OnSignalStrategyIncomingStanza(
43 const buzz::XmlElement* stanza) {
44 return false;
47 void LogToServer::Log(const ServerLogEntry& entry) {
48 pending_entries_.push_back(entry);
49 SendPendingEntries();
52 void LogToServer::SendPendingEntries() {
53 if (iq_sender_ == nullptr) {
54 return;
56 if (pending_entries_.empty()) {
57 return;
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.
71 return;
74 } // namespace remoting