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

Side by Side Diff: remoting/protocol/channel_dispatcher_base.cc

Issue 841773005: Cleanup channel dispatchers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/protocol/channel_dispatcher_base.h" 5 #include "remoting/protocol/channel_dispatcher_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "net/socket/stream_socket.h" 8 #include "net/socket/stream_socket.h"
9 #include "remoting/protocol/session.h" 9 #include "remoting/protocol/session.h"
10 #include "remoting/protocol/session_config.h" 10 #include "remoting/protocol/session_config.h"
11 #include "remoting/protocol/stream_channel_factory.h" 11 #include "remoting/protocol/stream_channel_factory.h"
12 12
13 namespace remoting { 13 namespace remoting {
14 namespace protocol { 14 namespace protocol {
15 15
16 ChannelDispatcherBase::ChannelDispatcherBase(const char* channel_name) 16 ChannelDispatcherBase::ChannelDispatcherBase(const char* channel_name)
17 : channel_name_(channel_name), 17 : channel_name_(channel_name),
18 channel_factory_(nullptr) { 18 channel_factory_(nullptr),
19 event_handler_(nullptr) {
19 } 20 }
20 21
21 ChannelDispatcherBase::~ChannelDispatcherBase() { 22 ChannelDispatcherBase::~ChannelDispatcherBase() {
23 writer()->Close();
22 if (channel_factory_) 24 if (channel_factory_)
23 channel_factory_->CancelChannelCreation(channel_name_); 25 channel_factory_->CancelChannelCreation(channel_name_);
24 } 26 }
25 27
26 void ChannelDispatcherBase::Init(Session* session, 28 void ChannelDispatcherBase::Init(Session* session,
27 const ChannelConfig& config, 29 const ChannelConfig& config,
28 const InitializedCallback& callback) { 30 EventHandler* event_handler) {
29 DCHECK(session); 31 DCHECK(session);
30 switch (config.transport) { 32 switch (config.transport) {
31 case ChannelConfig::TRANSPORT_MUX_STREAM: 33 case ChannelConfig::TRANSPORT_MUX_STREAM:
32 channel_factory_ = session->GetMultiplexedChannelFactory(); 34 channel_factory_ = session->GetMultiplexedChannelFactory();
33 break; 35 break;
34 36
35 case ChannelConfig::TRANSPORT_STREAM: 37 case ChannelConfig::TRANSPORT_STREAM:
36 channel_factory_ = session->GetTransportChannelFactory(); 38 channel_factory_ = session->GetTransportChannelFactory();
37 break; 39 break;
38 40
39 default: 41 default:
40 NOTREACHED(); 42 LOG(FATAL) << "Unknown transport type: " << config.transport;
41 callback.Run(false);
42 return;
43 } 43 }
44 44
45 initialized_callback_ = callback; 45 event_handler_ = event_handler;
46 46
47 channel_factory_->CreateChannel(channel_name_, base::Bind( 47 channel_factory_->CreateChannel(channel_name_, base::Bind(
48 &ChannelDispatcherBase::OnChannelReady, base::Unretained(this))); 48 &ChannelDispatcherBase::OnChannelReady, base::Unretained(this)));
49 } 49 }
50 50
51 void ChannelDispatcherBase::OnChannelReady( 51 void ChannelDispatcherBase::OnChannelReady(
52 scoped_ptr<net::StreamSocket> socket) { 52 scoped_ptr<net::StreamSocket> socket) {
53 if (!socket.get()) { 53 if (!socket.get()) {
54 initialized_callback_.Run(false); 54 event_handler_->OnChannelError(this, CHANNEL_CONNECTION_ERROR);
55 return; 55 return;
56 } 56 }
57 57
58 channel_factory_ = nullptr; 58 channel_factory_ = nullptr;
59 channel_ = socket.Pass(); 59 channel_ = socket.Pass();
60 writer_.Init(channel_.get(), base::Bind(&ChannelDispatcherBase::OnWriteFailed,
rmsousa 2015/01/08 02:22:31 This means that every child of ChannelDispatcherBa
Sergey Ulanov 2015/01/08 19:20:32 Video and Audio channels are currently used in onl
61 base::Unretained(this)));
62 reader_.StartReading(channel_.get());
60 63
61 OnInitialized(); 64 event_handler_->OnChannelInitialized(this);
65 }
62 66
63 initialized_callback_.Run(true); 67 void ChannelDispatcherBase::OnWriteFailed(int error) {
68 event_handler_->OnChannelError(this, CHANNEL_CONNECTION_ERROR);
64 } 69 }
65 70
66 } // namespace protocol 71 } // namespace protocol
67 } // namespace remoting 72 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698