| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/app/mash/mash_runner.h" | 5 #include "chrome/app/mash/mash_runner.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| 11 #include "base/base_switches.h" | 11 #include "base/base_switches.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/debug/debugger.h" | 14 #include "base/debug/debugger.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
| 17 #include "base/i18n/icu_util.h" | 17 #include "base/i18n/icu_util.h" |
| 18 #include "base/json/json_reader.h" | |
| 19 #include "base/logging.h" | 18 #include "base/logging.h" |
| 20 #include "base/memory/ptr_util.h" | 19 #include "base/memory/ptr_util.h" |
| 21 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
| 22 #include "base/path_service.h" | 21 #include "base/path_service.h" |
| 23 #include "base/process/launch.h" | 22 #include "base/process/launch.h" |
| 24 #include "base/process/process.h" | 23 #include "base/process/process.h" |
| 25 #include "base/run_loop.h" | 24 #include "base/run_loop.h" |
| 26 #include "base/sys_info.h" | 25 #include "base/sys_info.h" |
| 27 #include "base/task_scheduler/task_scheduler.h" | 26 #include "base/task_scheduler/task_scheduler.h" |
| 28 #include "base/threading/sequenced_worker_pool.h" | 27 #include "base/threading/sequenced_worker_pool.h" |
| 29 #include "base/threading/thread.h" | 28 #include "base/threading/thread.h" |
| 30 #include "base/trace_event/trace_event.h" | 29 #include "base/trace_event/trace_event.h" |
| 30 #include "chrome/app/mash/chrome_mash_catalog.h" |
| 31 #include "components/tracing/common/trace_to_console.h" | 31 #include "components/tracing/common/trace_to_console.h" |
| 32 #include "components/tracing/common/tracing_switches.h" | 32 #include "components/tracing/common/tracing_switches.h" |
| 33 #include "content/public/common/content_switches.h" | 33 #include "content/public/common/content_switches.h" |
| 34 #include "content/public/common/service_names.mojom.h" | 34 #include "content/public/common/service_names.mojom.h" |
| 35 #include "mash/package/mash_packaged_service.h" | 35 #include "mash/package/mash_packaged_service.h" |
| 36 #include "mash/session/public/interfaces/constants.mojom.h" | 36 #include "mash/session/public/interfaces/constants.mojom.h" |
| 37 #include "mojo/edk/embedder/embedder.h" | 37 #include "mojo/edk/embedder/embedder.h" |
| 38 #include "mojo/edk/embedder/scoped_ipc_support.h" | 38 #include "mojo/edk/embedder/scoped_ipc_support.h" |
| 39 #include "mojo/public/cpp/bindings/binding_set.h" | 39 #include "mojo/public/cpp/bindings/binding_set.h" |
| 40 #include "services/catalog/public/interfaces/catalog.mojom.h" | 40 #include "services/catalog/public/interfaces/catalog.mojom.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 54 #include "ui/base/ui_base_switches.h" | 54 #include "ui/base/ui_base_switches.h" |
| 55 | 55 |
| 56 #if defined(OS_CHROMEOS) | 56 #if defined(OS_CHROMEOS) |
| 57 #include "base/debug/leak_annotations.h" | 57 #include "base/debug/leak_annotations.h" |
| 58 #include "chrome/app/mash/mash_crash_reporter_client.h" | 58 #include "chrome/app/mash/mash_crash_reporter_client.h" |
| 59 #include "components/crash/content/app/breakpad_linux.h" // nogncheck | 59 #include "components/crash/content/app/breakpad_linux.h" // nogncheck |
| 60 #endif | 60 #endif |
| 61 | 61 |
| 62 using service_manager::mojom::ServiceFactory; | 62 using service_manager::mojom::ServiceFactory; |
| 63 | 63 |
| 64 // Defined externally by the ":catalog_cpp_source" target. | |
| 65 extern const char kChromeMashCatalogContents[]; | |
| 66 | |
| 67 namespace { | 64 namespace { |
| 68 | 65 |
| 69 // kProcessType used to identify child processes. | 66 // kProcessType used to identify child processes. |
| 70 const char* kMashChild = "mash-child"; | 67 const char* kMashChild = "mash-child"; |
| 71 | 68 |
| 72 const char kChromeMashServiceName[] = "chrome_mash"; | 69 const char kChromeMashServiceName[] = "chrome_mash"; |
| 73 | 70 |
| 74 bool IsChild() { | 71 bool IsChild() { |
| 75 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 72 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 76 switches::kProcessType) && | 73 switches::kProcessType) && |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 167 |
| 171 mojo::edk::Init(); | 168 mojo::edk::Init(); |
| 172 | 169 |
| 173 base::Thread ipc_thread("IPC thread"); | 170 base::Thread ipc_thread("IPC thread"); |
| 174 ipc_thread.StartWithOptions( | 171 ipc_thread.StartWithOptions( |
| 175 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 172 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
| 176 mojo::edk::ScopedIPCSupport ipc_support( | 173 mojo::edk::ScopedIPCSupport ipc_support( |
| 177 ipc_thread.task_runner(), | 174 ipc_thread.task_runner(), |
| 178 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST); | 175 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST); |
| 179 | 176 |
| 180 std::unique_ptr<base::Value> manifest_value = | |
| 181 base::JSONReader::Read(kChromeMashCatalogContents); | |
| 182 DCHECK(manifest_value); | |
| 183 | |
| 184 // TODO(sky): refactor BackgroundServiceManager so can supply own context, we | 177 // TODO(sky): refactor BackgroundServiceManager so can supply own context, we |
| 185 // shouldn't we using context as it has a lot of stuff we don't really want | 178 // shouldn't we using context as it has a lot of stuff we don't really want |
| 186 // in chrome. | 179 // in chrome. |
| 187 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate; | 180 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate; |
| 188 service_manager::BackgroundServiceManager background_service_manager( | 181 service_manager::BackgroundServiceManager background_service_manager( |
| 189 &service_process_launcher_delegate, std::move(manifest_value)); | 182 &service_process_launcher_delegate, CreateChromeMashCatalog()); |
| 190 service_manager::mojom::ServicePtr service; | 183 service_manager::mojom::ServicePtr service; |
| 191 context_.reset(new service_manager::ServiceContext( | 184 context_.reset(new service_manager::ServiceContext( |
| 192 base::MakeUnique<mash::MashPackagedService>(), | 185 base::MakeUnique<mash::MashPackagedService>(), |
| 193 service_manager::mojom::ServiceRequest(&service))); | 186 service_manager::mojom::ServiceRequest(&service))); |
| 194 background_service_manager.RegisterService( | 187 background_service_manager.RegisterService( |
| 195 service_manager::Identity( | 188 service_manager::Identity( |
| 196 kChromeMashServiceName, service_manager::mojom::kRootUserID), | 189 kChromeMashServiceName, service_manager::mojom::kRootUserID), |
| 197 std::move(service), nullptr); | 190 std::move(service), nullptr); |
| 198 | 191 |
| 199 // Ping mash_session to ensure an instance is brought up | 192 // Ping mash_session to ensure an instance is brought up |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 command_line->GetSwitchValueASCII(switches::kWaitForDebugger)) { | 271 command_line->GetSwitchValueASCII(switches::kWaitForDebugger)) { |
| 279 return; | 272 return; |
| 280 } | 273 } |
| 281 | 274 |
| 282 // Include the pid as logging may not have been initialized yet (the pid | 275 // Include the pid as logging may not have been initialized yet (the pid |
| 283 // printed out by logging is wrong). | 276 // printed out by logging is wrong). |
| 284 LOG(WARNING) << "waiting for debugger to attach for service " << service_name | 277 LOG(WARNING) << "waiting for debugger to attach for service " << service_name |
| 285 << " pid=" << base::Process::Current().Pid(); | 278 << " pid=" << base::Process::Current().Pid(); |
| 286 base::debug::WaitForDebugger(120, true); | 279 base::debug::WaitForDebugger(120, true); |
| 287 } | 280 } |
| OLD | NEW |