| OLD | NEW |
| (Empty) |
| 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 "ipc/mojo/scoped_ipc_support.h" | |
| 6 | |
| 7 #include "base/lazy_instance.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "mojo/edk/embedder/embedder.h" | |
| 11 #include "mojo/edk/embedder/process_delegate.h" | |
| 12 | |
| 13 namespace IPC { | |
| 14 | |
| 15 namespace { | |
| 16 class IPCSupportInitializer : public mojo::edk::ProcessDelegate { | |
| 17 public: | |
| 18 IPCSupportInitializer() {} | |
| 19 ~IPCSupportInitializer() override {} | |
| 20 | |
| 21 void Init(scoped_refptr<base::TaskRunner> io_thread_task_runner) { | |
| 22 CHECK(!io_thread_task_runner_); | |
| 23 CHECK(io_thread_task_runner); | |
| 24 io_thread_task_runner_ = io_thread_task_runner; | |
| 25 | |
| 26 mojo::edk::InitIPCSupport(this, io_thread_task_runner_); | |
| 27 } | |
| 28 | |
| 29 void ShutDown() { | |
| 30 CHECK(io_thread_task_runner_); | |
| 31 mojo::edk::ShutdownIPCSupport(); | |
| 32 } | |
| 33 | |
| 34 private: | |
| 35 // mojo::edk::ProcessDelegate: | |
| 36 void OnShutdownComplete() override { | |
| 37 // TODO(rockot): We should ensure that IO runner shutdown is blocked until | |
| 38 // this is called. | |
| 39 } | |
| 40 | |
| 41 scoped_refptr<base::TaskRunner> io_thread_task_runner_; | |
| 42 | |
| 43 DISALLOW_COPY_AND_ASSIGN(IPCSupportInitializer); | |
| 44 }; | |
| 45 | |
| 46 base::LazyInstance<IPCSupportInitializer>::Leaky ipc_support_initializer; | |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 50 ScopedIPCSupport::ScopedIPCSupport( | |
| 51 scoped_refptr<base::TaskRunner> io_thread_task_runner) { | |
| 52 ipc_support_initializer.Get().Init(io_thread_task_runner); | |
| 53 } | |
| 54 | |
| 55 ScopedIPCSupport::~ScopedIPCSupport() { | |
| 56 ipc_support_initializer.Get().ShutDown(); | |
| 57 } | |
| 58 | |
| 59 } // namespace IPC | |
| OLD | NEW |