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 "base/at_exit.h" | 5 #include "base/at_exit.h" |
| 6 #include "base/base_paths.h" |
6 #include "base/command_line.h" | 7 #include "base/command_line.h" |
7 #include "base/debug/stack_trace.h" | 8 #include "base/debug/stack_trace.h" |
8 #include "base/i18n/icu_util.h" | 9 #include "base/i18n/icu_util.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/path_service.h" |
11 #include "base/process/launch.h" | 13 #include "base/process/launch.h" |
12 #include "services/service_manager/public/c/main.h" | 14 #include "services/service_manager/public/c/main.h" |
13 #include "services/service_manager/public/cpp/standalone_service/standalone_serv
ice.h" | 15 #include "services/service_manager/public/cpp/standalone_service/standalone_serv
ice.h" |
14 #include "services/service_manager/public/cpp/standalone_service/switches.h" | 16 #include "services/service_manager/public/cpp/standalone_service/switches.h" |
15 #include "services/service_manager/public/interfaces/service.mojom.h" | 17 #include "services/service_manager/public/interfaces/service.mojom.h" |
16 #include "services/service_manager/runner/init.h" | 18 #include "services/service_manager/runner/init.h" |
17 | 19 |
18 #if defined(OS_MACOSX) | 20 #if defined(OS_MACOSX) |
19 #include "base/mac/bundle_locations.h" | 21 #include "base/mac/bundle_locations.h" |
20 #endif | 22 #endif |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
| 26 // Cross-platform helper to override the necessary hard-coded path location |
| 27 // used to load ICU data. |
| 28 // |
| 29 // TODO(rockot): We should just parameterize InitializeICU so hacks like |
| 30 // this are unnecessary. |
| 31 class ScopedIcuDataDirOverride { |
| 32 public: |
| 33 ScopedIcuDataDirOverride(const base::FilePath& path) { |
| 34 #if defined(OS_WIN) |
| 35 base::PathService::Get(base::DIR_MODULE, &original_path_); |
| 36 #elif defined(OS_MACOSX) |
| 37 original_path_= base::mac::FrameworkBundlePath(); |
| 38 #else |
| 39 base::PathService::Get(base::DIR_EXE, &original_path_); |
| 40 #endif |
| 41 |
| 42 if (!path.empty()) |
| 43 SetPathOverride(path); |
| 44 } |
| 45 |
| 46 ~ScopedIcuDataDirOverride() { SetPathOverride(original_path_); } |
| 47 |
| 48 private: |
| 49 static void SetPathOverride(const base::FilePath& path) { |
| 50 #if defined(OS_WIN) |
| 51 base::PathService::Override(base::DIR_MODULE, path); |
| 52 #elif defined(OS_MACOSX) |
| 53 base::mac::SetOverrideFrameworkBundlePath(path); |
| 54 #else |
| 55 base::PathService::Override(base::DIR_EXE, path); |
| 56 #endif |
| 57 } |
| 58 |
| 59 base::FilePath original_path_; |
| 60 }; |
| 61 |
24 // TODO(rockot): We should consider removing ServiceMain and instead allowing | 62 // TODO(rockot): We should consider removing ServiceMain and instead allowing |
25 // service sources to define a CreateService method which returns a new instance | 63 // service sources to define a CreateService method which returns a new instance |
26 // of service_manager::Service. This would reduce boilerplate in service sources | 64 // of service_manager::Service. This would reduce boilerplate in service sources |
27 // since they all effectively do the same thing via | 65 // since they all effectively do the same thing via |
28 // service_manager::ServiceRunner. | 66 // service_manager::ServiceRunner. |
29 void RunServiceMain(service_manager::mojom::ServiceRequest request) { | 67 void RunServiceMain(service_manager::mojom::ServiceRequest request) { |
30 MojoResult result = ServiceMain(request.PassMessagePipe().release().value()); | 68 MojoResult result = ServiceMain(request.PassMessagePipe().release().value()); |
31 DCHECK_EQ(result, MOJO_RESULT_OK); | 69 DCHECK_EQ(result, MOJO_RESULT_OK); |
32 } | 70 } |
33 | 71 |
34 } // namespace | 72 } // namespace |
35 | 73 |
36 int main(int argc, char** argv) { | 74 int main(int argc, char** argv) { |
37 base::AtExitManager at_exit; | 75 base::AtExitManager at_exit; |
38 base::CommandLine::Init(argc, argv); | 76 base::CommandLine::Init(argc, argv); |
39 | 77 |
40 #if !defined(OFFICIAL_BIULD) && defined(OS_WIN) | 78 #if !defined(OFFICIAL_BIULD) && defined(OS_WIN) |
41 base::RouteStdioToConsole(false); | 79 base::RouteStdioToConsole(false); |
42 #endif | 80 #endif |
43 | 81 |
44 service_manager::InitializeLogging(); | 82 service_manager::InitializeLogging(); |
45 | 83 |
46 base::i18n::InitializeICU(); | 84 { |
| 85 base::FilePath icu_data_dir = base::CommandLine::ForCurrentProcess() |
| 86 ->GetSwitchValuePath(service_manager::switches::kIcuDataDir); |
| 87 ScopedIcuDataDirOverride path_override(icu_data_dir); |
| 88 base::i18n::InitializeICU(); |
| 89 } |
47 | 90 |
48 #if !defined(OFFICIAL_BUILD) | 91 #if !defined(OFFICIAL_BUILD) |
49 // Initialize stack dumping before initializing sandbox to make sure symbol | 92 // Initialize stack dumping before initializing sandbox to make sure symbol |
50 // names in all loaded libraries will be cached. | 93 // names in all loaded libraries will be cached. |
51 base::debug::EnableInProcessStackDumping(); | 94 base::debug::EnableInProcessStackDumping(); |
52 #endif | 95 #endif |
53 | 96 |
54 service_manager::WaitForDebuggerIfNecessary(); | 97 service_manager::WaitForDebuggerIfNecessary(); |
55 | 98 |
56 service_manager::RunStandaloneService(base::Bind(&RunServiceMain)); | 99 service_manager::RunStandaloneService(base::Bind(&RunServiceMain)); |
57 return 0; | 100 return 0; |
58 } | 101 } |
OLD | NEW |