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

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

Issue 2566663004: Revert of Build services as standalone executables (Closed)
Patch Set: Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/at_exit.h"
6 #include "base/base_paths.h"
7 #include "base/command_line.h"
8 #include "base/debug/stack_trace.h"
9 #include "base/i18n/icu_util.h"
10 #include "base/logging.h"
11 #include "base/macros.h"
12 #include "base/path_service.h"
13 #include "base/process/launch.h"
14 #include "services/service_manager/public/c/main.h"
15 #include "services/service_manager/public/cpp/standalone_service/standalone_serv ice.h"
16 #include "services/service_manager/public/cpp/standalone_service/switches.h"
17 #include "services/service_manager/public/interfaces/service.mojom.h"
18 #include "services/service_manager/runner/init.h"
19
20 #if defined(OS_MACOSX)
21 #include "base/mac/bundle_locations.h"
22 #endif
23
24 namespace {
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 DCHECK(base::PathService::Get(base::DIR_MODULE, &original_path_));
36 #elif defined(OS_MACOSX)
37 original_path_= base::mac::FrameworkBundlePath();
38 #else
39 DCHECK(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 DCHECK(base::PathService::Override(base::DIR_MODULE, path));
52 #elif defined(OS_MACOSX)
53 base::mac::SetOverrideFrameworkBundlePath(path);
54 #else
55 DCHECK(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
63 // service sources to define a CreateService method which returns a new instance
64 // of service_manager::Service. This would reduce boilerplate in service sources
65 // since they all effectively do the same thing via
66 // service_manager::ServiceRunner.
67 void RunServiceMain(service_manager::mojom::ServiceRequest request) {
68 MojoResult result = ServiceMain(request.PassMessagePipe().release().value());
69 DCHECK_EQ(result, MOJO_RESULT_OK);
70 }
71
72 } // namespace
73
74 int main(int argc, char** argv) {
75 base::AtExitManager at_exit;
76 base::CommandLine::Init(argc, argv);
77
78 #if !defined(OFFICIAL_BIULD) && defined(OS_WIN)
79 base::RouteStdioToConsole(false);
80 #endif
81
82 service_manager::InitializeLogging();
83
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 }
90
91 service_manager::WaitForDebuggerIfNecessary();
92
93 service_manager::RunStandaloneService(base::Bind(&RunServiceMain));
94 return 0;
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698