Index: remoting/host/log_to_server.cc |
diff --git a/remoting/host/log_to_server.cc b/remoting/host/log_to_server.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1955563453d6523f94ac7d4981e14a32e1766268 |
--- /dev/null |
+++ b/remoting/host/log_to_server.cc |
@@ -0,0 +1,106 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "remoting/host/log_to_server.h" |
+ |
+#include "base/bind.h" |
+#include "base/message_loop_proxy.h" |
+#include "remoting/base/constants.h" |
+#include "remoting/host/server_log_entry.h" |
+#include "remoting/jingle_glue/iq_sender.h" |
+#include "remoting/jingle_glue/jingle_thread.h" |
+#include "remoting/jingle_glue/signal_strategy.h" |
+#include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
+#include "third_party/libjingle/source/talk/xmpp/constants.h" |
+ |
+using buzz::QName; |
+using buzz::XmlElement; |
+ |
+namespace remoting { |
+ |
+namespace { |
+const char kLogCommand[] = "log"; |
+} |
Sergey Ulanov
2011/11/17 01:16:33
// namespace
simonmorris
2011/11/18 19:23:04
Done.
|
+ |
+LogToServer::LogToServer(base::MessageLoopProxy* message_loop) |
+ : message_loop_(message_loop) { |
+} |
+ |
+LogToServer::~LogToServer() { |
+} |
+ |
+void LogToServer::LogSessionStateChange(bool connected) { |
+ scoped_ptr<ServerLogEntry> entry(ServerLogEntry::MakeSessionStateChange( |
+ connected)); |
+ entry->AddHostFields(); |
+ Log(*entry.get()); |
+} |
+ |
+void LogToServer::OnSignallingConnected(SignalStrategy* signal_strategy, |
+ const std::string& full_jid) { |
+ DCHECK(message_loop_->BelongsToCurrentThread()); |
+ iq_sender_.reset(new IqSender(signal_strategy)); |
+ SendPendingEntries(); |
+} |
+ |
+void LogToServer::OnSignallingDisconnected() { |
+ DCHECK(message_loop_->BelongsToCurrentThread()); |
+ iq_sender_.reset(); |
+} |
+ |
+void LogToServer::OnAccessDenied() { |
+} |
+ |
+void LogToServer::OnClientAuthenticated(const std::string& jid) { |
+ LogSessionStateChange(true); |
+} |
+ |
+void LogToServer::OnClientDisconnected(const std::string& jid) { |
+ LogSessionStateChange(false); |
+} |
+ |
+void LogToServer::OnShutdown() { |
+} |
+ |
+void LogToServer::Log(const ServerLogEntry& entry) { |
+ if (!message_loop_->BelongsToCurrentThread()) { |
Sergey Ulanov
2011/11/17 01:16:33
Currently this method is called only on network th
simonmorris
2011/11/18 19:23:04
Is it very unlikely that we'll ever want to log an
Sergey Ulanov
2011/11/22 02:01:43
There is no risk in not having this trampoline as
simonmorris
2011/11/22 23:27:35
Sounds like a good pattern.
Done.
|
+ message_loop_->PostTask(FROM_HERE, base::Bind( |
+ &LogToServer::Log, this, entry)); |
+ return; |
+ } |
+ |
+ pending_entries_.push_back(entry); |
Sergey Ulanov
2011/11/17 01:16:33
do we really need |pedning_entries_|? SendPendingE
simonmorris
2011/11/18 19:23:04
Yes, the idea was to avoid losing messages while s
|
+ SendPendingEntries(); |
+} |
+ |
+void LogToServer::SendPendingEntries() { |
+ DCHECK(message_loop_->BelongsToCurrentThread()); |
+ |
+ if (iq_sender_ == NULL) { |
+ return; |
+ } |
+ if (pending_entries_.empty()) { |
+ return; |
+ } |
+ // Make one stanza containing all the pending entries. |
+ scoped_ptr<XmlElement> stanza(new XmlElement(QName( |
+ kChromotingXmlNamespace, kLogCommand))); |
+ while (!pending_entries_.empty()) { |
+ ServerLogEntry& entry = pending_entries_.front(); |
+ stanza->AddElement(entry.ToStanza()); |
+ pending_entries_.pop_front(); |
+ } |
+ // Send the stanza to the server. |
+ scoped_ptr<IqRequest> req(iq_sender_->SendIq( |
+ buzz::STR_SET, kChromotingBotJid, stanza.release(), |
+ base::Bind(&LogToServer::ProcessResponse, this))); |
Sergey Ulanov
2011/11/17 01:16:33
you can pass null callback here (i.e. IqSender::Re
simonmorris
2011/11/18 19:23:04
Done.
|
+ // We ignore any response, so let the IqRequest be destroyed. |
+ return; |
+} |
+ |
+void LogToServer::ProcessResponse(const XmlElement* response) { |
Sergey Ulanov
2011/11/17 01:16:33
Don't think we need this.
simonmorris
2011/11/18 19:23:04
Done.
|
+ DCHECK(message_loop_->BelongsToCurrentThread()); |
+} |
+ |
+} // namespace remoting |