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

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

Issue 910883002: Update mojo sdk to rev 8af2ccff2eee4bfca1043015abee30482a030b30 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Apply 9f87aeadbda22441b7d469e596f7bd7d0d73e2a8 (https://codereview.chromium.org/908973002/) Created 5 years, 10 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
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "mojo/edk/system/message_in_transit.h" 12 #include "mojo/edk/system/message_in_transit.h"
13 13
14 namespace mojo { 14 namespace mojo {
15 namespace system { 15 namespace system {
16 16
17 // SlaveConnectionManager ------------------------------------------------------ 17 // SlaveConnectionManager ------------------------------------------------------
18 18
19 SlaveConnectionManager::SlaveConnectionManager() 19 SlaveConnectionManager::SlaveConnectionManager()
20 : creation_thread_task_runner_(base::MessageLoop::current()->task_runner()), 20 : slave_process_delegate_(),
21 slave_process_delegate_(),
22 private_thread_("SlaveConnectionManagerPrivateThread"), 21 private_thread_("SlaveConnectionManagerPrivateThread"),
23 awaiting_ack_type_(NOT_AWAITING_ACK), 22 awaiting_ack_type_(NOT_AWAITING_ACK),
24 ack_result_(), 23 ack_result_(),
25 ack_peer_process_identifier_(), 24 ack_peer_process_identifier_(),
26 ack_platform_handle_(), 25 ack_platform_handle_(),
27 event_(false, false) { // Auto-reset, not initially signalled. 26 event_(false, false) { // Auto-reset, not initially signalled.
28 DCHECK(creation_thread_task_runner_);
29 AssertOnCreationThread(); // Just make sure this assertion works correctly.
30 } 27 }
31 28
32 SlaveConnectionManager::~SlaveConnectionManager() { 29 SlaveConnectionManager::~SlaveConnectionManager() {
33 AssertOnCreationThread(); 30 DCHECK(!delegate_thread_task_runner_);
34 DCHECK(!slave_process_delegate_); 31 DCHECK(!slave_process_delegate_);
35 DCHECK(!private_thread_.message_loop()); 32 DCHECK(!private_thread_.message_loop());
36 DCHECK_EQ(awaiting_ack_type_, NOT_AWAITING_ACK); 33 DCHECK_EQ(awaiting_ack_type_, NOT_AWAITING_ACK);
37 DCHECK(!ack_result_); 34 DCHECK(!ack_result_);
38 DCHECK(!ack_peer_process_identifier_); 35 DCHECK(!ack_peer_process_identifier_);
39 DCHECK(!ack_platform_handle_); 36 DCHECK(!ack_platform_handle_);
40 } 37 }
41 38
42 void SlaveConnectionManager::Init( 39 void SlaveConnectionManager::Init(
40 scoped_refptr<base::TaskRunner> delegate_thread_task_runner,
43 embedder::SlaveProcessDelegate* slave_process_delegate, 41 embedder::SlaveProcessDelegate* slave_process_delegate,
44 embedder::ScopedPlatformHandle platform_handle) { 42 embedder::ScopedPlatformHandle platform_handle) {
45 AssertOnCreationThread(); 43 DCHECK(delegate_thread_task_runner);
46 DCHECK(slave_process_delegate); 44 DCHECK(slave_process_delegate);
47 DCHECK(platform_handle.is_valid()); 45 DCHECK(platform_handle.is_valid());
46 DCHECK(!delegate_thread_task_runner_);
48 DCHECK(!slave_process_delegate_); 47 DCHECK(!slave_process_delegate_);
49 DCHECK(!private_thread_.message_loop()); 48 DCHECK(!private_thread_.message_loop());
50 49
50 delegate_thread_task_runner_ = delegate_thread_task_runner;
51 AssertOnDelegateThread();
51 slave_process_delegate_ = slave_process_delegate; 52 slave_process_delegate_ = slave_process_delegate;
52 CHECK(private_thread_.StartWithOptions( 53 CHECK(private_thread_.StartWithOptions(
53 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); 54 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
54 private_thread_.message_loop()->PostTask( 55 private_thread_.message_loop()->PostTask(
55 FROM_HERE, 56 FROM_HERE,
56 base::Bind(&SlaveConnectionManager::InitOnPrivateThread, 57 base::Bind(&SlaveConnectionManager::InitOnPrivateThread,
57 base::Unretained(this), base::Passed(&platform_handle))); 58 base::Unretained(this), base::Passed(&platform_handle)));
58 event_.Wait(); 59 event_.Wait();
59 } 60 }
60 61
61 void SlaveConnectionManager::Shutdown() { 62 void SlaveConnectionManager::Shutdown() {
62 AssertOnCreationThread(); 63 AssertOnDelegateThread();
63 DCHECK(slave_process_delegate_); 64 DCHECK(slave_process_delegate_);
64 DCHECK(private_thread_.message_loop()); 65 DCHECK(private_thread_.message_loop());
65 66
66 // The |Stop()| will actually finish all posted tasks. 67 // The |Stop()| will actually finish all posted tasks.
67 private_thread_.message_loop()->PostTask( 68 private_thread_.message_loop()->PostTask(
68 FROM_HERE, base::Bind(&SlaveConnectionManager::ShutdownOnPrivateThread, 69 FROM_HERE, base::Bind(&SlaveConnectionManager::ShutdownOnPrivateThread,
69 base::Unretained(this))); 70 base::Unretained(this)));
70 private_thread_.Stop(); 71 private_thread_.Stop();
71 slave_process_delegate_ = nullptr; 72 slave_process_delegate_ = nullptr;
73 delegate_thread_task_runner_ = nullptr;
72 } 74 }
73 75
74 bool SlaveConnectionManager::AllowConnect( 76 bool SlaveConnectionManager::AllowConnect(
75 const ConnectionIdentifier& connection_id) { 77 const ConnectionIdentifier& connection_id) {
76 AssertNotOnPrivateThread(); 78 AssertNotOnPrivateThread();
77 79
78 base::AutoLock locker(lock_); 80 base::AutoLock locker(lock_);
79 bool result = false; 81 bool result = false;
80 private_thread_.message_loop()->PostTask( 82 private_thread_.message_loop()->PostTask(
81 FROM_HERE, 83 FROM_HERE,
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 AssertOnPrivateThread(); 282 AssertOnPrivateThread();
281 283
282 // Ignore write errors, since we may still have some messages to read. 284 // Ignore write errors, since we may still have some messages to read.
283 if (error == RawChannel::Delegate::ERROR_WRITE) 285 if (error == RawChannel::Delegate::ERROR_WRITE)
284 return; 286 return;
285 287
286 raw_channel_->Shutdown(); 288 raw_channel_->Shutdown();
287 raw_channel_.reset(); 289 raw_channel_.reset();
288 290
289 DCHECK(slave_process_delegate_); 291 DCHECK(slave_process_delegate_);
290 creation_thread_task_runner_->PostTask( 292 delegate_thread_task_runner_->PostTask(
291 FROM_HERE, base::Bind(&embedder::SlaveProcessDelegate::OnMasterDisconnect, 293 FROM_HERE, base::Bind(&embedder::SlaveProcessDelegate::OnMasterDisconnect,
292 base::Unretained(slave_process_delegate_))); 294 base::Unretained(slave_process_delegate_)));
293 } 295 }
294 296
295 void SlaveConnectionManager::AssertOnCreationThread() const { 297 void SlaveConnectionManager::AssertOnDelegateThread() const {
296 DCHECK(base::MessageLoop::current()); 298 DCHECK(base::MessageLoop::current());
297 DCHECK_EQ(base::MessageLoop::current()->task_runner(), 299 DCHECK_EQ(base::MessageLoop::current()->task_runner(),
298 creation_thread_task_runner_); 300 delegate_thread_task_runner_);
299 } 301 }
300 302
301 void SlaveConnectionManager::AssertNotOnPrivateThread() const { 303 void SlaveConnectionManager::AssertNotOnPrivateThread() const {
302 // This should only be called after |Init()| and before |Shutdown()|. (If not, 304 // This should only be called after |Init()| and before |Shutdown()|. (If not,
303 // the subsequent |DCHECK_NE()| is invalid, since the current thread may not 305 // the subsequent |DCHECK_NE()| is invalid, since the current thread may not
304 // have a message loop.) 306 // have a message loop.)
305 DCHECK(private_thread_.message_loop()); 307 DCHECK(private_thread_.message_loop());
306 DCHECK_NE(base::MessageLoop::current(), private_thread_.message_loop()); 308 DCHECK_NE(base::MessageLoop::current(), private_thread_.message_loop());
307 } 309 }
308 310
309 void SlaveConnectionManager::AssertOnPrivateThread() const { 311 void SlaveConnectionManager::AssertOnPrivateThread() const {
310 // This should only be called after |Init()| and before |Shutdown()|. 312 // This should only be called after |Init()| and before |Shutdown()|.
311 DCHECK(private_thread_.message_loop()); 313 DCHECK(private_thread_.message_loop());
312 DCHECK_EQ(base::MessageLoop::current(), private_thread_.message_loop()); 314 DCHECK_EQ(base::MessageLoop::current(), private_thread_.message_loop());
313 } 315 }
314 316
315 } // namespace system 317 } // namespace system
316 } // namespace mojo 318 } // namespace mojo
OLDNEW
« no previous file with comments | « third_party/mojo/src/mojo/edk/system/slave_connection_manager.h ('k') | third_party/mojo/src/mojo/public/VERSION » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698