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