OLD | NEW |
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/master_connection_manager.h" | 5 #include "mojo/edk/system/master_connection_manager.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <unordered_map> | 8 #include <unordered_map> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "mojo/edk/embedder/master_process_delegate.h" | 17 #include "mojo/edk/embedder/master_process_delegate.h" |
18 #include "mojo/edk/embedder/platform_channel_pair.h" | 18 #include "mojo/edk/embedder/platform_channel_pair.h" |
19 #include "mojo/edk/embedder/platform_handle.h" | 19 #include "mojo/edk/platform/platform_handle.h" |
20 #include "mojo/edk/embedder/scoped_platform_handle.h" | 20 #include "mojo/edk/platform/scoped_platform_handle.h" |
21 #include "mojo/edk/system/connection_manager_messages.h" | 21 #include "mojo/edk/system/connection_manager_messages.h" |
22 #include "mojo/edk/system/message_in_transit.h" | 22 #include "mojo/edk/system/message_in_transit.h" |
23 #include "mojo/edk/system/raw_channel.h" | 23 #include "mojo/edk/system/raw_channel.h" |
24 #include "mojo/edk/system/transport_data.h" | 24 #include "mojo/edk/system/transport_data.h" |
25 #include "mojo/edk/util/make_unique.h" | 25 #include "mojo/edk/util/make_unique.h" |
26 #include "mojo/edk/util/waitable_event.h" | 26 #include "mojo/edk/util/waitable_event.h" |
27 #include "mojo/public/cpp/system/macros.h" | 27 #include "mojo/public/cpp/system/macros.h" |
28 | 28 |
29 using mojo::embedder::ScopedPlatformHandle; | 29 using mojo::platform::PlatformHandle; |
| 30 using mojo::platform::ScopedPlatformHandle; |
30 using mojo::platform::TaskRunner; | 31 using mojo::platform::TaskRunner; |
31 using mojo::util::AutoResetWaitableEvent; | 32 using mojo::util::AutoResetWaitableEvent; |
32 using mojo::util::MakeUnique; | 33 using mojo::util::MakeUnique; |
33 using mojo::util::MutexLocker; | 34 using mojo::util::MutexLocker; |
34 using mojo::util::RefPtr; | 35 using mojo::util::RefPtr; |
35 | 36 |
36 namespace mojo { | 37 namespace mojo { |
37 namespace system { | 38 namespace system { |
38 | 39 |
39 namespace { | 40 namespace { |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 DCHECK(!pending_platform_handle || !pending_platform_handle->is_valid()); | 287 DCHECK(!pending_platform_handle || !pending_platform_handle->is_valid()); |
287 | 288 |
288 auto it = process_connections_.find(to_process_identifier); | 289 auto it = process_connections_.find(to_process_identifier); |
289 if (it == process_connections_.end()) | 290 if (it == process_connections_.end()) |
290 return ConnectionStatus::NONE; | 291 return ConnectionStatus::NONE; |
291 if (!it->second.is_valid()) | 292 if (!it->second.is_valid()) |
292 return ConnectionStatus::RUNNING; | 293 return ConnectionStatus::RUNNING; |
293 // Pending: | 294 // Pending: |
294 if (pending_platform_handle) { | 295 if (pending_platform_handle) { |
295 pending_platform_handle->reset(it->second); | 296 pending_platform_handle->reset(it->second); |
296 it->second = embedder::PlatformHandle(); | 297 it->second = PlatformHandle(); |
297 } | 298 } |
298 return ConnectionStatus::PENDING; | 299 return ConnectionStatus::PENDING; |
299 } | 300 } |
300 | 301 |
301 void AddConnection(ProcessIdentifier to_process_identifier, | 302 void AddConnection(ProcessIdentifier to_process_identifier, |
302 ConnectionStatus status, | 303 ConnectionStatus status, |
303 ScopedPlatformHandle pending_platform_handle) { | 304 ScopedPlatformHandle pending_platform_handle) { |
304 DCHECK(process_connections_.find(to_process_identifier) == | 305 DCHECK(process_connections_.find(to_process_identifier) == |
305 process_connections_.end()); | 306 process_connections_.end()); |
306 | 307 |
307 if (status == ConnectionStatus::RUNNING) { | 308 if (status == ConnectionStatus::RUNNING) { |
308 DCHECK(!pending_platform_handle.is_valid()); | 309 DCHECK(!pending_platform_handle.is_valid()); |
309 process_connections_[to_process_identifier] = embedder::PlatformHandle(); | 310 process_connections_[to_process_identifier] = PlatformHandle(); |
310 } else if (status == ConnectionStatus::PENDING) { | 311 } else if (status == ConnectionStatus::PENDING) { |
311 DCHECK(pending_platform_handle.is_valid()); | 312 DCHECK(pending_platform_handle.is_valid()); |
312 process_connections_[to_process_identifier] = | 313 process_connections_[to_process_identifier] = |
313 pending_platform_handle.release(); | 314 pending_platform_handle.release(); |
314 } else { | 315 } else { |
315 NOTREACHED(); | 316 NOTREACHED(); |
316 } | 317 } |
317 } | 318 } |
318 | 319 |
319 private: | 320 private: |
320 // TODO(vtl): Make |second| |ScopedPlatformHandle|s. | 321 // TODO(vtl): Make |second| |ScopedPlatformHandle|s. |
321 std::unordered_map<ProcessIdentifier, embedder::PlatformHandle> | 322 std::unordered_map<ProcessIdentifier, PlatformHandle> |
322 process_connections_; // "Owns" any valid platform handles. | 323 process_connections_; // "Owns" any valid platform handles. |
323 | 324 |
324 MOJO_DISALLOW_COPY_AND_ASSIGN(ProcessConnections); | 325 MOJO_DISALLOW_COPY_AND_ASSIGN(ProcessConnections); |
325 }; | 326 }; |
326 | 327 |
327 // MasterConnectionManager ----------------------------------------------------- | 328 // MasterConnectionManager ----------------------------------------------------- |
328 | 329 |
329 MasterConnectionManager::MasterConnectionManager( | 330 MasterConnectionManager::MasterConnectionManager( |
330 embedder::PlatformSupport* platform_support) | 331 embedder::PlatformSupport* platform_support) |
331 : ConnectionManager(platform_support), | 332 : ConnectionManager(platform_support), |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 } | 744 } |
744 | 745 |
745 void MasterConnectionManager::AssertOnPrivateThread() const { | 746 void MasterConnectionManager::AssertOnPrivateThread() const { |
746 // This should only be called after |Init()| and before |Shutdown()|. | 747 // This should only be called after |Init()| and before |Shutdown()|. |
747 DCHECK(private_thread_.message_loop()); | 748 DCHECK(private_thread_.message_loop()); |
748 DCHECK_EQ(base::MessageLoop::current(), private_thread_.message_loop()); | 749 DCHECK_EQ(base::MessageLoop::current(), private_thread_.message_loop()); |
749 } | 750 } |
750 | 751 |
751 } // namespace system | 752 } // namespace system |
752 } // namespace mojo | 753 } // namespace mojo |
OLD | NEW |