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 #ifndef MOJO_EDK_TEST_SCOPED_IPC_SUPPORT_H_ 6 #define MOJO_EDK_TEST_SCOPED_IPC_SUPPORT_H_ 7 8 #include "base/callback.h" 9 #include "base/memory/ref_counted.h" 10 #include "base/run_loop.h" 11 #include "base/task_runner.h" 12 #include "mojo/edk/embedder/process_delegate.h" 13 #include "mojo/edk/embedder/scoped_platform_handle.h" 14 15 namespace mojo { 16 namespace edk { 17 namespace test { 18 19 base::TaskRunner* GetIoTaskRunner(); 20 21 namespace internal { 22 23 class ScopedIPCSupportHelper { 24 public: 25 ScopedIPCSupportHelper(); 26 ~ScopedIPCSupportHelper(); 27 28 void Init(ProcessDelegate* process_delegate, 29 scoped_refptr<base::TaskRunner> io_thread_task_runner); 30 31 void OnShutdownCompleteImpl(); 32 33 private: 34 scoped_refptr<base::TaskRunner> io_thread_task_runner_; 35 36 base::RunLoop run_loop_; 37 38 DISALLOW_COPY_AND_ASSIGN(ScopedIPCSupportHelper); 39 }; 40 41 } // namespace internal 42 43 // A simple class that calls |InitIPCSupport()| on construction and 44 // |ShutdownIPCSupport()| on destruction. 45 class ScopedIPCSupport : public ProcessDelegate { 46 public: 47 explicit ScopedIPCSupport( 48 scoped_refptr<base::TaskRunner> io_thread_task_runner); 49 ~ScopedIPCSupport() override; 50 51 private: 52 // |ProcessDelegate| implementation: 53 // Note: Executed on the I/O thread. 54 void OnShutdownComplete() override; 55 56 internal::ScopedIPCSupportHelper helper_; 57 58 DISALLOW_COPY_AND_ASSIGN(ScopedIPCSupport); 59 }; 60 61 } // namespace test 62 } // namespace edk 63 } // namespace mojo 64 65 #endif // MOJO_EDK_TEST_SCOPED_IPC_SUPPORT_H_ 66