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

Side by Side Diff: extensions/utility/utility_handler.cc

Issue 2699663003: Convert utility process extension ParseUpdate IPC to mojo (Closed)
Patch Set: Sync to ToT, see if git apply issue and try jobs are happy. 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/utility/utility_handler.h" 5 #include "extensions/utility/utility_handler.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "content/public/utility/utility_thread.h" 9 #include "content/public/utility/utility_thread.h"
10 #include "extensions/common/constants.h" 10 #include "extensions/common/constants.h"
11 #include "extensions/common/extension_l10n_util.h" 11 #include "extensions/common/extension_l10n_util.h"
12 #include "extensions/common/extension_unpacker.mojom.h" 12 #include "extensions/common/extension_unpacker.mojom.h"
13 #include "extensions/common/extension_utility_messages.h"
14 #include "extensions/common/extensions_client.h" 13 #include "extensions/common/extensions_client.h"
15 #include "extensions/common/manifest.h" 14 #include "extensions/common/manifest.h"
15 #include "extensions/common/manifest_parser.mojom.h"
16 #include "extensions/common/update_manifest.h" 16 #include "extensions/common/update_manifest.h"
17 #include "extensions/strings/grit/extensions_strings.h" 17 #include "extensions/strings/grit/extensions_strings.h"
18 #include "extensions/utility/unpacker.h" 18 #include "extensions/utility/unpacker.h"
19 #include "ipc/ipc_message.h"
20 #include "ipc/ipc_message_macros.h"
21 #include "mojo/public/cpp/bindings/strong_binding.h" 19 #include "mojo/public/cpp/bindings/strong_binding.h"
22 #include "services/service_manager/public/cpp/interface_registry.h" 20 #include "services/service_manager/public/cpp/interface_registry.h"
23 #include "third_party/zlib/google/zip.h" 21 #include "third_party/zlib/google/zip.h"
24 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/ui_base_switches.h" 23 #include "ui/base/ui_base_switches.h"
26 24
27 namespace extensions { 25 namespace extensions {
28 26
29 namespace { 27 namespace {
30 28
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // Add install warnings. 94 // Add install warnings.
97 return zip::UnzipWithFilterCallback( 95 return zip::UnzipWithFilterCallback(
98 file, path, 96 file, path,
99 base::Bind(&Unpacker::ShouldExtractFile, internal.is_theme()), 97 base::Bind(&Unpacker::ShouldExtractFile, internal.is_theme()),
100 true /* log_skipped_files */); 98 true /* log_skipped_files */);
101 } 99 }
102 100
103 DISALLOW_COPY_AND_ASSIGN(ExtensionUnpackerImpl); 101 DISALLOW_COPY_AND_ASSIGN(ExtensionUnpackerImpl);
104 }; 102 };
105 103
104 class ManifestParserImpl : public extensions::mojom::ManifestParser {
105 public:
106 ManifestParserImpl() = default;
107 ~ManifestParserImpl() override = default;
108
109 static void Create(extensions::mojom::ManifestParserRequest request) {
110 mojo::MakeStrongBinding(base::MakeUnique<ManifestParserImpl>(),
111 std::move(request));
112 }
113
114 private:
115 void Parse(const std::string& xml, const ParseCallback& callback) override {
116 UpdateManifest manifest;
117 if (manifest.Parse(xml)) {
118 callback.Run(manifest.results());
119 } else {
120 LOG(WARNING) << "Error parsing update manifest:\n" << manifest.errors();
121 callback.Run(base::nullopt);
122 }
123 }
124
125 DISALLOW_COPY_AND_ASSIGN(ManifestParserImpl);
126 };
127
106 } // namespace 128 } // namespace
107 129
108 UtilityHandler::UtilityHandler() = default;
109
110 UtilityHandler::~UtilityHandler() = default;
111
112 // static 130 // static
113 void UtilityHandler::UtilityThreadStarted() { 131 void UtilityHandler::UtilityThreadStarted() {
114 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 132 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
115 std::string lang = command_line->GetSwitchValueASCII(switches::kLang); 133 std::string lang = command_line->GetSwitchValueASCII(switches::kLang);
116 if (!lang.empty()) 134 if (!lang.empty())
117 extension_l10n_util::SetProcessLocale(lang); 135 extension_l10n_util::SetProcessLocale(lang);
118 } 136 }
119 137
120 // static 138 // static
121 void UtilityHandler::ExposeInterfacesToBrowser( 139 void UtilityHandler::ExposeInterfacesToBrowser(
122 service_manager::InterfaceRegistry* registry, 140 service_manager::InterfaceRegistry* registry,
123 bool running_elevated) { 141 bool running_elevated) {
124 // If our process runs with elevated privileges, only add elevated Mojo 142 // If our process runs with elevated privileges, only add elevated Mojo
125 // services to the interface registry. 143 // services to the interface registry.
126 if (running_elevated) 144 if (running_elevated)
127 return; 145 return;
128 146
129 registry->AddInterface(base::Bind(&ExtensionUnpackerImpl::Create)); 147 registry->AddInterface(base::Bind(&ExtensionUnpackerImpl::Create));
130 } 148 registry->AddInterface(base::Bind(&ManifestParserImpl::Create));
131
132 bool UtilityHandler::OnMessageReceived(const IPC::Message& message) {
133 bool handled = true;
134 IPC_BEGIN_MESSAGE_MAP(UtilityHandler, message)
135 IPC_MESSAGE_HANDLER(ExtensionUtilityMsg_ParseUpdateManifest,
136 OnParseUpdateManifest)
137 IPC_MESSAGE_UNHANDLED(handled = false)
138 IPC_END_MESSAGE_MAP()
139 return handled;
140 }
141
142 void UtilityHandler::OnParseUpdateManifest(const std::string& xml) {
143 UpdateManifest manifest;
144 if (!manifest.Parse(xml)) {
145 content::UtilityThread::Get()->Send(
146 new ExtensionUtilityHostMsg_ParseUpdateManifest_Failed(
147 manifest.errors()));
148 } else {
149 content::UtilityThread::Get()->Send(
150 new ExtensionUtilityHostMsg_ParseUpdateManifest_Succeeded(
151 manifest.results()));
152 }
153 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
154 } 149 }
155 150
156 } // namespace extensions 151 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/utility/utility_handler.h ('k') | mojo/public/tools/bindings/chromium_bindings_configuration.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698