| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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/protocol/session_manager_pair.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "remoting/jingle_glue/jingle_thread.h" | |
| 9 #include "third_party/libjingle/source/talk/base/network.h" | |
| 10 #include "third_party/libjingle/source/talk/base/basicpacketsocketfactory.h" | |
| 11 #include "third_party/libjingle/source/talk/p2p/base/sessionmanager.h" | |
| 12 #include "third_party/libjingle/source/talk/p2p/client/basicportallocator.h" | |
| 13 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | |
| 14 | |
| 15 namespace remoting { | |
| 16 | |
| 17 const char SessionManagerPair::kHostJid[] = "host1@gmail.com/123"; | |
| 18 const char SessionManagerPair::kClientJid[] = "host2@gmail.com/321"; | |
| 19 | |
| 20 SessionManagerPair::SessionManagerPair(JingleThread* thread) | |
| 21 : message_loop_(thread->message_loop()) { | |
| 22 } | |
| 23 | |
| 24 SessionManagerPair::~SessionManagerPair() {} | |
| 25 | |
| 26 void SessionManagerPair::Init() { | |
| 27 DCHECK_EQ(message_loop_, MessageLoop::current()); | |
| 28 | |
| 29 network_manager_.reset(new talk_base::NetworkManager()); | |
| 30 socket_factory_.reset(new talk_base::BasicPacketSocketFactory( | |
| 31 talk_base::Thread::Current())); | |
| 32 | |
| 33 cricket::BasicPortAllocator* port_allocator = | |
| 34 new cricket::BasicPortAllocator(network_manager_.get(), | |
| 35 socket_factory_.get()); | |
| 36 port_allocator_.reset(port_allocator); | |
| 37 | |
| 38 host_session_manager_.reset(new cricket::SessionManager(port_allocator)); | |
| 39 host_session_manager_->SignalOutgoingMessage.connect( | |
| 40 this, &SessionManagerPair::ProcessMessage); | |
| 41 host_session_manager_->SignalRequestSignaling.connect( | |
| 42 host_session_manager_.get(), &cricket::SessionManager::OnSignalingReady); | |
| 43 | |
| 44 client_session_manager_.reset(new cricket::SessionManager(port_allocator)); | |
| 45 client_session_manager_->SignalOutgoingMessage.connect( | |
| 46 this, &SessionManagerPair::ProcessMessage); | |
| 47 client_session_manager_->SignalRequestSignaling.connect( | |
| 48 client_session_manager_.get(), | |
| 49 &cricket::SessionManager::OnSignalingReady); | |
| 50 } | |
| 51 | |
| 52 cricket::SessionManager* SessionManagerPair::host_session_manager() { | |
| 53 return host_session_manager_.get(); | |
| 54 } | |
| 55 | |
| 56 cricket::SessionManager* SessionManagerPair::client_session_manager() { | |
| 57 return client_session_manager_.get(); | |
| 58 } | |
| 59 | |
| 60 void SessionManagerPair::ProcessMessage(cricket::SessionManager* manager, | |
| 61 const buzz::XmlElement* stanza) { | |
| 62 message_loop_->PostTask( | |
| 63 FROM_HERE, NewRunnableMethod(this, &SessionManagerPair::DoProcessMessage, | |
| 64 manager, new buzz::XmlElement(*stanza))); | |
| 65 } | |
| 66 | |
| 67 void SessionManagerPair::DoProcessMessage(cricket::SessionManager* manager, | |
| 68 buzz::XmlElement* stanza) { | |
| 69 DCHECK_EQ(message_loop_, MessageLoop::current()); | |
| 70 DCHECK(manager == host_session_manager_.get() || | |
| 71 manager == client_session_manager_.get()); | |
| 72 buzz::QName from_attr("", "from"); | |
| 73 buzz::QName to_attr("", "to"); | |
| 74 std::string to = stanza->Attr(to_attr); | |
| 75 if (to == kHostJid) { | |
| 76 DCHECK(manager == client_session_manager_.get()); | |
| 77 stanza->SetAttr(from_attr, kClientJid); | |
| 78 DeliverMessage(host_session_manager_.get(), stanza); | |
| 79 } else if (to == kClientJid) { | |
| 80 DCHECK(manager == host_session_manager_.get()); | |
| 81 stanza->SetAttr(from_attr, kHostJid); | |
| 82 DeliverMessage(client_session_manager_.get(), stanza); | |
| 83 } else { | |
| 84 LOG(ERROR) << "Dropping stanza sent to unknown jid " << to; | |
| 85 } | |
| 86 delete stanza; | |
| 87 } | |
| 88 | |
| 89 void SessionManagerPair::DeliverMessage(cricket::SessionManager* to, | |
| 90 buzz::XmlElement* stanza) { | |
| 91 if (to->IsSessionMessage(stanza)) { | |
| 92 to->OnIncomingMessage(stanza); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 | |
| 97 } // namespace remoting | |
| OLD | NEW |