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 ui::ResourceBundle::InitSharedInstanceWithLocale( | |
msw
2016/10/03 22:07:39
nit: add a comment that this loads Chrome's resour
sadrul
2016/10/04 00:42:48
Done.
| |
56 locale, NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES); | |
sky
2016/10/03 22:17:17
nullptr
sadrul
2016/10/04 00:42:48
Done.
| |
57 } | |
58 | |
47 // Convert the command line program from chrome_mash to chrome. This is | 59 // 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. | 60 // necessary as the shell will attempt to start chrome_mash. We want chrome. |
49 void ChangeChromeMashToChrome(base::CommandLine* command_line) { | 61 void ChangeChromeMashToChrome(base::CommandLine* command_line) { |
50 base::FilePath exe_path(command_line->GetProgram()); | 62 base::FilePath exe_path(command_line->GetProgram()); |
51 #if defined(OS_WIN) | 63 #if defined(OS_WIN) |
52 exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("chrome.exe")); | 64 exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("chrome.exe")); |
53 #else | 65 #else |
54 exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("chrome")); | 66 exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("chrome")); |
55 #endif | 67 #endif |
56 command_line->SetProgram(exe_path); | 68 command_line->SetProgram(exe_path); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 service_.reset(new mash::MashPackagedService); | 125 service_.reset(new mash::MashPackagedService); |
114 service_->set_context(base::MakeUnique<shell::ServiceContext>( | 126 service_->set_context(base::MakeUnique<shell::ServiceContext>( |
115 service_.get(), | 127 service_.get(), |
116 background_shell.CreateServiceRequest("exe:chrome_mash"))); | 128 background_shell.CreateServiceRequest("exe:chrome_mash"))); |
117 service_->connector()->Connect("mojo:mash_session"); | 129 service_->connector()->Connect("mojo:mash_session"); |
118 base::RunLoop().Run(); | 130 base::RunLoop().Run(); |
119 } | 131 } |
120 | 132 |
121 void MashRunner::RunChild() { | 133 void MashRunner::RunChild() { |
122 base::i18n::InitializeICU(); | 134 base::i18n::InitializeICU(); |
135 InitializeResources(); | |
123 shell::ChildProcessMainWithCallback( | 136 shell::ChildProcessMainWithCallback( |
124 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); | 137 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); |
125 } | 138 } |
126 | 139 |
127 void MashRunner::StartChildApp( | 140 void MashRunner::StartChildApp( |
128 shell::mojom::ServiceRequest service_request) { | 141 shell::mojom::ServiceRequest service_request) { |
129 // TODO(sad): Normally, this would be a TYPE_DEFAULT message loop. However, | 142 // 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 | 143 // 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 | 144 // going to be mojo:ui at this point. So always create a TYPE_UI message loop |
132 // for now. | 145 // for now. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 tracing::GetConfigForTraceToConsole(); | 177 tracing::GetConfigForTraceToConsole(); |
165 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 178 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
166 trace_config, | 179 trace_config, |
167 base::trace_event::TraceLog::RECORDING_MODE); | 180 base::trace_event::TraceLog::RECORDING_MODE); |
168 } | 181 } |
169 | 182 |
170 MashRunner mash_runner; | 183 MashRunner mash_runner; |
171 mash_runner.Run(); | 184 mash_runner.Run(); |
172 return 0; | 185 return 0; |
173 } | 186 } |
OLD | NEW |