| 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 11 matching lines...) Expand all Loading... |
| 22 #include "mojo/public/cpp/bindings/binding_set.h" | 22 #include "mojo/public/cpp/bindings/binding_set.h" |
| 23 #include "services/shell/background/background_shell.h" | 23 #include "services/shell/background/background_shell.h" |
| 24 #include "services/shell/native_runner_delegate.h" | 24 #include "services/shell/native_runner_delegate.h" |
| 25 #include "services/shell/public/cpp/connector.h" | 25 #include "services/shell/public/cpp/connector.h" |
| 26 #include "services/shell/public/cpp/identity.h" | 26 #include "services/shell/public/cpp/identity.h" |
| 27 #include "services/shell/public/cpp/service.h" | 27 #include "services/shell/public/cpp/service.h" |
| 28 #include "services/shell/public/cpp/service_context.h" | 28 #include "services/shell/public/cpp/service_context.h" |
| 29 #include "services/shell/public/interfaces/service_factory.mojom.h" | 29 #include "services/shell/public/interfaces/service_factory.mojom.h" |
| 30 #include "services/shell/runner/common/switches.h" | 30 #include "services/shell/runner/common/switches.h" |
| 31 #include "services/shell/runner/host/child_process_base.h" | 31 #include "services/shell/runner/host/child_process_base.h" |
| 32 #include "ui/base/resource/resource_bundle.h" |
| 33 #include "ui/base/ui_base_paths.h" |
| 34 #include "ui/base/ui_base_switches.h" |
| 32 | 35 |
| 33 using shell::mojom::ServiceFactory; | 36 using shell::mojom::ServiceFactory; |
| 34 | 37 |
| 35 namespace { | 38 namespace { |
| 36 | 39 |
| 37 // kProcessType used to identify child processes. | 40 // kProcessType used to identify child processes. |
| 38 const char* kMashChild = "mash-child"; | 41 const char* kMashChild = "mash-child"; |
| 39 | 42 |
| 40 bool IsChild() { | 43 bool IsChild() { |
| 41 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 44 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 42 switches::kProcessType) && | 45 switches::kProcessType) && |
| 43 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 46 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 44 switches::kProcessType) == kMashChild; | 47 switches::kProcessType) == kMashChild; |
| 45 } | 48 } |
| 46 | 49 |
| 50 void InitializeResources() { |
| 51 ui::RegisterPathProvider(); |
| 52 const std::string locale = |
| 53 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 54 switches::kLang); |
| 55 // This loads the Chrome's resources (chrome_100_percent.pak etc.) |
| 56 ui::ResourceBundle::InitSharedInstanceWithLocale( |
| 57 locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES); |
| 58 } |
| 59 |
| 47 // Convert the command line program from chrome_mash to chrome. This is | 60 // Convert the command line program from chrome_mash to chrome. This is |
| 48 // necessary as the shell will attempt to start chrome_mash. We want chrome. | 61 // necessary as the shell will attempt to start chrome_mash. We want chrome. |
| 49 void ChangeChromeMashToChrome(base::CommandLine* command_line) { | 62 void ChangeChromeMashToChrome(base::CommandLine* command_line) { |
| 50 base::FilePath exe_path(command_line->GetProgram()); | 63 base::FilePath exe_path(command_line->GetProgram()); |
| 51 #if defined(OS_WIN) | 64 #if defined(OS_WIN) |
| 52 exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("chrome.exe")); | 65 exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("chrome.exe")); |
| 53 #else | 66 #else |
| 54 exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("chrome")); | 67 exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("chrome")); |
| 55 #endif | 68 #endif |
| 56 command_line->SetProgram(exe_path); | 69 command_line->SetProgram(exe_path); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 service_.reset(new mash::MashPackagedService); | 126 service_.reset(new mash::MashPackagedService); |
| 114 service_->set_context(base::MakeUnique<shell::ServiceContext>( | 127 service_->set_context(base::MakeUnique<shell::ServiceContext>( |
| 115 service_.get(), | 128 service_.get(), |
| 116 background_shell.CreateServiceRequest("exe:chrome_mash"))); | 129 background_shell.CreateServiceRequest("exe:chrome_mash"))); |
| 117 service_->connector()->Connect("mojo:mash_session"); | 130 service_->connector()->Connect("mojo:mash_session"); |
| 118 base::RunLoop().Run(); | 131 base::RunLoop().Run(); |
| 119 } | 132 } |
| 120 | 133 |
| 121 void MashRunner::RunChild() { | 134 void MashRunner::RunChild() { |
| 122 base::i18n::InitializeICU(); | 135 base::i18n::InitializeICU(); |
| 136 InitializeResources(); |
| 123 shell::ChildProcessMainWithCallback( | 137 shell::ChildProcessMainWithCallback( |
| 124 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); | 138 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); |
| 125 } | 139 } |
| 126 | 140 |
| 127 void MashRunner::StartChildApp( | 141 void MashRunner::StartChildApp( |
| 128 shell::mojom::ServiceRequest service_request) { | 142 shell::mojom::ServiceRequest service_request) { |
| 129 // TODO(sad): Normally, this would be a TYPE_DEFAULT message loop. However, | 143 // TODO(sad): Normally, this would be a TYPE_DEFAULT message loop. However, |
| 130 // TYPE_UI is needed for mojo:ui. But it is not known whether the child app is | 144 // TYPE_UI is needed for mojo:ui. But it is not known whether the child app is |
| 131 // going to be mojo:ui at this point. So always create a TYPE_UI message loop | 145 // going to be mojo:ui at this point. So always create a TYPE_UI message loop |
| 132 // for now. | 146 // for now. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 tracing::GetConfigForTraceToConsole(); | 178 tracing::GetConfigForTraceToConsole(); |
| 165 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 179 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
| 166 trace_config, | 180 trace_config, |
| 167 base::trace_event::TraceLog::RECORDING_MODE); | 181 base::trace_event::TraceLog::RECORDING_MODE); |
| 168 } | 182 } |
| 169 | 183 |
| 170 MashRunner mash_runner; | 184 MashRunner mash_runner; |
| 171 mash_runner.Run(); | 185 mash_runner.Run(); |
| 172 return 0; | 186 return 0; |
| 173 } | 187 } |
| OLD | NEW |