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

Unified Diff: remoting/client/host_connection.cc

Issue 2690003: Copy the (early prototype of) remoting in Chrome into the public tree.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/client/host_connection.h ('k') | remoting/client/pepper/fake_browser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/client/host_connection.cc
===================================================================
--- remoting/client/host_connection.cc (revision 0)
+++ remoting/client/host_connection.cc (revision 0)
@@ -0,0 +1,78 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/client/host_connection.h"
+
+namespace remoting {
+
+HostConnection::HostConnection(ProtocolDecoder* decoder,
+ EventHandler* handler)
+ : decoder_(decoder), handler_(handler) {
+}
+
+HostConnection::~HostConnection() {
+ Disconnect();
+}
+
+void HostConnection::Connect(const std::string& username,
+ const std::string& password,
+ const std::string& host_jid) {
+ jingle_client_ = new JingleClient();
+ jingle_client_->Init(username, password, this);
+ jingle_channel_ = jingle_client_->Connect(host_jid, this);
+}
+
+void HostConnection::Disconnect() {
+ if (jingle_channel_.get())
+ jingle_channel_->Close();
+
+ if (jingle_client_.get())
+ jingle_client_->Close();
+}
+
+void HostConnection::OnStateChange(JingleChannel* channel,
+ JingleChannel::State state) {
+ DCHECK(handler_);
+ if (state == JingleChannel::FAILED)
+ handler_->OnConnectionFailed(this);
+ else if (state == JingleChannel::CLOSED)
+ handler_->OnConnectionClosed(this);
+ else if (state == JingleChannel::OPEN)
+ handler_->OnConnectionOpened(this);
+}
+
+void HostConnection::OnPacketReceived(JingleChannel* channel,
+ scoped_refptr<media::DataBuffer> buffer) {
+ HostMessageList list;
+ decoder_->ParseHostMessages(buffer, &list);
+ DCHECK(handler_);
+ handler_->HandleMessages(this, &list);
+}
+
+// JingleClient::Callback interface.
+void HostConnection::OnStateChange(JingleClient* client,
+ JingleClient::State state) {
+ DCHECK(client);
+ DCHECK(handler_);
+ if (state == JingleClient::CONNECTED) {
+ LOG(INFO) << "Connected as: " << client->GetFullJid();
+ } else if (state == JingleClient::CLOSED) {
+ LOG(INFO) << "Connection closed.";
+ handler_->OnConnectionClosed(this);
+ }
+}
+
+bool HostConnection::OnAcceptConnection(JingleClient* client,
+ const std::string& jid,
+ JingleChannel::Callback** callback) {
+ // Client rejects all connection.
+ return false;
+}
+
+void HostConnection::OnNewConnection(JingleClient* client,
+ scoped_refptr<JingleChannel> channel) {
+ NOTREACHED() << "SimpleClient can't accept connection.";
+}
+
+} // namespace remoting
Property changes on: remoting/client/host_connection.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « remoting/client/host_connection.h ('k') | remoting/client/pepper/fake_browser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698