| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "services/service_manager/runner/host/service_process_launcher.h" | 5 #include "services/service_manager/runner/host/service_process_launcher.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 19 #include "mojo/edk/embedder/embedder.h" | 19 #include "mojo/edk/embedder/embedder.h" |
| 20 #include "mojo/edk/embedder/process_delegate.h" | 20 #include "mojo/edk/embedder/scoped_ipc_support.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| 23 namespace service_manager { | 23 namespace service_manager { |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const char kTestServiceName[] = "host_test_service"; | 26 const char kTestServiceName[] = "host_test_service"; |
| 27 | 27 |
| 28 const base::FilePath::CharType kPackagesPath[] = FILE_PATH_LITERAL("Packages"); | 28 const base::FilePath::CharType kPackagesPath[] = FILE_PATH_LITERAL("Packages"); |
| 29 | 29 |
| 30 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
| 31 const base::FilePath::CharType kServiceExtension[] = | 31 const base::FilePath::CharType kServiceExtension[] = |
| 32 FILE_PATH_LITERAL(".service.exe"); | 32 FILE_PATH_LITERAL(".service.exe"); |
| 33 #else | 33 #else |
| 34 const base::FilePath::CharType kServiceExtension[] = | 34 const base::FilePath::CharType kServiceExtension[] = |
| 35 FILE_PATH_LITERAL(".service"); | 35 FILE_PATH_LITERAL(".service"); |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 void ProcessReadyCallbackAdapater(const base::Closure& callback, | 38 void ProcessReadyCallbackAdapater(const base::Closure& callback, |
| 39 base::ProcessId process_id) { | 39 base::ProcessId process_id) { |
| 40 callback.Run(); | 40 callback.Run(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 class ProcessDelegate : public mojo::edk::ProcessDelegate { | |
| 44 public: | |
| 45 ProcessDelegate() {} | |
| 46 ~ProcessDelegate() override {} | |
| 47 | |
| 48 private: | |
| 49 void OnShutdownComplete() override {} | |
| 50 DISALLOW_COPY_AND_ASSIGN(ProcessDelegate); | |
| 51 }; | |
| 52 | |
| 53 class ServiceProcessLauncherDelegateImpl | 43 class ServiceProcessLauncherDelegateImpl |
| 54 : public ServiceProcessLauncher::Delegate { | 44 : public ServiceProcessLauncher::Delegate { |
| 55 public: | 45 public: |
| 56 ServiceProcessLauncherDelegateImpl() {} | 46 ServiceProcessLauncherDelegateImpl() {} |
| 57 ~ServiceProcessLauncherDelegateImpl() override {} | 47 ~ServiceProcessLauncherDelegateImpl() override {} |
| 58 | 48 |
| 59 size_t get_and_clear_adjust_count() { | 49 size_t get_and_clear_adjust_count() { |
| 60 size_t count = 0; | 50 size_t count = 0; |
| 61 std::swap(count, adjust_count_); | 51 std::swap(count, adjust_count_); |
| 62 return count; | 52 return count; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 87 base::MessageLoop message_loop; | 77 base::MessageLoop message_loop; |
| 88 scoped_refptr<base::SequencedWorkerPool> blocking_pool( | 78 scoped_refptr<base::SequencedWorkerPool> blocking_pool( |
| 89 new base::SequencedWorkerPool(3, "blocking_pool", | 79 new base::SequencedWorkerPool(3, "blocking_pool", |
| 90 base::TaskPriority::USER_VISIBLE)); | 80 base::TaskPriority::USER_VISIBLE)); |
| 91 | 81 |
| 92 base::Thread io_thread("io_thread"); | 82 base::Thread io_thread("io_thread"); |
| 93 base::Thread::Options options; | 83 base::Thread::Options options; |
| 94 options.message_loop_type = base::MessageLoop::TYPE_IO; | 84 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 95 io_thread.StartWithOptions(options); | 85 io_thread.StartWithOptions(options); |
| 96 | 86 |
| 97 ProcessDelegate delegate; | 87 auto ipc_support = base::MakeUnique<mojo::edk::ScopedIPCSupport>( |
| 98 mojo::edk::InitIPCSupport(&delegate, io_thread.task_runner()); | 88 io_thread.task_runner(), |
| 89 mojo::edk::ScopedIPCSupport::ShutdownPolicy::CLEAN); |
| 99 | 90 |
| 100 base::FilePath test_service_path = | 91 base::FilePath test_service_path = |
| 101 base::FilePath(kPackagesPath).AppendASCII(kTestServiceName) | 92 base::FilePath(kPackagesPath).AppendASCII(kTestServiceName) |
| 102 .AppendASCII(kTestServiceName) .AddExtension(kServiceExtension); | 93 .AppendASCII(kTestServiceName) .AddExtension(kServiceExtension); |
| 103 | 94 |
| 104 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate; | 95 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate; |
| 105 ServiceProcessLauncher launcher(blocking_pool.get(), | 96 ServiceProcessLauncher launcher(blocking_pool.get(), |
| 106 &service_process_launcher_delegate, | 97 &service_process_launcher_delegate, |
| 107 test_service_path); | 98 test_service_path); |
| 108 base::RunLoop run_loop; | 99 base::RunLoop run_loop; |
| 109 launcher.Start( | 100 launcher.Start( |
| 110 Identity(), | 101 Identity(), |
| 111 false, | 102 false, |
| 112 base::Bind(&ProcessReadyCallbackAdapater, run_loop.QuitClosure())); | 103 base::Bind(&ProcessReadyCallbackAdapater, run_loop.QuitClosure())); |
| 113 run_loop.Run(); | 104 run_loop.Run(); |
| 114 | 105 |
| 115 launcher.Join(); | 106 launcher.Join(); |
| 116 blocking_pool->Shutdown(); | 107 blocking_pool->Shutdown(); |
| 117 mojo::edk::ShutdownIPCSupport(); | 108 ipc_support.reset(); |
| 109 |
| 118 EXPECT_EQ(1u, service_process_launcher_delegate.get_and_clear_adjust_count()); | 110 EXPECT_EQ(1u, service_process_launcher_delegate.get_and_clear_adjust_count()); |
| 119 } | 111 } |
| 120 | 112 |
| 121 } // namespace | 113 } // namespace |
| 122 } // namespace service_manager | 114 } // namespace service_manager |
| OLD | NEW |