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

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

Issue 1526063003: EDK: Add TaskRunner and PlatformHandleWatcher to RawChannel. (Closed) Base URL: https://github.com/domokit/mojo.git@channel_watcher
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/slave_connection_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/slave_connection_manager.h" 5 #include "mojo/edk/system/slave_connection_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 14 matching lines...) Expand all
25 using mojo::util::RefPtr; 25 using mojo::util::RefPtr;
26 26
27 namespace mojo { 27 namespace mojo {
28 namespace system { 28 namespace system {
29 29
30 // SlaveConnectionManager ------------------------------------------------------ 30 // SlaveConnectionManager ------------------------------------------------------
31 31
32 SlaveConnectionManager::SlaveConnectionManager( 32 SlaveConnectionManager::SlaveConnectionManager(
33 embedder::PlatformSupport* platform_support) 33 embedder::PlatformSupport* platform_support)
34 : ConnectionManager(platform_support), 34 : ConnectionManager(platform_support),
35 slave_process_delegate_(), 35 slave_process_delegate_(nullptr),
36 private_thread_platform_handle_watcher_(nullptr),
36 awaiting_ack_type_(NOT_AWAITING_ACK), 37 awaiting_ack_type_(NOT_AWAITING_ACK),
37 ack_result_(nullptr), 38 ack_result_(nullptr),
38 ack_peer_process_identifier_(nullptr), 39 ack_peer_process_identifier_(nullptr),
39 ack_is_first_(nullptr), 40 ack_is_first_(nullptr),
40 ack_platform_handle_(nullptr) {} 41 ack_platform_handle_(nullptr) {}
41 42
42 SlaveConnectionManager::~SlaveConnectionManager() { 43 SlaveConnectionManager::~SlaveConnectionManager() {
43 DCHECK(!delegate_thread_task_runner_); 44 DCHECK(!delegate_thread_task_runner_);
44 DCHECK(!slave_process_delegate_); 45 DCHECK(!slave_process_delegate_);
45 DCHECK(!private_thread_); 46 DCHECK(!private_thread_);
(...skipping 10 matching lines...) Expand all
56 ScopedPlatformHandle platform_handle) { 57 ScopedPlatformHandle platform_handle) {
57 DCHECK(delegate_thread_task_runner); 58 DCHECK(delegate_thread_task_runner);
58 DCHECK(slave_process_delegate); 59 DCHECK(slave_process_delegate);
59 DCHECK(platform_handle.is_valid()); 60 DCHECK(platform_handle.is_valid());
60 DCHECK(!delegate_thread_task_runner_); 61 DCHECK(!delegate_thread_task_runner_);
61 DCHECK(!slave_process_delegate_); 62 DCHECK(!slave_process_delegate_);
62 DCHECK(!private_thread_); 63 DCHECK(!private_thread_);
63 64
64 delegate_thread_task_runner_ = std::move(delegate_thread_task_runner); 65 delegate_thread_task_runner_ = std::move(delegate_thread_task_runner);
65 slave_process_delegate_ = slave_process_delegate; 66 slave_process_delegate_ = slave_process_delegate;
66 // TODO(vtl): We'll need to plumb this in further.
67 PlatformHandleWatcher* platform_handle_watcher = nullptr;
68 private_thread_ = platform::CreateAndStartIOThread( 67 private_thread_ = platform::CreateAndStartIOThread(
69 &private_thread_task_runner_, &platform_handle_watcher); 68 &private_thread_task_runner_, &private_thread_platform_handle_watcher_);
70 // TODO(vtl): With C++14 lambda captures, we'll be able to move 69 // TODO(vtl): With C++14 lambda captures, we'll be able to move
71 // |platform_handle|. 70 // |platform_handle|.
72 auto raw_platform_handle = platform_handle.release(); 71 auto raw_platform_handle = platform_handle.release();
73 private_thread_task_runner_->PostTask([this, raw_platform_handle]() { 72 private_thread_task_runner_->PostTask([this, raw_platform_handle]() {
74 InitOnPrivateThread( 73 InitOnPrivateThread(
75 ScopedPlatformHandle(PlatformHandle(raw_platform_handle))); 74 ScopedPlatformHandle(PlatformHandle(raw_platform_handle)));
76 }); 75 });
77 event_.Wait(); 76 event_.Wait();
78 } 77 }
79 78
80 void SlaveConnectionManager::Shutdown() { 79 void SlaveConnectionManager::Shutdown() {
81 AssertNotOnPrivateThread(); 80 AssertNotOnPrivateThread();
82 DCHECK(slave_process_delegate_); 81 DCHECK(slave_process_delegate_);
83 DCHECK(private_thread_); 82 DCHECK(private_thread_);
84 83
85 // The |Stop()| will actually finish all posted tasks. 84 // The |Stop()| will actually finish all posted tasks.
86 private_thread_task_runner_->PostTask( 85 private_thread_task_runner_->PostTask(
87 [this]() { ShutdownOnPrivateThread(); }); 86 [this]() { ShutdownOnPrivateThread(); });
88 private_thread_->Stop(); 87 private_thread_->Stop();
89 private_thread_.reset(); 88 private_thread_.reset();
90 private_thread_task_runner_ = nullptr; 89 private_thread_task_runner_ = nullptr;
90 private_thread_platform_handle_watcher_ = nullptr;
91 slave_process_delegate_ = nullptr; 91 slave_process_delegate_ = nullptr;
92 delegate_thread_task_runner_ = nullptr; 92 delegate_thread_task_runner_ = nullptr;
93 } 93 }
94 94
95 bool SlaveConnectionManager::AllowConnect( 95 bool SlaveConnectionManager::AllowConnect(
96 const ConnectionIdentifier& connection_id) { 96 const ConnectionIdentifier& connection_id) {
97 AssertNotOnPrivateThread(); 97 AssertNotOnPrivateThread();
98 98
99 MutexLocker locker(&mutex_); 99 MutexLocker locker(&mutex_);
100 Result result = Result::FAILURE; 100 Result result = Result::FAILURE;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 }); 141 });
142 event_.Wait(); 142 event_.Wait();
143 return result; 143 return result;
144 } 144 }
145 145
146 void SlaveConnectionManager::InitOnPrivateThread( 146 void SlaveConnectionManager::InitOnPrivateThread(
147 ScopedPlatformHandle platform_handle) { 147 ScopedPlatformHandle platform_handle) {
148 AssertOnPrivateThread(); 148 AssertOnPrivateThread();
149 149
150 raw_channel_ = RawChannel::Create(platform_handle.Pass()); 150 raw_channel_ = RawChannel::Create(platform_handle.Pass());
151 raw_channel_->Init(this); 151 raw_channel_->Init(private_thread_task_runner_.Clone(),
152 private_thread_platform_handle_watcher_, this);
152 event_.Signal(); 153 event_.Signal();
153 } 154 }
154 155
155 void SlaveConnectionManager::ShutdownOnPrivateThread() { 156 void SlaveConnectionManager::ShutdownOnPrivateThread() {
156 AssertOnPrivateThread(); 157 AssertOnPrivateThread();
157 158
158 CHECK_EQ(awaiting_ack_type_, NOT_AWAITING_ACK); 159 CHECK_EQ(awaiting_ack_type_, NOT_AWAITING_ACK);
159 if (raw_channel_) { 160 if (raw_channel_) {
160 raw_channel_->Shutdown(); 161 raw_channel_->Shutdown();
161 raw_channel_.reset(); 162 raw_channel_.reset();
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 DCHECK(!private_thread_task_runner_->RunsTasksOnCurrentThread()); 348 DCHECK(!private_thread_task_runner_->RunsTasksOnCurrentThread());
348 } 349 }
349 350
350 void SlaveConnectionManager::AssertOnPrivateThread() const { 351 void SlaveConnectionManager::AssertOnPrivateThread() const {
351 // This should only be called after |Init()| and before |Shutdown()|. 352 // This should only be called after |Init()| and before |Shutdown()|.
352 DCHECK(private_thread_task_runner_->RunsTasksOnCurrentThread()); 353 DCHECK(private_thread_task_runner_->RunsTasksOnCurrentThread());
353 } 354 }
354 355
355 } // namespace system 356 } // namespace system
356 } // namespace mojo 357 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/slave_connection_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698