OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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/data_channel_handler.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "base/location.h" | |
10 #include "base/logging.h" | |
11 #include "base/threading/thread_task_runner_handle.h" | |
12 #include "remoting/base/compound_buffer.h" | |
13 | |
14 namespace remoting { | |
15 namespace protocol { | |
16 | |
17 DataChannelHandler::DataChannelHandler(const std::string& name, | |
18 std::unique_ptr<MessagePipe> pipe) | |
19 : name_(name), | |
20 pipe_(std::move(pipe)) { | |
21 DCHECK(pipe_); | |
22 pipe_->Start(this); | |
23 } | |
24 | |
25 DataChannelHandler::~DataChannelHandler() = default; | |
joedow
2017/05/30 16:24:17
Don't you want to call Close() in the d'tor?
Hzj_jie
2017/05/31 00:11:51
No, instead, destructor is called by Close() funct
Sergey Ulanov
2017/05/31 19:49:02
This is a rather bug-prone approach, we should be
Hzj_jie
2017/06/01 15:43:34
only
The public methods are only public for tests.
| |
26 | |
27 void DataChannelHandler::Close() { | |
28 DCHECK(thread_checker_.CalledOnValidThread()); | |
29 if (connected()) { | |
30 OnDisconnected(); | |
joedow
2017/05/30 16:24:17
Should this be called 'OnDisconnecting()'? You ar
Hzj_jie
2017/05/31 00:11:51
Since this is the only callback regarding to the d
joedow
2017/06/01 17:25:25
It is important as they have very different meanin
Hzj_jie
2017/06/01 19:32:08
Done.
| |
31 is_connected_ = false; | |
32 } | |
33 if (!closed()) { | |
34 pipe_.reset(); | |
35 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | |
joedow
2017/05/30 16:24:17
This feels weird, I'm not sure why the owner shoul
Hzj_jie
2017/05/31 00:11:51
Because the handler should be deleted once the Mes
Sergey Ulanov
2017/05/31 19:49:02
In order to send outgoing messages some other clas
Hzj_jie
2017/06/01 15:43:34
Yes, Send() is not intentionally used by any other
| |
36 } | |
37 } | |
38 | |
39 bool DataChannelHandler::Send(google::protobuf::MessageLite* message, | |
40 const base::Closure& done) { | |
41 DCHECK(thread_checker_.CalledOnValidThread()); | |
42 if (is_connected_) { | |
joedow
2017/05/30 16:24:17
You use your helper method above (connected()), it
Hzj_jie
2017/05/31 00:11:51
Done.
| |
43 pipe_->Send(message, done); | |
44 return true; | |
45 } | |
46 | |
47 return false; | |
48 } | |
49 | |
50 void DataChannelHandler::OnIncomingMessage( | |
51 std::unique_ptr<CompoundBuffer> message) {} | |
joedow
2017/05/30 16:24:17
Do these need to be implemented? If they are opti
Hzj_jie
2017/05/31 00:11:51
Observer pattern seems not fitting this class: the
| |
52 | |
53 void DataChannelHandler::OnConnected() {} | |
54 | |
55 void DataChannelHandler::OnDisconnected() {} | |
56 | |
57 void DataChannelHandler::OnMessagePipeOpen() { | |
58 DCHECK(thread_checker_.CalledOnValidThread()); | |
59 is_connected_ = true; | |
joedow
2017/05/30 16:24:17
DCHECK(!is_connected); to protect against multiple
Hzj_jie
2017/05/31 00:11:51
Done.
| |
60 OnConnected(); | |
61 } | |
62 | |
63 void DataChannelHandler::OnMessageReceived( | |
64 std::unique_ptr<CompoundBuffer> message) { | |
65 DCHECK(thread_checker_.CalledOnValidThread()); | |
66 OnIncomingMessage(std::move(message)); | |
67 } | |
68 | |
69 void DataChannelHandler::OnMessagePipeClosed() { | |
70 Close(); | |
71 } | |
72 | |
73 } // namespace protocol | |
74 } // namespace remoting | |
OLD | NEW |