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

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

Issue 1525883002: EDK: Add PlatformHandleWatcher to IPCSupport class. (Closed) Base URL: https://github.com/domokit/mojo.git@embedder_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/ipc_support.h ('k') | mojo/edk/system/ipc_support_unittest.cc » ('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 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/ipc_support.h" 5 #include "mojo/edk/system/ipc_support.h"
6 6
7 #include <type_traits> 7 #include <type_traits>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "mojo/edk/embedder/master_process_delegate.h" 11 #include "mojo/edk/embedder/master_process_delegate.h"
12 #include "mojo/edk/embedder/slave_process_delegate.h" 12 #include "mojo/edk/embedder/slave_process_delegate.h"
13 #include "mojo/edk/system/channel_manager.h" 13 #include "mojo/edk/system/channel_manager.h"
14 #include "mojo/edk/system/master_connection_manager.h" 14 #include "mojo/edk/system/master_connection_manager.h"
15 #include "mojo/edk/system/message_pipe_dispatcher.h" 15 #include "mojo/edk/system/message_pipe_dispatcher.h"
16 #include "mojo/edk/system/slave_connection_manager.h" 16 #include "mojo/edk/system/slave_connection_manager.h"
17 17
18 using mojo::platform::PlatformHandleWatcher;
18 using mojo::platform::ScopedPlatformHandle; 19 using mojo::platform::ScopedPlatformHandle;
19 using mojo::platform::TaskRunner; 20 using mojo::platform::TaskRunner;
20 using mojo::util::RefPtr; 21 using mojo::util::RefPtr;
21 22
22 namespace mojo { 23 namespace mojo {
23 namespace system { 24 namespace system {
24 25
25 IPCSupport::IPCSupport(embedder::PlatformSupport* platform_support, 26 IPCSupport::IPCSupport(embedder::PlatformSupport* platform_support,
26 embedder::ProcessType process_type, 27 embedder::ProcessType process_type,
27 RefPtr<TaskRunner>&& delegate_thread_task_runner, 28 RefPtr<TaskRunner>&& delegate_thread_task_runner,
28 embedder::ProcessDelegate* process_delegate, 29 embedder::ProcessDelegate* process_delegate,
29 RefPtr<TaskRunner>&& io_thread_task_runner, 30 RefPtr<TaskRunner>&& io_task_runner,
31 PlatformHandleWatcher* io_watcher,
30 ScopedPlatformHandle platform_handle) 32 ScopedPlatformHandle platform_handle)
31 : process_type_(process_type), 33 : process_type_(process_type),
32 delegate_thread_task_runner_(std::move(delegate_thread_task_runner)), 34 delegate_thread_task_runner_(std::move(delegate_thread_task_runner)),
33 process_delegate_(process_delegate), 35 process_delegate_(process_delegate),
34 io_thread_task_runner_(std::move(io_thread_task_runner)) { 36 io_task_runner_(std::move(io_task_runner)),
37 io_watcher_(io_watcher) {
35 DCHECK(delegate_thread_task_runner_); 38 DCHECK(delegate_thread_task_runner_);
36 DCHECK(io_thread_task_runner_); 39 DCHECK(io_task_runner_);
40 DCHECK(io_watcher_);
37 41
38 switch (process_type_) { 42 switch (process_type_) {
39 case embedder::ProcessType::UNINITIALIZED: 43 case embedder::ProcessType::UNINITIALIZED:
40 CHECK(false); 44 CHECK(false);
41 break; 45 break;
42 case embedder::ProcessType::NONE: 46 case embedder::ProcessType::NONE:
43 DCHECK(!platform_handle.is_valid()); // We wouldn't do anything with it. 47 DCHECK(!platform_handle.is_valid()); // We wouldn't do anything with it.
44 // Nothing to do. 48 // Nothing to do.
45 break; 49 break;
46 case embedder::ProcessType::MASTER: 50 case embedder::ProcessType::MASTER:
47 DCHECK(!platform_handle.is_valid()); // We wouldn't do anything with it. 51 DCHECK(!platform_handle.is_valid()); // We wouldn't do anything with it.
48 connection_manager_.reset( 52 connection_manager_.reset(
49 new system::MasterConnectionManager(platform_support)); 53 new system::MasterConnectionManager(platform_support));
50 static_cast<system::MasterConnectionManager*>(connection_manager_.get()) 54 static_cast<system::MasterConnectionManager*>(connection_manager_.get())
51 ->Init( 55 ->Init(
52 delegate_thread_task_runner_.Clone(), 56 delegate_thread_task_runner_.Clone(),
53 static_cast<embedder::MasterProcessDelegate*>(process_delegate_)); 57 static_cast<embedder::MasterProcessDelegate*>(process_delegate_));
54 break; 58 break;
55 case embedder::ProcessType::SLAVE: 59 case embedder::ProcessType::SLAVE:
56 connection_manager_.reset( 60 connection_manager_.reset(
57 new system::SlaveConnectionManager(platform_support)); 61 new system::SlaveConnectionManager(platform_support));
58 static_cast<system::SlaveConnectionManager*>(connection_manager_.get()) 62 static_cast<system::SlaveConnectionManager*>(connection_manager_.get())
59 ->Init( 63 ->Init(
60 delegate_thread_task_runner_.Clone(), 64 delegate_thread_task_runner_.Clone(),
61 static_cast<embedder::SlaveProcessDelegate*>(process_delegate_), 65 static_cast<embedder::SlaveProcessDelegate*>(process_delegate_),
62 platform_handle.Pass()); 66 platform_handle.Pass());
63 break; 67 break;
64 } 68 }
65 69
66 channel_manager_.reset(new ChannelManager(platform_support, 70 channel_manager_.reset(new ChannelManager(
67 io_thread_task_runner_.Clone(), 71 platform_support, io_task_runner_.Clone(), connection_manager_.get()));
68 connection_manager_.get()));
69 } 72 }
70 73
71 IPCSupport::~IPCSupport() { 74 IPCSupport::~IPCSupport() {
72 DCHECK_EQ(process_type_, embedder::ProcessType::UNINITIALIZED); 75 DCHECK_EQ(process_type_, embedder::ProcessType::UNINITIALIZED);
73 } 76 }
74 77
75 void IPCSupport::ShutdownOnIOThread() { 78 void IPCSupport::ShutdownOnIOThread() {
76 DCHECK_NE(process_type_, embedder::ProcessType::UNINITIALIZED); 79 DCHECK_NE(process_type_, embedder::ProcessType::UNINITIALIZED);
77 80
78 channel_manager_->ShutdownOnIOThread(); 81 channel_manager_->ShutdownOnIOThread();
79 channel_manager_.reset(); 82 channel_manager_.reset();
80 83
81 if (connection_manager_) { 84 if (connection_manager_) {
82 connection_manager_->Shutdown(); 85 connection_manager_->Shutdown();
83 connection_manager_.reset(); 86 connection_manager_.reset();
84 } 87 }
85 88
86 io_thread_task_runner_ = nullptr; 89 io_watcher_ = nullptr;
90 io_task_runner_ = nullptr;
87 process_delegate_ = nullptr; 91 process_delegate_ = nullptr;
88 delegate_thread_task_runner_ = nullptr; 92 delegate_thread_task_runner_ = nullptr;
89 process_type_ = embedder::ProcessType::UNINITIALIZED; 93 process_type_ = embedder::ProcessType::UNINITIALIZED;
90 } 94 }
91 95
92 ConnectionIdentifier IPCSupport::GenerateConnectionIdentifier() { 96 ConnectionIdentifier IPCSupport::GenerateConnectionIdentifier() {
93 return connection_manager()->GenerateConnectionIdentifier(); 97 return connection_manager()->GenerateConnectionIdentifier();
94 } 98 }
95 99
96 RefPtr<MessagePipeDispatcher> IPCSupport::ConnectToSlave( 100 RefPtr<MessagePipeDispatcher> IPCSupport::ConnectToSlave(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 CHECK_EQ(connection_manager()->Connect(connection_id, &peer_id, &is_first, 168 CHECK_EQ(connection_manager()->Connect(connection_id, &peer_id, &is_first,
165 &platform_connection_handle), 169 &platform_connection_handle),
166 ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION); 170 ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION);
167 DCHECK_EQ(peer_id, system::kMasterProcessIdentifier); 171 DCHECK_EQ(peer_id, system::kMasterProcessIdentifier);
168 DCHECK(platform_connection_handle.is_valid()); 172 DCHECK(platform_connection_handle.is_valid());
169 return platform_connection_handle; 173 return platform_connection_handle;
170 } 174 }
171 175
172 } // namespace system 176 } // namespace system
173 } // namespace mojo 177 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/ipc_support.h ('k') | mojo/edk/system/ipc_support_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698