Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: services/service_manager/public/cpp/standalone_service/main.cc

Issue 2645973006: [Service Manager] Get rid of dynamic service discovery (Closed)
Patch Set: . Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
7 #include "base/command_line.h" 6 #include "base/command_line.h"
8 #include "base/debug/stack_trace.h" 7 #include "base/debug/stack_trace.h"
9 #include "base/i18n/icu_util.h" 8 #include "base/i18n/icu_util.h"
10 #include "base/logging.h" 9 #include "base/logging.h"
11 #include "base/macros.h" 10 #include "base/macros.h"
12 #include "base/path_service.h"
13 #include "base/process/launch.h" 11 #include "base/process/launch.h"
14 #include "services/service_manager/public/c/main.h" 12 #include "services/service_manager/public/c/main.h"
15 #include "services/service_manager/public/cpp/standalone_service/standalone_serv ice.h" 13 #include "services/service_manager/public/cpp/standalone_service/standalone_serv ice.h"
16 #include "services/service_manager/public/cpp/standalone_service/switches.h" 14 #include "services/service_manager/public/cpp/standalone_service/switches.h"
17 #include "services/service_manager/public/interfaces/service.mojom.h" 15 #include "services/service_manager/public/interfaces/service.mojom.h"
18 #include "services/service_manager/runner/init.h" 16 #include "services/service_manager/runner/init.h"
19 17
20 #if defined(OS_MACOSX) 18 #if defined(OS_MACOSX)
21 #include "base/mac/bundle_locations.h" 19 #include "base/mac/bundle_locations.h"
22 #endif 20 #endif
23 21
24 namespace { 22 namespace {
25 23
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
62 // TODO(rockot): We should consider removing ServiceMain and instead allowing 24 // TODO(rockot): We should consider removing ServiceMain and instead allowing
63 // service sources to define a CreateService method which returns a new instance 25 // service sources to define a CreateService method which returns a new instance
64 // of service_manager::Service. This would reduce boilerplate in service sources 26 // of service_manager::Service. This would reduce boilerplate in service sources
65 // since they all effectively do the same thing via 27 // since they all effectively do the same thing via
66 // service_manager::ServiceRunner. 28 // service_manager::ServiceRunner.
67 void RunServiceMain(service_manager::mojom::ServiceRequest request) { 29 void RunServiceMain(service_manager::mojom::ServiceRequest request) {
68 MojoResult result = ServiceMain(request.PassMessagePipe().release().value()); 30 MojoResult result = ServiceMain(request.PassMessagePipe().release().value());
69 DCHECK_EQ(result, MOJO_RESULT_OK); 31 DCHECK_EQ(result, MOJO_RESULT_OK);
70 } 32 }
71 33
72 } // namespace 34 } // namespace
73 35
74 int main(int argc, char** argv) { 36 int main(int argc, char** argv) {
75 base::AtExitManager at_exit; 37 base::AtExitManager at_exit;
76 base::CommandLine::Init(argc, argv); 38 base::CommandLine::Init(argc, argv);
77 39
78 #if !defined(OFFICIAL_BIULD) && defined(OS_WIN) 40 #if !defined(OFFICIAL_BIULD) && defined(OS_WIN)
79 base::RouteStdioToConsole(false); 41 base::RouteStdioToConsole(false);
80 #endif 42 #endif
81 43
82 service_manager::InitializeLogging(); 44 service_manager::InitializeLogging();
83 45
84 { 46 base::i18n::InitializeICU();
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 }
90 47
91 #if !defined(OFFICIAL_BUILD) 48 #if !defined(OFFICIAL_BUILD)
92 // Initialize stack dumping before initializing sandbox to make sure symbol 49 // Initialize stack dumping before initializing sandbox to make sure symbol
93 // names in all loaded libraries will be cached. 50 // names in all loaded libraries will be cached.
94 base::debug::EnableInProcessStackDumping(); 51 base::debug::EnableInProcessStackDumping();
95 #endif 52 #endif
96 53
97 service_manager::WaitForDebuggerIfNecessary(); 54 service_manager::WaitForDebuggerIfNecessary();
98 55
99 service_manager::RunStandaloneService(base::Bind(&RunServiceMain)); 56 service_manager::RunStandaloneService(base::Bind(&RunServiceMain));
100 return 0; 57 return 0;
101 } 58 }
OLDNEW
« no previous file with comments | « services/service_manager/public/cpp/service_test.h ('k') | services/service_manager/public/service_manifest.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698