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

Side by Side Diff: chrome/utility/chrome_content_utility_client.cc

Issue 2566053002: Convert utility process out-of-process file patching to mojo (Closed)
Patch Set: Fix linux_chromium_chromeos_ozone_rel_ng apply patch failure. Created 3 years, 12 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
« chrome/common/file_patcher.mojom ('K') | « chrome/test/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/utility/chrome_content_utility_client.h" 5 #include "chrome/utility/chrome_content_utility_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "chrome/common/chrome_utility_messages.h" 15 #include "chrome/common/chrome_utility_messages.h"
16 #include "chrome/common/file_patcher.mojom.h"
16 #include "chrome/common/safe_browsing/zip_analyzer.h" 17 #include "chrome/common/safe_browsing/zip_analyzer.h"
17 #include "chrome/common/safe_browsing/zip_analyzer_results.h" 18 #include "chrome/common/safe_browsing/zip_analyzer_results.h"
18 #include "chrome/utility/chrome_content_utility_ipc_whitelist.h" 19 #include "chrome/utility/chrome_content_utility_ipc_whitelist.h"
19 #include "chrome/utility/utility_message_handler.h" 20 #include "chrome/utility/utility_message_handler.h"
20 #include "components/safe_json/utility/safe_json_parser_mojo_impl.h" 21 #include "components/safe_json/utility/safe_json_parser_mojo_impl.h"
21 #include "content/public/child/image_decoder_utils.h" 22 #include "content/public/child/image_decoder_utils.h"
22 #include "content/public/common/content_switches.h" 23 #include "content/public/common/content_switches.h"
23 #include "content/public/common/service_info.h" 24 #include "content/public/common/service_info.h"
24 #include "content/public/utility/utility_thread.h" 25 #include "content/public/utility/utility_thread.h"
25 #include "courgette/courgette.h" 26 #include "courgette/courgette.h"
(...skipping 30 matching lines...) Expand all
56 (BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN)) 57 (BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN))
57 #include "chrome/utility/printing_handler.h" 58 #include "chrome/utility/printing_handler.h"
58 #endif 59 #endif
59 60
60 #if defined(OS_MACOSX) && defined(FULL_SAFE_BROWSING) 61 #if defined(OS_MACOSX) && defined(FULL_SAFE_BROWSING)
61 #include "chrome/utility/safe_browsing/mac/dmg_analyzer.h" 62 #include "chrome/utility/safe_browsing/mac/dmg_analyzer.h"
62 #endif 63 #endif
63 64
64 namespace { 65 namespace {
65 66
66 bool Send(IPC::Message* message) { 67 class FilePatcherImpl : public chrome::mojom::FilePatcher {
67 return content::UtilityThread::Get()->Send(message); 68 public:
68 } 69 FilePatcherImpl() {}
Sam McNally 2016/12/22 02:45:49 = default;
Noel Gordon 2016/12/22 05:06:34 Done.
70 ~FilePatcherImpl() override {}
Sam McNally 2016/12/22 02:45:49 = default;
Noel Gordon 2016/12/22 05:06:34 Done.
69 71
70 void ReleaseProcessIfNeeded() { 72 static void Create(chrome::mojom::FilePatcherRequest request) {
71 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); 73 mojo::MakeStrongBinding(base::MakeUnique<FilePatcherImpl>(),
72 } 74 std::move(request));
75 }
76
77 private:
78 void PatchFileBsdiff(base::File input_file,
tibell 2016/12/22 02:59:38 We usually add line // chrome::mojom::FilePatcher
79 base::File patch_file,
80 base::File output_file,
81 const PatchFileBsdiffCallback& callback) override {
82 const int patch_result_status = bsdiff::ApplyBinaryPatch(
83 std::move(input_file), std::move(patch_file), std::move(output_file));
84 callback.Run(patch_result_status);
85 }
86
87 void PatchFileCourgette(base::File input_file,
88 base::File patch_file,
89 base::File output_file,
90 const PatchFileCourgetteCallback& callback) override {
91 const int patch_result_status = courgette::ApplyEnsemblePatch(
92 std::move(input_file), std::move(patch_file), std::move(output_file));
93 callback.Run(patch_result_status);
94 }
95
96 DISALLOW_COPY_AND_ASSIGN(FilePatcherImpl);
97 };
73 98
74 #if !defined(OS_ANDROID) 99 #if !defined(OS_ANDROID)
75 void CreateProxyResolverFactory( 100 void CreateProxyResolverFactory(
76 net::interfaces::ProxyResolverFactoryRequest request) { 101 net::interfaces::ProxyResolverFactoryRequest request) {
77 mojo::MakeStrongBinding(base::MakeUnique<net::MojoProxyResolverFactoryImpl>(), 102 mojo::MakeStrongBinding(base::MakeUnique<net::MojoProxyResolverFactoryImpl>(),
78 std::move(request)); 103 std::move(request));
79 } 104 }
80 105
81 class ResourceUsageReporterImpl : public chrome::mojom::ResourceUsageReporter { 106 class ResourceUsageReporterImpl : public chrome::mojom::ResourceUsageReporter {
82 public: 107 public:
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 173
149 bool ChromeContentUtilityClient::OnMessageReceived( 174 bool ChromeContentUtilityClient::OnMessageReceived(
150 const IPC::Message& message) { 175 const IPC::Message& message) {
151 if (filter_messages_ && 176 if (filter_messages_ &&
152 !base::ContainsKey(message_id_whitelist_, message.type())) { 177 !base::ContainsKey(message_id_whitelist_, message.type())) {
153 return false; 178 return false;
154 } 179 }
155 180
156 bool handled = true; 181 bool handled = true;
157 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) 182 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message)
158 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff,
159 OnPatchFileBsdiff)
160 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileCourgette,
161 OnPatchFileCourgette)
162 #if defined(FULL_SAFE_BROWSING) 183 #if defined(FULL_SAFE_BROWSING)
163 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, 184 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection,
164 OnAnalyzeZipFileForDownloadProtection) 185 OnAnalyzeZipFileForDownloadProtection)
165 #if defined(OS_MACOSX) 186 #if defined(OS_MACOSX)
166 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeDmgFileForDownloadProtection, 187 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeDmgFileForDownloadProtection,
167 OnAnalyzeDmgFileForDownloadProtection) 188 OnAnalyzeDmgFileForDownloadProtection)
168 #endif // defined(OS_MACOSX) 189 #endif // defined(OS_MACOSX)
169 #endif // defined(FULL_SAFE_BROWSING) 190 #endif // defined(FULL_SAFE_BROWSING)
170 #if defined(OS_CHROMEOS) 191 #if defined(OS_CHROMEOS)
171 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CreateZipFile, OnCreateZipFile) 192 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CreateZipFile, OnCreateZipFile)
(...skipping 21 matching lines...) Expand all
193 service_manager::InterfaceRegistry* registry) { 214 service_manager::InterfaceRegistry* registry) {
194 // When the utility process is running with elevated privileges, we need to 215 // When the utility process is running with elevated privileges, we need to
195 // filter messages so that only a whitelist of IPCs can run. In Mojo, there's 216 // filter messages so that only a whitelist of IPCs can run. In Mojo, there's
196 // no way of filtering individual messages. Instead, we can avoid adding 217 // no way of filtering individual messages. Instead, we can avoid adding
197 // non-whitelisted Mojo services to the service_manager::InterfaceRegistry. 218 // non-whitelisted Mojo services to the service_manager::InterfaceRegistry.
198 // TODO(amistry): Use a whitelist once the whistlisted IPCs have been 219 // TODO(amistry): Use a whitelist once the whistlisted IPCs have been
199 // converted to Mojo. 220 // converted to Mojo.
200 if (filter_messages_) 221 if (filter_messages_)
201 return; 222 return;
202 223
224 registry->AddInterface(base::Bind(&FilePatcherImpl::Create));
203 #if !defined(OS_ANDROID) 225 #if !defined(OS_ANDROID)
204 registry->AddInterface<net::interfaces::ProxyResolverFactory>( 226 registry->AddInterface<net::interfaces::ProxyResolverFactory>(
205 base::Bind(CreateProxyResolverFactory)); 227 base::Bind(CreateProxyResolverFactory));
206 registry->AddInterface(base::Bind(CreateResourceUsageReporter)); 228 registry->AddInterface(base::Bind(CreateResourceUsageReporter));
207 registry->AddInterface(base::Bind(&ProfileImportHandler::Create)); 229 registry->AddInterface(base::Bind(&ProfileImportHandler::Create));
208 #endif 230 #endif
209 registry->AddInterface( 231 registry->AddInterface(
210 base::Bind(&safe_json::SafeJsonParserMojoImpl::Create)); 232 base::Bind(&safe_json::SafeJsonParserMojoImpl::Create));
211 #if defined(OS_WIN) 233 #if defined(OS_WIN)
212 registry->AddInterface(base::Bind(&ShellHandlerImpl::Create)); 234 registry->AddInterface(base::Bind(&ShellHandlerImpl::Create));
(...skipping 12 matching lines...) Expand all
225 handlers_.push_back(std::move(handler)); 247 handlers_.push_back(std::move(handler));
226 } 248 }
227 249
228 // static 250 // static
229 void ChromeContentUtilityClient::PreSandboxStartup() { 251 void ChromeContentUtilityClient::PreSandboxStartup() {
230 #if BUILDFLAG(ENABLE_EXTENSIONS) 252 #if BUILDFLAG(ENABLE_EXTENSIONS)
231 extensions::ExtensionsHandler::PreSandboxStartup(); 253 extensions::ExtensionsHandler::PreSandboxStartup();
232 #endif 254 #endif
233 } 255 }
234 256
257 #if defined(OS_CHROMEOS) || defined(FULL_SAFE_BROWSING)
258 bool Send(IPC::Message* message) {
Sam McNally 2016/12/22 02:45:49 These should remain in the anonymous namespace.
Noel Gordon 2016/12/22 05:06:34 Done.
259 return content::UtilityThread::Get()->Send(message);
260 }
261
262 void ReleaseProcessIfNeeded() {
263 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
264 }
265 #endif // defined(OS_CHROMEOS) || defined(FULL_SAFE_BROWSING)
266
235 #if defined(OS_CHROMEOS) 267 #if defined(OS_CHROMEOS)
236 void ChromeContentUtilityClient::OnCreateZipFile( 268 void ChromeContentUtilityClient::OnCreateZipFile(
237 const base::FilePath& src_dir, 269 const base::FilePath& src_dir,
238 const std::vector<base::FilePath>& src_relative_paths, 270 const std::vector<base::FilePath>& src_relative_paths,
239 const base::FileDescriptor& dest_fd) { 271 const base::FileDescriptor& dest_fd) {
240 // dest_fd should be closed in the function. See ipc/ipc_message_util.h for 272 // dest_fd should be closed in the function. See ipc/ipc_message_util.h for
241 // details. 273 // details.
242 base::ScopedFD fd_closer(dest_fd.fd); 274 base::ScopedFD fd_closer(dest_fd.fd);
243 bool succeeded = true; 275 bool succeeded = true;
244 276
(...skipping 12 matching lines...) Expand all
257 succeeded = zip::ZipFiles(src_dir, src_relative_paths, dest_fd.fd); 289 succeeded = zip::ZipFiles(src_dir, src_relative_paths, dest_fd.fd);
258 290
259 if (succeeded) 291 if (succeeded)
260 Send(new ChromeUtilityHostMsg_CreateZipFile_Succeeded()); 292 Send(new ChromeUtilityHostMsg_CreateZipFile_Succeeded());
261 else 293 else
262 Send(new ChromeUtilityHostMsg_CreateZipFile_Failed()); 294 Send(new ChromeUtilityHostMsg_CreateZipFile_Failed());
263 ReleaseProcessIfNeeded(); 295 ReleaseProcessIfNeeded();
264 } 296 }
265 #endif // defined(OS_CHROMEOS) 297 #endif // defined(OS_CHROMEOS)
266 298
267 void ChromeContentUtilityClient::OnPatchFileBsdiff(
268 const IPC::PlatformFileForTransit& input_file,
269 const IPC::PlatformFileForTransit& patch_file,
270 const IPC::PlatformFileForTransit& output_file) {
271 const int patch_status = bsdiff::ApplyBinaryPatch(
272 IPC::PlatformFileForTransitToFile(input_file),
273 IPC::PlatformFileForTransitToFile(patch_file),
274 IPC::PlatformFileForTransitToFile(output_file));
275 Send(new ChromeUtilityHostMsg_PatchFile_Finished(patch_status));
276 ReleaseProcessIfNeeded();
277 }
278
279 void ChromeContentUtilityClient::OnPatchFileCourgette(
280 const IPC::PlatformFileForTransit& input_file,
281 const IPC::PlatformFileForTransit& patch_file,
282 const IPC::PlatformFileForTransit& output_file) {
283 const int patch_status = courgette::ApplyEnsemblePatch(
284 IPC::PlatformFileForTransitToFile(input_file),
285 IPC::PlatformFileForTransitToFile(patch_file),
286 IPC::PlatformFileForTransitToFile(output_file));
287 Send(new ChromeUtilityHostMsg_PatchFile_Finished(patch_status));
288 ReleaseProcessIfNeeded();
289 }
290
291 #if defined(FULL_SAFE_BROWSING) 299 #if defined(FULL_SAFE_BROWSING)
292 void ChromeContentUtilityClient::OnAnalyzeZipFileForDownloadProtection( 300 void ChromeContentUtilityClient::OnAnalyzeZipFileForDownloadProtection(
293 const IPC::PlatformFileForTransit& zip_file, 301 const IPC::PlatformFileForTransit& zip_file,
294 const IPC::PlatformFileForTransit& temp_file) { 302 const IPC::PlatformFileForTransit& temp_file) {
295 safe_browsing::zip_analyzer::Results results; 303 safe_browsing::zip_analyzer::Results results;
296 safe_browsing::zip_analyzer::AnalyzeZipFile( 304 safe_browsing::zip_analyzer::AnalyzeZipFile(
297 IPC::PlatformFileForTransitToFile(zip_file), 305 IPC::PlatformFileForTransitToFile(zip_file),
298 IPC::PlatformFileForTransitToFile(temp_file), &results); 306 IPC::PlatformFileForTransitToFile(temp_file), &results);
299 Send(new ChromeUtilityHostMsg_AnalyzeZipFileForDownloadProtection_Finished( 307 Send(new ChromeUtilityHostMsg_AnalyzeZipFileForDownloadProtection_Finished(
300 results)); 308 results));
301 ReleaseProcessIfNeeded(); 309 ReleaseProcessIfNeeded();
302 } 310 }
303 311
304 #if defined(OS_MACOSX) 312 #if defined(OS_MACOSX)
305 void ChromeContentUtilityClient::OnAnalyzeDmgFileForDownloadProtection( 313 void ChromeContentUtilityClient::OnAnalyzeDmgFileForDownloadProtection(
306 const IPC::PlatformFileForTransit& dmg_file) { 314 const IPC::PlatformFileForTransit& dmg_file) {
307 safe_browsing::zip_analyzer::Results results; 315 safe_browsing::zip_analyzer::Results results;
308 safe_browsing::dmg::AnalyzeDMGFile( 316 safe_browsing::dmg::AnalyzeDMGFile(
309 IPC::PlatformFileForTransitToFile(dmg_file), &results); 317 IPC::PlatformFileForTransitToFile(dmg_file), &results);
310 Send(new ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished( 318 Send(new ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished(
311 results)); 319 results));
312 ReleaseProcessIfNeeded(); 320 ReleaseProcessIfNeeded();
313 } 321 }
314 #endif // defined(OS_MACOSX) 322 #endif // defined(OS_MACOSX)
315 323
316 #endif // defined(FULL_SAFE_BROWSING) 324 #endif // defined(FULL_SAFE_BROWSING)
OLDNEW
« chrome/common/file_patcher.mojom ('K') | « chrome/test/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698