| 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 "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/debugger.h" | 10 #include "base/debug/debugger.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "mash/package/mash_packaged_service.h" | 25 #include "mash/package/mash_packaged_service.h" |
| 26 #include "mojo/public/cpp/bindings/binding_set.h" | 26 #include "mojo/public/cpp/bindings/binding_set.h" |
| 27 #include "services/catalog/public/interfaces/catalog.mojom.h" | 27 #include "services/catalog/public/interfaces/catalog.mojom.h" |
| 28 #include "services/catalog/public/interfaces/constants.mojom.h" | 28 #include "services/catalog/public/interfaces/constants.mojom.h" |
| 29 #include "services/service_manager/background/background_service_manager.h" | 29 #include "services/service_manager/background/background_service_manager.h" |
| 30 #include "services/service_manager/native_runner_delegate.h" | 30 #include "services/service_manager/native_runner_delegate.h" |
| 31 #include "services/service_manager/public/cpp/connector.h" | 31 #include "services/service_manager/public/cpp/connector.h" |
| 32 #include "services/service_manager/public/cpp/identity.h" | 32 #include "services/service_manager/public/cpp/identity.h" |
| 33 #include "services/service_manager/public/cpp/service.h" | 33 #include "services/service_manager/public/cpp/service.h" |
| 34 #include "services/service_manager/public/cpp/service_context.h" | 34 #include "services/service_manager/public/cpp/service_context.h" |
| 35 #include "services/service_manager/public/cpp/standalone_service/standalone_serv
ice.h" | |
| 36 #include "services/service_manager/public/interfaces/service_factory.mojom.h" | 35 #include "services/service_manager/public/interfaces/service_factory.mojom.h" |
| 37 #include "services/service_manager/runner/common/switches.h" | 36 #include "services/service_manager/runner/common/switches.h" |
| 37 #include "services/service_manager/runner/host/child_process.h" |
| 38 #include "services/service_manager/runner/host/child_process_base.h" |
| 38 #include "services/service_manager/runner/init.h" | 39 #include "services/service_manager/runner/init.h" |
| 39 #include "services/service_manager/standalone/context.h" | 40 #include "services/service_manager/standalone/context.h" |
| 40 #include "ui/base/resource/resource_bundle.h" | 41 #include "ui/base/resource/resource_bundle.h" |
| 41 #include "ui/base/ui_base_paths.h" | 42 #include "ui/base/ui_base_paths.h" |
| 42 #include "ui/base/ui_base_switches.h" | 43 #include "ui/base/ui_base_switches.h" |
| 43 | 44 |
| 44 using service_manager::mojom::ServiceFactory; | 45 using service_manager::mojom::ServiceFactory; |
| 45 | 46 |
| 46 namespace { | 47 namespace { |
| 47 | 48 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 class NativeRunnerDelegateImpl : public service_manager::NativeRunnerDelegate { | 86 class NativeRunnerDelegateImpl : public service_manager::NativeRunnerDelegate { |
| 86 public: | 87 public: |
| 87 NativeRunnerDelegateImpl() {} | 88 NativeRunnerDelegateImpl() {} |
| 88 ~NativeRunnerDelegateImpl() override {} | 89 ~NativeRunnerDelegateImpl() override {} |
| 89 | 90 |
| 90 private: | 91 private: |
| 91 // service_manager::NativeRunnerDelegate: | 92 // service_manager::NativeRunnerDelegate: |
| 92 void AdjustCommandLineArgumentsForTarget( | 93 void AdjustCommandLineArgumentsForTarget( |
| 93 const service_manager::Identity& target, | 94 const service_manager::Identity& target, |
| 94 base::CommandLine* command_line) override { | 95 base::CommandLine* command_line) override { |
| 95 if (target.name() == kChromeMashServiceName || | |
| 96 target.name() == content::mojom::kBrowserServiceName) { | |
| 97 command_line->SetProgram( | |
| 98 base::CommandLine::ForCurrentProcess()->GetProgram()); | |
| 99 } | |
| 100 if (target.name() != content::mojom::kBrowserServiceName) { | 96 if (target.name() != content::mojom::kBrowserServiceName) { |
| 101 // If running anything other than the browser process, launch a mash | 97 // If running anything other than the browser process, launch a mash |
| 102 // child process. The new process will execute MashRunner::RunChild(). | 98 // child process. The new process will execute MashRunner::RunChild(). |
| 103 command_line->AppendSwitchASCII(switches::kProcessType, kMashChild); | 99 command_line->AppendSwitchASCII(switches::kProcessType, kMashChild); |
| 104 #if defined(OS_WIN) | 100 #if defined(OS_WIN) |
| 105 command_line->AppendArg(switches::kPrefetchArgumentOther); | 101 command_line->AppendArg(switches::kPrefetchArgumentOther); |
| 106 #endif | 102 #endif |
| 107 return; | 103 return; |
| 108 } | 104 } |
| 109 | 105 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 } | 182 } |
| 187 | 183 |
| 188 int MashRunner::RunChild() { | 184 int MashRunner::RunChild() { |
| 189 // TODO(fdoray): Add TaskScheduler initialization code in | 185 // TODO(fdoray): Add TaskScheduler initialization code in |
| 190 // service_manager::ServiceRunner. TaskScheduler can't be initialized here | 186 // service_manager::ServiceRunner. TaskScheduler can't be initialized here |
| 191 // because it wouldn't be visible to the service's dynamic library. | 187 // because it wouldn't be visible to the service's dynamic library. |
| 192 // https://crbug.com/664996 | 188 // https://crbug.com/664996 |
| 193 | 189 |
| 194 service_manager::WaitForDebuggerIfNecessary(); | 190 service_manager::WaitForDebuggerIfNecessary(); |
| 195 | 191 |
| 192 base::FilePath path = |
| 193 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
| 194 switches::kChildProcess); |
| 195 if (base::PathExists(path)) |
| 196 return service_manager::ChildProcessMain(); |
| 197 |
| 198 // If the path doesn't exist - try launching this as a packaged service. |
| 196 base::i18n::InitializeICU(); | 199 base::i18n::InitializeICU(); |
| 197 InitializeResources(); | 200 InitializeResources(); |
| 198 service_manager::RunStandaloneService( | 201 service_manager::ChildProcessMainWithCallback( |
| 199 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); | 202 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); |
| 200 return 0; | 203 return 0; |
| 201 } | 204 } |
| 202 | 205 |
| 203 void MashRunner::StartChildApp( | 206 void MashRunner::StartChildApp( |
| 204 service_manager::mojom::ServiceRequest service_request) { | 207 service_manager::mojom::ServiceRequest service_request) { |
| 205 // TODO(sad): Normally, this would be a TYPE_DEFAULT message loop. However, | 208 // TODO(sad): Normally, this would be a TYPE_DEFAULT message loop. However, |
| 206 // TYPE_UI is needed for mojo:ui. But it is not known whether the child app is | 209 // TYPE_UI is needed for mojo:ui. But it is not known whether the child app is |
| 207 // going to be mojo:ui at this point. So always create a TYPE_UI message loop | 210 // going to be mojo:ui at this point. So always create a TYPE_UI message loop |
| 208 // for now. | 211 // for now. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 232 base::trace_event::TraceConfig trace_config = | 235 base::trace_event::TraceConfig trace_config = |
| 233 tracing::GetConfigForTraceToConsole(); | 236 tracing::GetConfigForTraceToConsole(); |
| 234 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 237 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
| 235 trace_config, | 238 trace_config, |
| 236 base::trace_event::TraceLog::RECORDING_MODE); | 239 base::trace_event::TraceLog::RECORDING_MODE); |
| 237 } | 240 } |
| 238 | 241 |
| 239 MashRunner mash_runner; | 242 MashRunner mash_runner; |
| 240 return mash_runner.Run(); | 243 return mash_runner.Run(); |
| 241 } | 244 } |
| OLD | NEW |