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

Side by Side Diff: mojo/edk/system/channel.cc

Issue 1530443005: EDK: Add PlatformHandleWatcher to Channel (and ChannelManager) classes. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « mojo/edk/system/channel.h ('k') | mojo/edk/system/channel_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "mojo/edk/system/channel.h" 5 #include "mojo/edk/system/channel.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "mojo/edk/system/endpoint_relayer.h" 11 #include "mojo/edk/system/endpoint_relayer.h"
12 #include "mojo/edk/system/transport_data.h" 12 #include "mojo/edk/system/transport_data.h"
13 #include "mojo/edk/util/string_printf.h" 13 #include "mojo/edk/util/string_printf.h"
14 14
15 using mojo::platform::PlatformHandleWatcher;
15 using mojo::platform::ScopedPlatformHandle; 16 using mojo::platform::ScopedPlatformHandle;
17 using mojo::platform::TaskRunner;
16 using mojo::util::MakeRefCounted; 18 using mojo::util::MakeRefCounted;
17 using mojo::util::MutexLocker; 19 using mojo::util::MutexLocker;
18 using mojo::util::RefPtr; 20 using mojo::util::RefPtr;
19 using mojo::util::StringPrintf; 21 using mojo::util::StringPrintf;
20 22
21 namespace mojo { 23 namespace mojo {
22 namespace system { 24 namespace system {
23 25
24 namespace { 26 namespace {
25 27
26 struct SerializedEndpoint { 28 struct SerializedEndpoint {
27 // This is the endpoint ID on the receiving side, and should be a "remote ID". 29 // This is the endpoint ID on the receiving side, and should be a "remote ID".
28 // (The receiving side should already have had an endpoint attached and been 30 // (The receiving side should already have had an endpoint attached and been
29 // run via the |Channel|s. This endpoint will have both IDs assigned, so this 31 // run via the |Channel|s. This endpoint will have both IDs assigned, so this
30 // ID is only needed to associate that endpoint with a particular dispatcher.) 32 // ID is only needed to associate that endpoint with a particular dispatcher.)
31 ChannelEndpointId receiver_endpoint_id; 33 ChannelEndpointId receiver_endpoint_id;
32 }; 34 };
33 35
34 } // namespace 36 } // namespace
35 37
36 void Channel::Init(std::unique_ptr<RawChannel> raw_channel) { 38 void Channel::Init(RefPtr<TaskRunner>&& io_task_runner,
39 PlatformHandleWatcher* io_watcher,
40 std::unique_ptr<RawChannel> raw_channel) {
37 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) 41 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
38 DCHECK(thread_checker_.IsCreationThreadCurrent()); 42 DCHECK(thread_checker_.IsCreationThreadCurrent());
39 #endif // !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) 43 #endif // !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
40 DCHECK(raw_channel); 44 DCHECK(raw_channel);
41 45
42 // No need to take |mutex_|, since this must be called before this object 46 // No need to take |mutex_|, since this must be called before this object
43 // becomes thread-safe. 47 // becomes thread-safe.
44 DCHECK(!is_running_); 48 DCHECK(!is_running_);
45 raw_channel_ = std::move(raw_channel); 49 raw_channel_ = std::move(raw_channel);
50 // TODO(vtl): Add explicit |io_task_runner| and |io_watcher| arguments to
51 // |RawChannel::Init()| and pass them on.
46 raw_channel_->Init(this); 52 raw_channel_->Init(this);
47 is_running_ = true; 53 is_running_ = true;
48 } 54 }
49 55
50 void Channel::SetChannelManager(ChannelManager* channel_manager) { 56 void Channel::SetChannelManager(ChannelManager* channel_manager) {
51 DCHECK(channel_manager); 57 DCHECK(channel_manager);
52 58
53 MutexLocker locker(&mutex_); 59 MutexLocker locker(&mutex_);
54 DCHECK(!is_shutting_down_); 60 DCHECK(!is_shutting_down_);
55 DCHECK(!channel_manager_); 61 DCHECK(!channel_manager_);
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 << ", local ID " << local_id << ", remote ID " << remote_id; 648 << ", local ID " << local_id << ", remote ID " << remote_id;
643 std::unique_ptr<MessageInTransit> message(new MessageInTransit( 649 std::unique_ptr<MessageInTransit> message(new MessageInTransit(
644 MessageInTransit::Type::CHANNEL, subtype, num_bytes, bytes)); 650 MessageInTransit::Type::CHANNEL, subtype, num_bytes, bytes));
645 message->set_source_id(local_id); 651 message->set_source_id(local_id);
646 message->set_destination_id(remote_id); 652 message->set_destination_id(remote_id);
647 return WriteMessage(std::move(message)); 653 return WriteMessage(std::move(message));
648 } 654 }
649 655
650 } // namespace system 656 } // namespace system
651 } // namespace mojo 657 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/channel.h ('k') | mojo/edk/system/channel_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698