| 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 "ash/mus/sysui_application.h" | 7 #include "ash/mus/sysui_application.h" |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "services/shell/public/cpp/shell_client.h" | 30 #include "services/shell/public/cpp/shell_client.h" |
| 31 #include "services/shell/public/cpp/shell_connection.h" | 31 #include "services/shell/public/cpp/shell_connection.h" |
| 32 #include "services/shell/public/interfaces/shell_client_factory.mojom.h" | 32 #include "services/shell/public/interfaces/shell_client_factory.mojom.h" |
| 33 #include "services/shell/runner/common/switches.h" | 33 #include "services/shell/runner/common/switches.h" |
| 34 #include "services/shell/runner/host/child_process_base.h" | 34 #include "services/shell/runner/host/child_process_base.h" |
| 35 | 35 |
| 36 #if defined(OS_LINUX) | 36 #if defined(OS_LINUX) |
| 37 #include "components/font_service/font_service_app.h" | 37 #include "components/font_service/font_service_app.h" |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 using mojo::shell::mojom::ShellClientFactory; | 40 using shell::mojom::ShellClientFactory; |
| 41 | 41 |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 // kProcessType used to identify child processes. | 44 // kProcessType used to identify child processes. |
| 45 const char* kMashChild = "mash-child"; | 45 const char* kMashChild = "mash-child"; |
| 46 | 46 |
| 47 // ShellClient responsible for starting the appropriate app. | 47 // ShellClient responsible for starting the appropriate app. |
| 48 class DefaultShellClient : public mojo::ShellClient, | 48 class DefaultShellClient : public shell::ShellClient, |
| 49 public ShellClientFactory, | 49 public ShellClientFactory, |
| 50 public mojo::InterfaceFactory<ShellClientFactory> { | 50 public shell::InterfaceFactory<ShellClientFactory> { |
| 51 public: | 51 public: |
| 52 DefaultShellClient() {} | 52 DefaultShellClient() {} |
| 53 ~DefaultShellClient() override {} | 53 ~DefaultShellClient() override {} |
| 54 | 54 |
| 55 // mojo::ShellClient: | 55 // shell::ShellClient: |
| 56 bool AcceptConnection(mojo::Connection* connection) override { | 56 bool AcceptConnection(shell::Connection* connection) override { |
| 57 connection->AddInterface<ShellClientFactory>(this); | 57 connection->AddInterface<ShellClientFactory>(this); |
| 58 return true; | 58 return true; |
| 59 } | 59 } |
| 60 | 60 |
| 61 // mojo::InterfaceFactory<ShellClientFactory> | 61 // shell::InterfaceFactory<ShellClientFactory> |
| 62 void Create(mojo::Connection* connection, | 62 void Create(shell::Connection* connection, |
| 63 mojo::InterfaceRequest<ShellClientFactory> request) override { | 63 mojo::InterfaceRequest<ShellClientFactory> request) override { |
| 64 shell_client_factory_bindings_.AddBinding(this, std::move(request)); | 64 shell_client_factory_bindings_.AddBinding(this, std::move(request)); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // ShellClientFactory: | 67 // ShellClientFactory: |
| 68 void CreateShellClient(mojo::shell::mojom::ShellClientRequest request, | 68 void CreateShellClient(shell::mojom::ShellClientRequest request, |
| 69 const mojo::String& mojo_name) override { | 69 const mojo::String& mojo_name) override { |
| 70 if (shell_client_) { | 70 if (shell_client_) { |
| 71 LOG(ERROR) << "request to create additional app " << mojo_name; | 71 LOG(ERROR) << "request to create additional app " << mojo_name; |
| 72 return; | 72 return; |
| 73 } | 73 } |
| 74 shell_client_ = CreateShellClient(mojo_name); | 74 shell_client_ = CreateShellClient(mojo_name); |
| 75 if (shell_client_) { | 75 if (shell_client_) { |
| 76 shell_connection_.reset( | 76 shell_connection_.reset( |
| 77 new mojo::ShellConnection(shell_client_.get(), std::move(request))); | 77 new shell::ShellConnection(shell_client_.get(), std::move(request))); |
| 78 return; | 78 return; |
| 79 } | 79 } |
| 80 LOG(ERROR) << "unknown name " << mojo_name; | 80 LOG(ERROR) << "unknown name " << mojo_name; |
| 81 NOTREACHED(); | 81 NOTREACHED(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 private: | 84 private: |
| 85 // TODO(sky): move this into mash. | 85 // TODO(sky): move this into mash. |
| 86 scoped_ptr<mojo::ShellClient> CreateShellClient(const std::string& name) { | 86 scoped_ptr<shell::ShellClient> CreateShellClient(const std::string& name) { |
| 87 if (name == "mojo:ash_sysui") | 87 if (name == "mojo:ash_sysui") |
| 88 return base::WrapUnique(new ash::sysui::SysUIApplication); | 88 return base::WrapUnique(new ash::sysui::SysUIApplication); |
| 89 if (name == "mojo:desktop_wm") | 89 if (name == "mojo:desktop_wm") |
| 90 return base::WrapUnique(new mash::wm::WindowManagerApplication); | 90 return base::WrapUnique(new mash::wm::WindowManagerApplication); |
| 91 if (name == "mojo:mash_session") | 91 if (name == "mojo:mash_session") |
| 92 return base::WrapUnique(new mash::session::Session); | 92 return base::WrapUnique(new mash::session::Session); |
| 93 if (name == "mojo:mus") | 93 if (name == "mojo:mus") |
| 94 return base::WrapUnique(new mus::MandolineUIServicesApp); | 94 return base::WrapUnique(new mus::MandolineUIServicesApp); |
| 95 if (name == "mojo:quick_launch") | 95 if (name == "mojo:quick_launch") |
| 96 return base::WrapUnique(new mash::quick_launch::QuickLaunchApplication); | 96 return base::WrapUnique(new mash::quick_launch::QuickLaunchApplication); |
| 97 if (name == "mojo:resource_provider") { | 97 if (name == "mojo:resource_provider") { |
| 98 return base::WrapUnique( | 98 return base::WrapUnique( |
| 99 new resource_provider::ResourceProviderApp("mojo:resource_provider")); | 99 new resource_provider::ResourceProviderApp("mojo:resource_provider")); |
| 100 } | 100 } |
| 101 if (name == "mojo:task_viewer") | 101 if (name == "mojo:task_viewer") |
| 102 return base::WrapUnique(new mash::task_viewer::TaskViewer); | 102 return base::WrapUnique(new mash::task_viewer::TaskViewer); |
| 103 #if defined(OS_LINUX) | 103 #if defined(OS_LINUX) |
| 104 if (name == "mojo:font_service") | 104 if (name == "mojo:font_service") |
| 105 return base::WrapUnique(new font_service::FontServiceApp); | 105 return base::WrapUnique(new font_service::FontServiceApp); |
| 106 #endif | 106 #endif |
| 107 if (name == "mojo:browser_driver") { | 107 if (name == "mojo:browser_driver") { |
| 108 return base::WrapUnique( | 108 return base::WrapUnique( |
| 109 new mash::browser_driver::BrowserDriverApplicationDelegate()); | 109 new mash::browser_driver::BrowserDriverApplicationDelegate()); |
| 110 } | 110 } |
| 111 return nullptr; | 111 return nullptr; |
| 112 } | 112 } |
| 113 | 113 |
| 114 mojo::BindingSet<ShellClientFactory> shell_client_factory_bindings_; | 114 mojo::BindingSet<ShellClientFactory> shell_client_factory_bindings_; |
| 115 scoped_ptr<mojo::ShellClient> shell_client_; | 115 scoped_ptr<shell::ShellClient> shell_client_; |
| 116 scoped_ptr<mojo::ShellConnection> shell_connection_; | 116 scoped_ptr<shell::ShellConnection> shell_connection_; |
| 117 | 117 |
| 118 DISALLOW_COPY_AND_ASSIGN(DefaultShellClient); | 118 DISALLOW_COPY_AND_ASSIGN(DefaultShellClient); |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 bool IsChild() { | 121 bool IsChild() { |
| 122 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 122 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 123 switches::kProcessType) && | 123 switches::kProcessType) && |
| 124 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 124 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 125 switches::kProcessType) == kMashChild; | 125 switches::kProcessType) == kMashChild; |
| 126 } | 126 } |
| 127 | 127 |
| 128 // Convert the command line program from chrome_mash to chrome. This is | 128 // Convert the command line program from chrome_mash to chrome. This is |
| 129 // necessary as the shell will attempt to start chrome_mash. We want chrome. | 129 // necessary as the shell will attempt to start chrome_mash. We want chrome. |
| 130 void ChangeChromeMashToChrome(base::CommandLine* command_line) { | 130 void ChangeChromeMashToChrome(base::CommandLine* command_line) { |
| 131 base::FilePath exe_path(command_line->GetProgram()); | 131 base::FilePath exe_path(command_line->GetProgram()); |
| 132 #if defined(OS_WIN) | 132 #if defined(OS_WIN) |
| 133 exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("chrome.exe")); | 133 exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("chrome.exe")); |
| 134 #else | 134 #else |
| 135 exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("chrome")); | 135 exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("chrome")); |
| 136 #endif | 136 #endif |
| 137 command_line->SetProgram(exe_path); | 137 command_line->SetProgram(exe_path); |
| 138 } | 138 } |
| 139 | 139 |
| 140 class NativeRunnerDelegateImpl : public mojo::shell::NativeRunnerDelegate { | 140 class NativeRunnerDelegateImpl : public shell::NativeRunnerDelegate { |
| 141 public: | 141 public: |
| 142 NativeRunnerDelegateImpl() {} | 142 NativeRunnerDelegateImpl() {} |
| 143 ~NativeRunnerDelegateImpl() override {} | 143 ~NativeRunnerDelegateImpl() override {} |
| 144 | 144 |
| 145 private: | 145 private: |
| 146 // mojo::shell::NativeRunnerDelegate: | 146 // shell::NativeRunnerDelegate: |
| 147 void AdjustCommandLineArgumentsForTarget( | 147 void AdjustCommandLineArgumentsForTarget( |
| 148 const mojo::Identity& target, | 148 const shell::Identity& target, |
| 149 base::CommandLine* command_line) override { | 149 base::CommandLine* command_line) override { |
| 150 command_line->AppendSwitch(switches::kWaitForMojoShell); | 150 command_line->AppendSwitch(switches::kWaitForMojoShell); |
| 151 if (target.name() != "exe:chrome") { | 151 if (target.name() != "exe:chrome") { |
| 152 if (target.name() == "exe:chrome_mash") | 152 if (target.name() == "exe:chrome_mash") |
| 153 ChangeChromeMashToChrome(command_line); | 153 ChangeChromeMashToChrome(command_line); |
| 154 command_line->AppendSwitchASCII(switches::kProcessType, kMashChild); | 154 command_line->AppendSwitchASCII(switches::kProcessType, kMashChild); |
| 155 #if defined(OS_WIN) | 155 #if defined(OS_WIN) |
| 156 command_line->AppendArg(switches::kPrefetchArgumentOther); | 156 command_line->AppendArg(switches::kPrefetchArgumentOther); |
| 157 #endif | 157 #endif |
| 158 return; | 158 return; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 180 RunChild(); | 180 RunChild(); |
| 181 else | 181 else |
| 182 RunMain(); | 182 RunMain(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 void MashRunner::RunMain() { | 185 void MashRunner::RunMain() { |
| 186 // TODO(sky): refactor backgroundshell so can supply own context, we | 186 // TODO(sky): refactor backgroundshell so can supply own context, we |
| 187 // shouldn't we using context as it has a lot of stuff we don't really want | 187 // shouldn't we using context as it has a lot of stuff we don't really want |
| 188 // in chrome. | 188 // in chrome. |
| 189 NativeRunnerDelegateImpl native_runner_delegate; | 189 NativeRunnerDelegateImpl native_runner_delegate; |
| 190 mojo::shell::BackgroundShell background_shell; | 190 shell::BackgroundShell background_shell; |
| 191 scoped_ptr<mojo::shell::BackgroundShell::InitParams> init_params( | 191 scoped_ptr<shell::BackgroundShell::InitParams> init_params( |
| 192 new mojo::shell::BackgroundShell::InitParams); | 192 new shell::BackgroundShell::InitParams); |
| 193 init_params->native_runner_delegate = &native_runner_delegate; | 193 init_params->native_runner_delegate = &native_runner_delegate; |
| 194 background_shell.Init(std::move(init_params)); | 194 background_shell.Init(std::move(init_params)); |
| 195 shell_client_.reset(new DefaultShellClient); | 195 shell_client_.reset(new DefaultShellClient); |
| 196 shell_connection_.reset(new mojo::ShellConnection( | 196 shell_connection_.reset(new shell::ShellConnection( |
| 197 shell_client_.get(), | 197 shell_client_.get(), |
| 198 background_shell.CreateShellClientRequest("exe:chrome_mash"))); | 198 background_shell.CreateShellClientRequest("exe:chrome_mash"))); |
| 199 shell_connection_->connector()->Connect("mojo:mash_session"); | 199 shell_connection_->connector()->Connect("mojo:mash_session"); |
| 200 base::MessageLoop::current()->Run(); | 200 base::MessageLoop::current()->Run(); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void MashRunner::RunChild() { | 203 void MashRunner::RunChild() { |
| 204 base::i18n::InitializeICU(); | 204 base::i18n::InitializeICU(); |
| 205 mojo::shell::ChildProcessMain( | 205 shell::ChildProcessMain( |
| 206 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); | 206 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); |
| 207 } | 207 } |
| 208 | 208 |
| 209 void MashRunner::StartChildApp( | 209 void MashRunner::StartChildApp( |
| 210 mojo::shell::mojom::ShellClientRequest client_request) { | 210 shell::mojom::ShellClientRequest client_request) { |
| 211 // TODO(sky): use MessagePumpMojo. | 211 // TODO(sky): use MessagePumpMojo. |
| 212 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); | 212 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); |
| 213 shell_client_.reset(new DefaultShellClient); | 213 shell_client_.reset(new DefaultShellClient); |
| 214 shell_connection_.reset(new mojo::ShellConnection(shell_client_.get(), | 214 shell_connection_.reset(new shell::ShellConnection( |
| 215 std::move(client_request))); | 215 shell_client_.get(), std::move(client_request))); |
| 216 message_loop.Run(); | 216 message_loop.Run(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 int MashMain() { | 219 int MashMain() { |
| 220 #if defined(OS_WIN) | 220 #if defined(OS_WIN) |
| 221 base::RouteStdioToConsole(false); | 221 base::RouteStdioToConsole(false); |
| 222 #endif | 222 #endif |
| 223 // TODO(sky): wire this up correctly. | 223 // TODO(sky): wire this up correctly. |
| 224 logging::LoggingSettings settings; | 224 logging::LoggingSettings settings; |
| 225 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 225 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 226 logging::InitLogging(settings); | 226 logging::InitLogging(settings); |
| 227 // To view log output with IDs and timestamps use "adb logcat -v threadtime". | 227 // To view log output with IDs and timestamps use "adb logcat -v threadtime". |
| 228 logging::SetLogItems(true, // Process ID | 228 logging::SetLogItems(true, // Process ID |
| 229 true, // Thread ID | 229 true, // Thread ID |
| 230 true, // Timestamp | 230 true, // Timestamp |
| 231 true); // Tick count | 231 true); // Tick count |
| 232 | 232 |
| 233 // TODO(sky): use MessagePumpMojo. | 233 // TODO(sky): use MessagePumpMojo. |
| 234 scoped_ptr<base::MessageLoop> message_loop; | 234 scoped_ptr<base::MessageLoop> message_loop; |
| 235 #if defined(OS_LINUX) | 235 #if defined(OS_LINUX) |
| 236 base::AtExitManager exit_manager; | 236 base::AtExitManager exit_manager; |
| 237 #endif | 237 #endif |
| 238 if (!IsChild()) | 238 if (!IsChild()) |
| 239 message_loop.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI)); | 239 message_loop.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI)); |
| 240 MashRunner mash_runner; | 240 MashRunner mash_runner; |
| 241 mash_runner.Run(); | 241 mash_runner.Run(); |
| 242 return 0; | 242 return 0; |
| 243 } | 243 } |
| OLD | NEW |