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

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

Issue 2632143002: Convert utility process out-of-process file patching IPC to mojo (Closed)
Patch Set: Reupload to sync to tip. Try landing again. Created 3 years, 11 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 | « 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/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "chrome/common/chrome_utility_messages.h" 16 #include "chrome/common/chrome_utility_messages.h"
17 #include "chrome/common/file_patcher.mojom.h"
17 #include "chrome/common/safe_browsing/zip_analyzer.h" 18 #include "chrome/common/safe_browsing/zip_analyzer.h"
18 #include "chrome/common/safe_browsing/zip_analyzer_results.h" 19 #include "chrome/common/safe_browsing/zip_analyzer_results.h"
19 #include "chrome/utility/chrome_content_utility_ipc_whitelist.h" 20 #include "chrome/utility/chrome_content_utility_ipc_whitelist.h"
20 #include "chrome/utility/utility_message_handler.h" 21 #include "chrome/utility/utility_message_handler.h"
21 #include "components/safe_json/utility/safe_json_parser_mojo_impl.h" 22 #include "components/safe_json/utility/safe_json_parser_mojo_impl.h"
22 #include "content/public/child/image_decoder_utils.h" 23 #include "content/public/child/image_decoder_utils.h"
23 #include "content/public/common/content_switches.h" 24 #include "content/public/common/content_switches.h"
24 #include "content/public/common/service_info.h" 25 #include "content/public/common/service_info.h"
25 #include "content/public/utility/utility_thread.h" 26 #include "content/public/utility/utility_thread.h"
26 #include "courgette/courgette.h" 27 #include "courgette/courgette.h"
(...skipping 30 matching lines...) Expand all
57 (BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN)) 58 (BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN))
58 #include "chrome/utility/printing_handler.h" 59 #include "chrome/utility/printing_handler.h"
59 #endif 60 #endif
60 61
61 #if defined(OS_MACOSX) && defined(FULL_SAFE_BROWSING) 62 #if defined(OS_MACOSX) && defined(FULL_SAFE_BROWSING)
62 #include "chrome/utility/safe_browsing/mac/dmg_analyzer.h" 63 #include "chrome/utility/safe_browsing/mac/dmg_analyzer.h"
63 #endif 64 #endif
64 65
65 namespace { 66 namespace {
66 67
68 #if defined(OS_CHROMEOS) || defined(FULL_SAFE_BROWSING)
67 bool Send(IPC::Message* message) { 69 bool Send(IPC::Message* message) {
68 return content::UtilityThread::Get()->Send(message); 70 return content::UtilityThread::Get()->Send(message);
69 } 71 }
70 72
71 void ReleaseProcessIfNeeded() { 73 void ReleaseProcessIfNeeded() {
72 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); 74 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
73 } 75 }
76 #endif // defined(OS_CHROMEOS) || defined(FULL_SAFE_BROWSING)
77
78 class FilePatcherImpl : public chrome::mojom::FilePatcher {
79 public:
80 FilePatcherImpl() = default;
81 ~FilePatcherImpl() override = default;
82
83 static void Create(chrome::mojom::FilePatcherRequest request) {
84 mojo::MakeStrongBinding(base::MakeUnique<FilePatcherImpl>(),
85 std::move(request));
86 }
87
88 private:
89 // chrome::mojom::FilePatcher:
90 void PatchFileBsdiff(base::File input_file,
91 base::File patch_file,
92 base::File output_file,
93 const PatchFileBsdiffCallback& callback) override {
94 const int patch_result_status = bsdiff::ApplyBinaryPatch(
95 std::move(input_file), std::move(patch_file), std::move(output_file));
96 callback.Run(patch_result_status);
97 }
98
99 void PatchFileCourgette(base::File input_file,
100 base::File patch_file,
101 base::File output_file,
102 const PatchFileCourgetteCallback& callback) override {
103 const int patch_result_status = courgette::ApplyEnsemblePatch(
104 std::move(input_file), std::move(patch_file), std::move(output_file));
105 callback.Run(patch_result_status);
106 }
107
108 DISALLOW_COPY_AND_ASSIGN(FilePatcherImpl);
109 };
74 110
75 #if !defined(OS_ANDROID) 111 #if !defined(OS_ANDROID)
76 void CreateProxyResolverFactory( 112 void CreateProxyResolverFactory(
77 net::interfaces::ProxyResolverFactoryRequest request) { 113 net::interfaces::ProxyResolverFactoryRequest request) {
78 mojo::MakeStrongBinding(base::MakeUnique<net::MojoProxyResolverFactoryImpl>(), 114 mojo::MakeStrongBinding(base::MakeUnique<net::MojoProxyResolverFactoryImpl>(),
79 std::move(request)); 115 std::move(request));
80 } 116 }
81 117
82 class ResourceUsageReporterImpl : public chrome::mojom::ResourceUsageReporter { 118 class ResourceUsageReporterImpl : public chrome::mojom::ResourceUsageReporter {
83 public: 119 public:
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 185
150 bool ChromeContentUtilityClient::OnMessageReceived( 186 bool ChromeContentUtilityClient::OnMessageReceived(
151 const IPC::Message& message) { 187 const IPC::Message& message) {
152 if (filter_messages_ && 188 if (filter_messages_ &&
153 !base::ContainsKey(message_id_whitelist_, message.type())) { 189 !base::ContainsKey(message_id_whitelist_, message.type())) {
154 return false; 190 return false;
155 } 191 }
156 192
157 bool handled = true; 193 bool handled = true;
158 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) 194 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message)
159 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff,
160 OnPatchFileBsdiff)
161 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileCourgette,
162 OnPatchFileCourgette)
163 #if defined(FULL_SAFE_BROWSING) 195 #if defined(FULL_SAFE_BROWSING)
164 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, 196 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection,
165 OnAnalyzeZipFileForDownloadProtection) 197 OnAnalyzeZipFileForDownloadProtection)
166 #if defined(OS_MACOSX) 198 #if defined(OS_MACOSX)
167 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeDmgFileForDownloadProtection, 199 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeDmgFileForDownloadProtection,
168 OnAnalyzeDmgFileForDownloadProtection) 200 OnAnalyzeDmgFileForDownloadProtection)
169 #endif // defined(OS_MACOSX) 201 #endif // defined(OS_MACOSX)
170 #endif // defined(FULL_SAFE_BROWSING) 202 #endif // defined(FULL_SAFE_BROWSING)
171 #if defined(OS_CHROMEOS) 203 #if defined(OS_CHROMEOS)
172 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CreateZipFile, OnCreateZipFile) 204 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CreateZipFile, OnCreateZipFile)
(...skipping 25 matching lines...) Expand all
198 #if BUILDFLAG(ENABLE_EXTENSIONS) 230 #if BUILDFLAG(ENABLE_EXTENSIONS)
199 ChromeContentUtilityClient* utility_client = this; 231 ChromeContentUtilityClient* utility_client = this;
200 extensions::ExtensionsHandler::ExposeInterfacesToBrowser( 232 extensions::ExtensionsHandler::ExposeInterfacesToBrowser(
201 registry, utility_client, running_elevated); 233 registry, utility_client, running_elevated);
202 #endif 234 #endif
203 // If our process runs with elevated privileges, only add elevated Mojo 235 // If our process runs with elevated privileges, only add elevated Mojo
204 // services to the interface registry. 236 // services to the interface registry.
205 if (running_elevated) 237 if (running_elevated)
206 return; 238 return;
207 239
240 registry->AddInterface(base::Bind(&FilePatcherImpl::Create));
208 #if !defined(OS_ANDROID) 241 #if !defined(OS_ANDROID)
209 registry->AddInterface<net::interfaces::ProxyResolverFactory>( 242 registry->AddInterface<net::interfaces::ProxyResolverFactory>(
210 base::Bind(CreateProxyResolverFactory)); 243 base::Bind(CreateProxyResolverFactory));
211 registry->AddInterface(base::Bind(CreateResourceUsageReporter)); 244 registry->AddInterface(base::Bind(CreateResourceUsageReporter));
212 registry->AddInterface(base::Bind(&ProfileImportHandler::Create)); 245 registry->AddInterface(base::Bind(&ProfileImportHandler::Create));
213 #endif 246 #endif
214 registry->AddInterface( 247 registry->AddInterface(
215 base::Bind(&safe_json::SafeJsonParserMojoImpl::Create)); 248 base::Bind(&safe_json::SafeJsonParserMojoImpl::Create));
216 #if defined(OS_WIN) 249 #if defined(OS_WIN)
217 registry->AddInterface(base::Bind(&ShellHandlerImpl::Create)); 250 registry->AddInterface(base::Bind(&ShellHandlerImpl::Create));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 succeeded = zip::ZipFiles(src_dir, src_relative_paths, dest_fd.fd); 295 succeeded = zip::ZipFiles(src_dir, src_relative_paths, dest_fd.fd);
263 296
264 if (succeeded) 297 if (succeeded)
265 Send(new ChromeUtilityHostMsg_CreateZipFile_Succeeded()); 298 Send(new ChromeUtilityHostMsg_CreateZipFile_Succeeded());
266 else 299 else
267 Send(new ChromeUtilityHostMsg_CreateZipFile_Failed()); 300 Send(new ChromeUtilityHostMsg_CreateZipFile_Failed());
268 ReleaseProcessIfNeeded(); 301 ReleaseProcessIfNeeded();
269 } 302 }
270 #endif // defined(OS_CHROMEOS) 303 #endif // defined(OS_CHROMEOS)
271 304
272 void ChromeContentUtilityClient::OnPatchFileBsdiff(
273 const IPC::PlatformFileForTransit& input_file,
274 const IPC::PlatformFileForTransit& patch_file,
275 const IPC::PlatformFileForTransit& output_file) {
276 const int patch_status = bsdiff::ApplyBinaryPatch(
277 IPC::PlatformFileForTransitToFile(input_file),
278 IPC::PlatformFileForTransitToFile(patch_file),
279 IPC::PlatformFileForTransitToFile(output_file));
280 Send(new ChromeUtilityHostMsg_PatchFile_Finished(patch_status));
281 ReleaseProcessIfNeeded();
282 }
283
284 void ChromeContentUtilityClient::OnPatchFileCourgette(
285 const IPC::PlatformFileForTransit& input_file,
286 const IPC::PlatformFileForTransit& patch_file,
287 const IPC::PlatformFileForTransit& output_file) {
288 const int patch_status = courgette::ApplyEnsemblePatch(
289 IPC::PlatformFileForTransitToFile(input_file),
290 IPC::PlatformFileForTransitToFile(patch_file),
291 IPC::PlatformFileForTransitToFile(output_file));
292 Send(new ChromeUtilityHostMsg_PatchFile_Finished(patch_status));
293 ReleaseProcessIfNeeded();
294 }
295
296 #if defined(FULL_SAFE_BROWSING) 305 #if defined(FULL_SAFE_BROWSING)
297 void ChromeContentUtilityClient::OnAnalyzeZipFileForDownloadProtection( 306 void ChromeContentUtilityClient::OnAnalyzeZipFileForDownloadProtection(
298 const IPC::PlatformFileForTransit& zip_file, 307 const IPC::PlatformFileForTransit& zip_file,
299 const IPC::PlatformFileForTransit& temp_file) { 308 const IPC::PlatformFileForTransit& temp_file) {
300 safe_browsing::zip_analyzer::Results results; 309 safe_browsing::zip_analyzer::Results results;
301 safe_browsing::zip_analyzer::AnalyzeZipFile( 310 safe_browsing::zip_analyzer::AnalyzeZipFile(
302 IPC::PlatformFileForTransitToFile(zip_file), 311 IPC::PlatformFileForTransitToFile(zip_file),
303 IPC::PlatformFileForTransitToFile(temp_file), &results); 312 IPC::PlatformFileForTransitToFile(temp_file), &results);
304 Send(new ChromeUtilityHostMsg_AnalyzeZipFileForDownloadProtection_Finished( 313 Send(new ChromeUtilityHostMsg_AnalyzeZipFileForDownloadProtection_Finished(
305 results)); 314 results));
306 ReleaseProcessIfNeeded(); 315 ReleaseProcessIfNeeded();
307 } 316 }
308 317
309 #if defined(OS_MACOSX) 318 #if defined(OS_MACOSX)
310 void ChromeContentUtilityClient::OnAnalyzeDmgFileForDownloadProtection( 319 void ChromeContentUtilityClient::OnAnalyzeDmgFileForDownloadProtection(
311 const IPC::PlatformFileForTransit& dmg_file) { 320 const IPC::PlatformFileForTransit& dmg_file) {
312 safe_browsing::zip_analyzer::Results results; 321 safe_browsing::zip_analyzer::Results results;
313 safe_browsing::dmg::AnalyzeDMGFile( 322 safe_browsing::dmg::AnalyzeDMGFile(
314 IPC::PlatformFileForTransitToFile(dmg_file), &results); 323 IPC::PlatformFileForTransitToFile(dmg_file), &results);
315 Send(new ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished( 324 Send(new ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished(
316 results)); 325 results));
317 ReleaseProcessIfNeeded(); 326 ReleaseProcessIfNeeded();
318 } 327 }
319 #endif // defined(OS_MACOSX) 328 #endif // defined(OS_MACOSX)
320 329
321 #endif // defined(FULL_SAFE_BROWSING) 330 #endif // defined(FULL_SAFE_BROWSING)
OLDNEW
« no previous file with comments | « chrome/test/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698