OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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. | |
4 | |
5 #include "remoting/host/log_to_server.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/message_loop_proxy.h" | |
9 #include "remoting/base/constants.h" | |
10 #include "remoting/host/server_log_entry.h" | |
11 #include "remoting/jingle_glue/iq_sender.h" | |
12 #include "remoting/jingle_glue/jingle_thread.h" | |
13 #include "remoting/jingle_glue/signal_strategy.h" | |
14 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | |
15 #include "third_party/libjingle/source/talk/xmpp/constants.h" | |
16 | |
17 using buzz::QName; | |
18 using buzz::XmlElement; | |
19 | |
20 namespace remoting { | |
21 | |
22 namespace { | |
23 const char kLogCommand[] = "log"; | |
24 } | |
Sergey Ulanov
2011/11/17 01:16:33
// namespace
simonmorris
2011/11/18 19:23:04
Done.
| |
25 | |
26 LogToServer::LogToServer(base::MessageLoopProxy* message_loop) | |
27 : message_loop_(message_loop) { | |
28 } | |
29 | |
30 LogToServer::~LogToServer() { | |
31 } | |
32 | |
33 void LogToServer::LogSessionStateChange(bool connected) { | |
34 scoped_ptr<ServerLogEntry> entry(ServerLogEntry::MakeSessionStateChange( | |
35 connected)); | |
36 entry->AddHostFields(); | |
37 Log(*entry.get()); | |
38 } | |
39 | |
40 void LogToServer::OnSignallingConnected(SignalStrategy* signal_strategy, | |
41 const std::string& full_jid) { | |
42 DCHECK(message_loop_->BelongsToCurrentThread()); | |
43 iq_sender_.reset(new IqSender(signal_strategy)); | |
44 SendPendingEntries(); | |
45 } | |
46 | |
47 void LogToServer::OnSignallingDisconnected() { | |
48 DCHECK(message_loop_->BelongsToCurrentThread()); | |
49 iq_sender_.reset(); | |
50 } | |
51 | |
52 void LogToServer::OnAccessDenied() { | |
53 } | |
54 | |
55 void LogToServer::OnClientAuthenticated(const std::string& jid) { | |
56 LogSessionStateChange(true); | |
57 } | |
58 | |
59 void LogToServer::OnClientDisconnected(const std::string& jid) { | |
60 LogSessionStateChange(false); | |
61 } | |
62 | |
63 void LogToServer::OnShutdown() { | |
64 } | |
65 | |
66 void LogToServer::Log(const ServerLogEntry& entry) { | |
67 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.
| |
68 message_loop_->PostTask(FROM_HERE, base::Bind( | |
69 &LogToServer::Log, this, entry)); | |
70 return; | |
71 } | |
72 | |
73 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
| |
74 SendPendingEntries(); | |
75 } | |
76 | |
77 void LogToServer::SendPendingEntries() { | |
78 DCHECK(message_loop_->BelongsToCurrentThread()); | |
79 | |
80 if (iq_sender_ == NULL) { | |
81 return; | |
82 } | |
83 if (pending_entries_.empty()) { | |
84 return; | |
85 } | |
86 // Make one stanza containing all the pending entries. | |
87 scoped_ptr<XmlElement> stanza(new XmlElement(QName( | |
88 kChromotingXmlNamespace, kLogCommand))); | |
89 while (!pending_entries_.empty()) { | |
90 ServerLogEntry& entry = pending_entries_.front(); | |
91 stanza->AddElement(entry.ToStanza()); | |
92 pending_entries_.pop_front(); | |
93 } | |
94 // Send the stanza to the server. | |
95 scoped_ptr<IqRequest> req(iq_sender_->SendIq( | |
96 buzz::STR_SET, kChromotingBotJid, stanza.release(), | |
97 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.
| |
98 // We ignore any response, so let the IqRequest be destroyed. | |
99 return; | |
100 } | |
101 | |
102 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.
| |
103 DCHECK(message_loop_->BelongsToCurrentThread()); | |
104 } | |
105 | |
106 } // namespace remoting | |
OLD | NEW |