OLD | NEW |
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/core.h" | 5 #include "mojo/edk/system/core.h" |
6 | 6 |
| 7 #include <utility> |
7 #include <vector> | 8 #include <vector> |
8 | 9 |
9 #include "base/containers/stack_container.h" | 10 #include "base/containers/stack_container.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "mojo/edk/embedder/embedder_internal.h" | 14 #include "mojo/edk/embedder/embedder_internal.h" |
14 #include "mojo/edk/embedder/platform_channel_pair.h" | 15 #include "mojo/edk/embedder/platform_channel_pair.h" |
15 #include "mojo/edk/embedder/platform_shared_buffer.h" | 16 #include "mojo/edk/embedder/platform_shared_buffer.h" |
16 #include "mojo/edk/embedder/platform_support.h" | 17 #include "mojo/edk/embedder/platform_support.h" |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_TRANSFERABLE) { | 287 MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_TRANSFERABLE) { |
287 ScopedPlatformHandle server_handle, client_handle; | 288 ScopedPlatformHandle server_handle, client_handle; |
288 #if defined(OS_WIN) | 289 #if defined(OS_WIN) |
289 internal::g_broker->CreatePlatformChannelPair(&server_handle, | 290 internal::g_broker->CreatePlatformChannelPair(&server_handle, |
290 &client_handle); | 291 &client_handle); |
291 #else | 292 #else |
292 PlatformChannelPair channel_pair; | 293 PlatformChannelPair channel_pair; |
293 server_handle = channel_pair.PassServerHandle(); | 294 server_handle = channel_pair.PassServerHandle(); |
294 client_handle = channel_pair.PassClientHandle(); | 295 client_handle = channel_pair.PassClientHandle(); |
295 #endif | 296 #endif |
296 dispatcher0->Init(server_handle.Pass(), nullptr, 0u, nullptr, 0u, nullptr, | 297 dispatcher0->Init(std::move(server_handle), nullptr, 0u, nullptr, 0u, |
297 nullptr); | 298 nullptr, nullptr); |
298 dispatcher1->Init(client_handle.Pass(), nullptr, 0u, nullptr, 0u, nullptr, | 299 dispatcher1->Init(std::move(client_handle), nullptr, 0u, nullptr, 0u, |
299 nullptr); | 300 nullptr, nullptr); |
300 } else { | 301 } else { |
301 uint64_t pipe_id = 0; | 302 uint64_t pipe_id = 0; |
302 // route_id 0 is used internally in RoutedRawChannel. See kInternalRouteId | 303 // route_id 0 is used internally in RoutedRawChannel. See kInternalRouteId |
303 // in routed_raw_channel.cc. | 304 // in routed_raw_channel.cc. |
304 // route_id 1 is used by broker communication. See kBrokerRouteId in | 305 // route_id 1 is used by broker communication. See kBrokerRouteId in |
305 // broker_messages.h. | 306 // broker_messages.h. |
306 while (pipe_id < 2) | 307 while (pipe_id < 2) |
307 pipe_id = base::RandUint64(); | 308 pipe_id = base::RandUint64(); |
308 dispatcher0->InitNonTransferable(pipe_id); | 309 dispatcher0->InitNonTransferable(pipe_id); |
309 dispatcher1->InitNonTransferable(pipe_id); | 310 dispatcher1->InitNonTransferable(pipe_id); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 DCHECK_NE(handle_pair.second, MOJO_HANDLE_INVALID); | 465 DCHECK_NE(handle_pair.second, MOJO_HANDLE_INVALID); |
465 | 466 |
466 ScopedPlatformHandle server_handle, client_handle; | 467 ScopedPlatformHandle server_handle, client_handle; |
467 #if defined(OS_WIN) | 468 #if defined(OS_WIN) |
468 internal::g_broker->CreatePlatformChannelPair(&server_handle, &client_handle); | 469 internal::g_broker->CreatePlatformChannelPair(&server_handle, &client_handle); |
469 #else | 470 #else |
470 PlatformChannelPair channel_pair; | 471 PlatformChannelPair channel_pair; |
471 server_handle = channel_pair.PassServerHandle(); | 472 server_handle = channel_pair.PassServerHandle(); |
472 client_handle = channel_pair.PassClientHandle(); | 473 client_handle = channel_pair.PassClientHandle(); |
473 #endif | 474 #endif |
474 producer_dispatcher->Init(server_handle.Pass(), nullptr, 0u); | 475 producer_dispatcher->Init(std::move(server_handle), nullptr, 0u); |
475 consumer_dispatcher->Init(client_handle.Pass(), nullptr, 0u); | 476 consumer_dispatcher->Init(std::move(client_handle), nullptr, 0u); |
476 | 477 |
477 *data_pipe_producer_handle = handle_pair.first; | 478 *data_pipe_producer_handle = handle_pair.first; |
478 *data_pipe_consumer_handle = handle_pair.second; | 479 *data_pipe_consumer_handle = handle_pair.second; |
479 return MOJO_RESULT_OK; | 480 return MOJO_RESULT_OK; |
480 } | 481 } |
481 | 482 |
482 MojoResult Core::WriteData(MojoHandle data_pipe_producer_handle, | 483 MojoResult Core::WriteData(MojoHandle data_pipe_producer_handle, |
483 const void* elements, | 484 const void* elements, |
484 uint32_t* num_bytes, | 485 uint32_t* num_bytes, |
485 MojoWriteDataFlags flags) { | 486 MojoWriteDataFlags flags) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 | 612 |
612 scoped_ptr<PlatformSharedBufferMapping> mapping; | 613 scoped_ptr<PlatformSharedBufferMapping> mapping; |
613 MojoResult result = dispatcher->MapBuffer(offset, num_bytes, flags, &mapping); | 614 MojoResult result = dispatcher->MapBuffer(offset, num_bytes, flags, &mapping); |
614 if (result != MOJO_RESULT_OK) | 615 if (result != MOJO_RESULT_OK) |
615 return result; | 616 return result; |
616 | 617 |
617 DCHECK(mapping); | 618 DCHECK(mapping); |
618 void* address = mapping->GetBase(); | 619 void* address = mapping->GetBase(); |
619 { | 620 { |
620 base::AutoLock locker(mapping_table_lock_); | 621 base::AutoLock locker(mapping_table_lock_); |
621 result = mapping_table_.AddMapping(mapping.Pass()); | 622 result = mapping_table_.AddMapping(std::move(mapping)); |
622 } | 623 } |
623 if (result != MOJO_RESULT_OK) | 624 if (result != MOJO_RESULT_OK) |
624 return result; | 625 return result; |
625 | 626 |
626 *buffer = address; | 627 *buffer = address; |
627 return MOJO_RESULT_OK; | 628 return MOJO_RESULT_OK; |
628 } | 629 } |
629 | 630 |
630 MojoResult Core::UnmapBuffer(void* buffer) { | 631 MojoResult Core::UnmapBuffer(void* buffer) { |
631 base::AutoLock locker(mapping_table_lock_); | 632 base::AutoLock locker(mapping_table_lock_); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 if (signals_states) { | 697 if (signals_states) { |
697 for (; i < num_handles; i++) | 698 for (; i < num_handles; i++) |
698 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); | 699 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); |
699 } | 700 } |
700 | 701 |
701 return rv; | 702 return rv; |
702 } | 703 } |
703 | 704 |
704 } // namespace edk | 705 } // namespace edk |
705 } // namespace mojo | 706 } // namespace mojo |
OLD | NEW |