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

Side by Side Diff: services/shell/service_overrides.cc

Issue 2419723002: Move services/shell to services/service_manager (Closed)
Patch Set: rebase Created 4 years, 2 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
« no previous file with comments | « services/shell/service_overrides.h ('k') | services/shell/standalone/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "services/shell/service_overrides.h"
6
7 #include "base/base_paths.h"
8 #include "base/path_service.h"
9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h"
11
12 namespace shell {
13
14 namespace {
15
16 const char kExecutablePathKey[] = "executable_path";
17 const char kPackageNameKey[] = "package_name";
18
19 } // namespace
20
21 ServiceOverrides::Entry::Entry() {}
22
23 ServiceOverrides::Entry::~Entry() {}
24
25 ServiceOverrides::ServiceOverrides(std::unique_ptr<base::Value> overrides) {
26 const base::DictionaryValue* services;
27 if (!overrides->GetAsDictionary(&services)) {
28 LOG(ERROR) << "Expected top-level dictionary.";
29 return;
30 }
31
32 base::DictionaryValue::Iterator service_iter(*services);
33 for (; !service_iter.IsAtEnd(); service_iter.Advance()) {
34 Entry& new_entry = entries_[service_iter.key()];
35
36 const base::DictionaryValue* value;
37 if (!service_iter.value().GetAsDictionary(&value)) {
38 LOG(ERROR) << "Expected service entry to be a dictionary.";
39 return;
40 }
41
42 std::string executable_path_value;
43 if (value->GetString(kExecutablePathKey, &executable_path_value)) {
44 base::FilePath exe_dir;
45 CHECK(base::PathService::Get(base::DIR_EXE, &exe_dir));
46 #if defined(OS_WIN)
47 executable_path_value += ".exe";
48 base::ReplaceFirstSubstringAfterOffset(
49 &executable_path_value, 0, "$EXE_DIR",
50 base::UTF16ToUTF8(exe_dir.value()));
51 new_entry.executable_path =
52 base::FilePath(base::UTF8ToUTF16(executable_path_value));
53 #else
54 base::ReplaceFirstSubstringAfterOffset(
55 &executable_path_value, 0, "$EXE_DIR",
56 exe_dir.value());
57 new_entry.executable_path = base::FilePath(executable_path_value);
58 #endif
59 }
60
61 value->GetString(kPackageNameKey, &new_entry.package_name);
62 }
63 }
64
65 ServiceOverrides::~ServiceOverrides() {}
66
67 bool ServiceOverrides::GetExecutablePathOverride(
68 const std::string& service_name,
69 base::FilePath* path) const {
70 auto iter = entries_.find(service_name);
71 if (iter == entries_.end() || iter->second.executable_path.empty())
72 return false;
73
74 *path = iter->second.executable_path;
75 return true;
76 }
77
78 } // namespace shell
OLDNEW
« no previous file with comments | « services/shell/service_overrides.h ('k') | services/shell/standalone/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698