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

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

Issue 7218061: Close all writers before JingleSession is destroyed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 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) 2011 The Chromium Authors. All rights reserved. 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 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/connection_to_client.h" 5 #include "remoting/protocol/connection_to_client.h"
6 6
7 #include "google/protobuf/message.h" 7 #include "google/protobuf/message.h"
8 #include "net/base/io_buffer.h" 8 #include "net/base/io_buffer.h"
9 #include "remoting/protocol/client_control_sender.h" 9 #include "remoting/protocol/client_control_sender.h"
10 #include "remoting/protocol/host_message_dispatcher.h" 10 #include "remoting/protocol/host_message_dispatcher.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 void ConnectionToClient::Disconnect() { 51 void ConnectionToClient::Disconnect() {
52 // This method can be called from main thread so perform threading switching. 52 // This method can be called from main thread so perform threading switching.
53 if (MessageLoop::current() != loop_) { 53 if (MessageLoop::current() != loop_) {
54 loop_->PostTask( 54 loop_->PostTask(
55 FROM_HERE, 55 FROM_HERE,
56 NewRunnableMethod(this, &ConnectionToClient::Disconnect)); 56 NewRunnableMethod(this, &ConnectionToClient::Disconnect));
57 return; 57 return;
58 } 58 }
59 59
60 if (video_writer_.get())
61 video_writer_->Close();
62 if (client_control_sender_.get())
63 client_control_sender_->Close();
Wez 2011/06/30 18:27:31 We Close() these in Disconnect(), but we created t
Sergey Ulanov 2011/06/30 20:55:24 Done.
64
60 // If there is a channel then close it and release the reference. 65 // If there is a channel then close it and release the reference.
61 if (session_) { 66 if (session_) {
62 session_->Close(NewRunnableMethod(this, &ConnectionToClient::OnClosed)); 67 session_->Close(NewRunnableMethod(this, &ConnectionToClient::OnClosed));
63 session_ = NULL; 68 session_ = NULL;
64 } 69 }
65 } 70 }
66 71
67 void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) { 72 void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) {
68 handler_->OnSequenceNumberUpdated(this, sequence_number); 73 handler_->OnSequenceNumberUpdated(this, sequence_number);
69 } 74 }
70 75
71 VideoStub* ConnectionToClient::video_stub() { 76 VideoStub* ConnectionToClient::video_stub() {
72 return video_writer_.get(); 77 return video_writer_.get();
73 } 78 }
74 79
75 // Return pointer to ClientStub. 80 // Return pointer to ClientStub.
76 ClientStub* ConnectionToClient::client_stub() { 81 ClientStub* ConnectionToClient::client_stub() {
77 return client_stub_.get(); 82 return client_control_sender_.get();
78 } 83 }
79 84
80 void ConnectionToClient::set_host_stub(protocol::HostStub* host_stub) { 85 void ConnectionToClient::set_host_stub(protocol::HostStub* host_stub) {
81 host_stub_ = host_stub; 86 host_stub_ = host_stub;
82 } 87 }
83 88
84 void ConnectionToClient::set_input_stub(protocol::InputStub* input_stub) { 89 void ConnectionToClient::set_input_stub(protocol::InputStub* input_stub) {
85 input_stub_ = input_stub; 90 input_stub_ = input_stub;
86 } 91 }
87 92
88 void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) { 93 void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) {
89 if (state == protocol::Session::CONNECTED) {
90 client_stub_.reset(new ClientControlSender(session_->control_channel()));
91 video_writer_.reset(VideoWriter::Create(session_->config()));
92 video_writer_->Init(session_);
93
94 dispatcher_.reset(new HostMessageDispatcher());
95 dispatcher_->Initialize(this, host_stub_, input_stub_);
96 }
97
98 // This method can be called from main thread so perform threading switching.
99 if (MessageLoop::current() != loop_) {
100 loop_->PostTask(
101 FROM_HERE,
102 NewRunnableMethod(this, &ConnectionToClient::StateChangeTask, state));
103 } else {
104 StateChangeTask(state);
105 }
106 }
107
108 void ConnectionToClient::StateChangeTask(protocol::Session::State state) {
109 DCHECK_EQ(loop_, MessageLoop::current()); 94 DCHECK_EQ(loop_, MessageLoop::current());
110 95
111 DCHECK(handler_); 96 DCHECK(handler_);
112 switch(state) { 97 switch(state) {
113 case protocol::Session::CONNECTING: 98 case protocol::Session::CONNECTING:
114 break; 99 break;
115 // Don't care about this message. 100 // Don't care about this message.
116 case protocol::Session::CONNECTED: 101 case protocol::Session::CONNECTED:
102 client_control_sender_.reset(
103 new ClientControlSender(session_->control_channel()));
104 video_writer_.reset(VideoWriter::Create(session_->config()));
105 video_writer_->Init(session_);
106
107 dispatcher_.reset(new HostMessageDispatcher());
108 dispatcher_->Initialize(this, host_stub_, input_stub_);
109
117 handler_->OnConnectionOpened(this); 110 handler_->OnConnectionOpened(this);
118 break; 111 break;
119 case protocol::Session::CLOSED: 112 case protocol::Session::CLOSED:
120 handler_->OnConnectionClosed(this); 113 handler_->OnConnectionClosed(this);
121 break; 114 break;
122 case protocol::Session::FAILED: 115 case protocol::Session::FAILED:
123 handler_->OnConnectionFailed(this); 116 handler_->OnConnectionFailed(this);
124 break; 117 break;
125 default: 118 default:
126 // We shouldn't receive other states. 119 // We shouldn't receive other states.
127 NOTREACHED(); 120 NOTREACHED();
128 } 121 }
129 } 122 }
130 123
131 // OnClosed() is used as a callback for protocol::Session::Close(). 124 // OnClosed() is used as a callback for protocol::Session::Close().
132 void ConnectionToClient::OnClosed() { 125 void ConnectionToClient::OnClosed() {
133 } 126 }
134 127
135 } // namespace protocol 128 } // namespace protocol
136 } // namespace remoting 129 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698