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

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

Issue 2907073003: [Chromoting] Add DataChannelManager to manage optional incoming data channels (Closed)
Patch Set: Resolve review comments Created 3 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 unified diff | Download patch
OLDNEW
(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;
26
27 void DataChannelHandler::Close() {
28 DCHECK(thread_checker_.CalledOnValidThread());
29 if (connected()) {
30 OnDisconnecting();
31 is_connected_ = false;
32 }
33 if (!closing()) {
34 pipe_.reset();
35 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
joedow 2017/06/06 23:33:25 Why not just delete now instead of doing it async?
Hzj_jie 2017/06/07 17:31:24 If the DataChannelHandler works with a timer and t
36 }
37 }
38
39 bool DataChannelHandler::Send(google::protobuf::MessageLite* message,
40 const base::Closure& done) {
41 DCHECK(thread_checker_.CalledOnValidThread());
42 if (connected()) {
43 pipe_->Send(message, done);
44 return true;
45 }
46
47 return false;
joedow 2017/06/06 23:33:25 Why don't you want to DCHECK if someone tries to s
Hzj_jie 2017/06/07 17:31:24 It also relates to the potential usage of timer: t
48 }
49
50 void DataChannelHandler::OnIncomingMessage(
51 std::unique_ptr<CompoundBuffer> message) {}
52
53 void DataChannelHandler::OnConnected() {}
54
55 void DataChannelHandler::OnDisconnecting() {}
56
57 void DataChannelHandler::OnMessagePipeOpen() {
58 DCHECK(thread_checker_.CalledOnValidThread());
59 DCHECK(!is_connected_);
60 is_connected_ = true;
61 OnConnected();
62 }
63
64 void DataChannelHandler::OnMessageReceived(
65 std::unique_ptr<CompoundBuffer> message) {
66 DCHECK(thread_checker_.CalledOnValidThread());
67 OnIncomingMessage(std::move(message));
68 }
69
70 void DataChannelHandler::OnMessagePipeClosed() {
71 Close();
72 }
73
74 } // namespace protocol
75 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698