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

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

Issue 320403002: Pull out common code from client and host versions of LogToServer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix try failures Created 6 years, 5 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/jingle_glue/log_to_server.h"
6 6
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop_proxy.h"
9 #include "remoting/base/constants.h" 7 #include "remoting/base/constants.h"
10 #include "remoting/host/host_status_monitor.h"
11 #include "remoting/host/server_log_entry_host.h"
12 #include "remoting/jingle_glue/iq_sender.h" 8 #include "remoting/jingle_glue/iq_sender.h"
13 #include "remoting/jingle_glue/server_log_entry.h"
14 #include "remoting/jingle_glue/signal_strategy.h" 9 #include "remoting/jingle_glue/signal_strategy.h"
15 #include "remoting/protocol/transport.h"
16 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" 10 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
17 #include "third_party/libjingle/source/talk/xmpp/constants.h" 11 #include "third_party/libjingle/source/talk/xmpp/constants.h"
18 12
19 using buzz::QName; 13 using buzz::QName;
20 using buzz::XmlElement; 14 using buzz::XmlElement;
21 15
22 namespace remoting { 16 namespace remoting {
23 17
24 LogToServer::LogToServer(base::WeakPtr<HostStatusMonitor> monitor, 18 LogToServer::LogToServer(ServerLogEntry::Mode mode,
25 ServerLogEntry::Mode mode,
26 SignalStrategy* signal_strategy, 19 SignalStrategy* signal_strategy,
27 const std::string& directory_bot_jid) 20 const std::string& directory_bot_jid)
28 : monitor_(monitor), 21 : mode_(mode),
29 mode_(mode),
30 signal_strategy_(signal_strategy), 22 signal_strategy_(signal_strategy),
31 directory_bot_jid_(directory_bot_jid) { 23 directory_bot_jid_(directory_bot_jid) {
32 monitor_->AddStatusObserver(this);
33 signal_strategy_->AddListener(this); 24 signal_strategy_->AddListener(this);
34 } 25 }
35 26
36 LogToServer::~LogToServer() { 27 LogToServer::~LogToServer() {
37 signal_strategy_->RemoveListener(this); 28 signal_strategy_->RemoveListener(this);
38 if (monitor_.get())
39 monitor_->RemoveStatusObserver(this);
40 }
41
42 void LogToServer::LogSessionStateChange(const std::string& jid,
43 bool connected) {
44 DCHECK(CalledOnValidThread());
45
46 scoped_ptr<ServerLogEntry> entry(
47 MakeLogEntryForSessionStateChange(connected));
48 AddHostFieldsToLogEntry(entry.get());
49 entry->AddModeField(mode_);
50
51 if (connected) {
52 DCHECK(connection_route_type_.count(jid) == 1);
53 AddConnectionTypeToLogEntry(entry.get(), connection_route_type_[jid]);
54 }
55 Log(*entry.get());
56 } 29 }
57 30
58 void LogToServer::OnSignalStrategyStateChange(SignalStrategy::State state) { 31 void LogToServer::OnSignalStrategyStateChange(SignalStrategy::State state) {
59 DCHECK(CalledOnValidThread()); 32 DCHECK(CalledOnValidThread());
60 33
61 if (state == SignalStrategy::CONNECTED) { 34 if (state == SignalStrategy::CONNECTED) {
62 iq_sender_.reset(new IqSender(signal_strategy_)); 35 iq_sender_.reset(new IqSender(signal_strategy_));
63 SendPendingEntries(); 36 SendPendingEntries();
64 } else if (state == SignalStrategy::DISCONNECTED) { 37 } else if (state == SignalStrategy::DISCONNECTED) {
65 iq_sender_.reset(); 38 iq_sender_.reset();
66 } 39 }
67 } 40 }
68 41
69 bool LogToServer::OnSignalStrategyIncomingStanza( 42 bool LogToServer::OnSignalStrategyIncomingStanza(
70 const buzz::XmlElement* stanza) { 43 const buzz::XmlElement* stanza) {
71 return false; 44 return false;
72 } 45 }
73 46
74 void LogToServer::OnClientConnected(const std::string& jid) {
75 DCHECK(CalledOnValidThread());
76 LogSessionStateChange(jid, true);
77 }
78
79 void LogToServer::OnClientDisconnected(const std::string& jid) {
80 DCHECK(CalledOnValidThread());
81 LogSessionStateChange(jid, false);
82 connection_route_type_.erase(jid);
83 }
84
85 void LogToServer::OnClientRouteChange(const std::string& jid,
86 const std::string& channel_name,
87 const protocol::TransportRoute& route) {
88 // Store connection type for the video channel. It is logged later
89 // when client authentication is finished.
90 if (channel_name == kVideoChannelName) {
91 connection_route_type_[jid] = route.type;
92 }
93 }
94
95 void LogToServer::Log(const ServerLogEntry& entry) { 47 void LogToServer::Log(const ServerLogEntry& entry) {
96 pending_entries_.push_back(entry); 48 pending_entries_.push_back(entry);
97 SendPendingEntries(); 49 SendPendingEntries();
98 } 50 }
99 51
100 void LogToServer::SendPendingEntries() { 52 void LogToServer::SendPendingEntries() {
101 if (iq_sender_ == NULL) { 53 if (iq_sender_ == NULL) {
102 return; 54 return;
103 } 55 }
104 if (pending_entries_.empty()) { 56 if (pending_entries_.empty()) {
105 return; 57 return;
106 } 58 }
107 // Make one stanza containing all the pending entries. 59 // Make one stanza containing all the pending entries.
108 scoped_ptr<XmlElement> stanza(ServerLogEntry::MakeStanza()); 60 scoped_ptr<XmlElement> stanza(ServerLogEntry::MakeStanza());
109 while (!pending_entries_.empty()) { 61 while (!pending_entries_.empty()) {
110 ServerLogEntry& entry = pending_entries_.front(); 62 ServerLogEntry& entry = pending_entries_.front();
111 stanza->AddElement(entry.ToStanza().release()); 63 stanza->AddElement(entry.ToStanza().release());
112 pending_entries_.pop_front(); 64 pending_entries_.pop_front();
113 } 65 }
114 // Send the stanza to the server. 66 // Send the stanza to the server.
115 scoped_ptr<IqRequest> req = iq_sender_->SendIq( 67 scoped_ptr<IqRequest> req = iq_sender_->SendIq(
116 buzz::STR_SET, directory_bot_jid_, stanza.Pass(), 68 buzz::STR_SET, directory_bot_jid_, stanza.Pass(),
117 IqSender::ReplyCallback()); 69 IqSender::ReplyCallback());
118 // We ignore any response, so let the IqRequest be destroyed. 70 // We ignore any response, so let the IqRequest be destroyed.
119 return; 71 return;
120 } 72 }
121 73
122 } // namespace remoting 74 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698