Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: remoting/host/log_to_server.cc

Issue 8468015: The host sends simple log entries to the server. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/log_to_server.h ('k') | remoting/host/log_to_server_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 } // namespace
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 DCHECK(message_loop_->BelongsToCurrentThread());
68 pending_entries_.push_back(entry);
69 SendPendingEntries();
70 }
71
72 void LogToServer::SendPendingEntries() {
73 DCHECK(message_loop_->BelongsToCurrentThread());
74
75 if (iq_sender_ == NULL) {
76 return;
77 }
78 if (pending_entries_.empty()) {
79 return;
80 }
81 // Make one stanza containing all the pending entries.
82 scoped_ptr<XmlElement> stanza(new XmlElement(QName(
83 kChromotingXmlNamespace, kLogCommand)));
84 while (!pending_entries_.empty()) {
85 ServerLogEntry& entry = pending_entries_.front();
86 stanza->AddElement(entry.ToStanza());
87 pending_entries_.pop_front();
88 }
89 // Send the stanza to the server.
90 scoped_ptr<IqRequest> req(iq_sender_->SendIq(
91 buzz::STR_SET, kChromotingBotJid, stanza.release(),
92 IqSender::ReplyCallback()));
93 // We ignore any response, so let the IqRequest be destroyed.
94 return;
95 }
96
97 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/log_to_server.h ('k') | remoting/host/log_to_server_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698