• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "mojo/edk/test/scoped_ipc_support.h"
6 
7 #include <utility>
8 
9 #include "base/message_loop/message_loop.h"
10 #include "mojo/edk/embedder/embedder.h"
11 
12 namespace mojo {
13 namespace edk {
14 namespace test {
15 
16 namespace {
17 base::TaskRunner* g_io_task_runner = nullptr;
18 }
19 
GetIoTaskRunner()20 base::TaskRunner* GetIoTaskRunner() {
21   return g_io_task_runner;
22 }
23 
24 namespace internal {
25 
ScopedIPCSupportHelper()26 ScopedIPCSupportHelper::ScopedIPCSupportHelper() {
27 }
28 
~ScopedIPCSupportHelper()29 ScopedIPCSupportHelper::~ScopedIPCSupportHelper() {
30   ShutdownIPCSupport();
31   run_loop_.Run();
32 }
33 
Init(ProcessDelegate * process_delegate,scoped_refptr<base::TaskRunner> io_thread_task_runner)34 void ScopedIPCSupportHelper::Init(
35     ProcessDelegate* process_delegate,
36     scoped_refptr<base::TaskRunner> io_thread_task_runner) {
37   io_thread_task_runner_ = io_thread_task_runner;
38   InitIPCSupport(process_delegate, io_thread_task_runner_);
39 }
40 
OnShutdownCompleteImpl()41 void ScopedIPCSupportHelper::OnShutdownCompleteImpl() {
42   run_loop_.Quit();
43 }
44 
45 }  // namespace internal
46 
ScopedIPCSupport(scoped_refptr<base::TaskRunner> io_thread_task_runner)47 ScopedIPCSupport::ScopedIPCSupport(
48     scoped_refptr<base::TaskRunner> io_thread_task_runner) {
49   g_io_task_runner = io_thread_task_runner.get();
50   helper_.Init(this, std::move(io_thread_task_runner));
51 }
52 
~ScopedIPCSupport()53 ScopedIPCSupport::~ScopedIPCSupport() {
54 }
55 
OnShutdownComplete()56 void ScopedIPCSupport::OnShutdownComplete() {
57   helper_.OnShutdownCompleteImpl();
58 }
59 
60 }  // namespace test
61 }  // namespace edk
62 }  // namespace mojo
63