Chromium Code Reviews| Index: chrome/utility/chrome_content_utility_client.cc |
| diff --git a/chrome/utility/chrome_content_utility_client.cc b/chrome/utility/chrome_content_utility_client.cc |
| index f95ceadf3fa977e555000d5a31af82ab7574b0df..acf04efb5db91a57570a4090142edc27f3915a5e 100644 |
| --- a/chrome/utility/chrome_content_utility_client.cc |
| +++ b/chrome/utility/chrome_content_utility_client.cc |
| @@ -13,6 +13,7 @@ |
| #include "base/time/time.h" |
| #include "build/build_config.h" |
| #include "chrome/common/chrome_utility_messages.h" |
| +#include "chrome/common/file_patcher.mojom.h" |
| #include "chrome/common/safe_browsing/zip_analyzer.h" |
| #include "chrome/common/safe_browsing/zip_analyzer_results.h" |
| #include "chrome/utility/chrome_content_utility_ipc_whitelist.h" |
| @@ -63,13 +64,37 @@ |
| namespace { |
| -bool Send(IPC::Message* message) { |
| - return content::UtilityThread::Get()->Send(message); |
| -} |
| +class FilePatcherImpl : public chrome::mojom::FilePatcher { |
| + public: |
| + FilePatcherImpl() {} |
|
Sam McNally
2016/12/22 02:45:49
= default;
Noel Gordon
2016/12/22 05:06:34
Done.
|
| + ~FilePatcherImpl() override {} |
|
Sam McNally
2016/12/22 02:45:49
= default;
Noel Gordon
2016/12/22 05:06:34
Done.
|
| -void ReleaseProcessIfNeeded() { |
| - content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
| -} |
| + static void Create(chrome::mojom::FilePatcherRequest request) { |
| + mojo::MakeStrongBinding(base::MakeUnique<FilePatcherImpl>(), |
| + std::move(request)); |
| + } |
| + |
| + private: |
| + void PatchFileBsdiff(base::File input_file, |
|
tibell
2016/12/22 02:59:38
We usually add line
// chrome::mojom::FilePatcher
|
| + base::File patch_file, |
| + base::File output_file, |
| + const PatchFileBsdiffCallback& callback) override { |
| + const int patch_result_status = bsdiff::ApplyBinaryPatch( |
| + std::move(input_file), std::move(patch_file), std::move(output_file)); |
| + callback.Run(patch_result_status); |
| + } |
| + |
| + void PatchFileCourgette(base::File input_file, |
| + base::File patch_file, |
| + base::File output_file, |
| + const PatchFileCourgetteCallback& callback) override { |
| + const int patch_result_status = courgette::ApplyEnsemblePatch( |
| + std::move(input_file), std::move(patch_file), std::move(output_file)); |
| + callback.Run(patch_result_status); |
| + } |
| + |
| + DISALLOW_COPY_AND_ASSIGN(FilePatcherImpl); |
| +}; |
| #if !defined(OS_ANDROID) |
| void CreateProxyResolverFactory( |
| @@ -155,10 +180,6 @@ bool ChromeContentUtilityClient::OnMessageReceived( |
| bool handled = true; |
| IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) |
| - IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff, |
| - OnPatchFileBsdiff) |
| - IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileCourgette, |
| - OnPatchFileCourgette) |
| #if defined(FULL_SAFE_BROWSING) |
| IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, |
| OnAnalyzeZipFileForDownloadProtection) |
| @@ -200,6 +221,7 @@ void ChromeContentUtilityClient::ExposeInterfacesToBrowser( |
| if (filter_messages_) |
| return; |
| + registry->AddInterface(base::Bind(&FilePatcherImpl::Create)); |
| #if !defined(OS_ANDROID) |
| registry->AddInterface<net::interfaces::ProxyResolverFactory>( |
| base::Bind(CreateProxyResolverFactory)); |
| @@ -232,6 +254,16 @@ void ChromeContentUtilityClient::PreSandboxStartup() { |
| #endif |
| } |
| +#if defined(OS_CHROMEOS) || defined(FULL_SAFE_BROWSING) |
| +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.
|
| + return content::UtilityThread::Get()->Send(message); |
| +} |
| + |
| +void ReleaseProcessIfNeeded() { |
| + content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
| +} |
| +#endif // defined(OS_CHROMEOS) || defined(FULL_SAFE_BROWSING) |
| + |
| #if defined(OS_CHROMEOS) |
| void ChromeContentUtilityClient::OnCreateZipFile( |
| const base::FilePath& src_dir, |
| @@ -264,30 +296,6 @@ void ChromeContentUtilityClient::OnCreateZipFile( |
| } |
| #endif // defined(OS_CHROMEOS) |
| -void ChromeContentUtilityClient::OnPatchFileBsdiff( |
| - const IPC::PlatformFileForTransit& input_file, |
| - const IPC::PlatformFileForTransit& patch_file, |
| - const IPC::PlatformFileForTransit& output_file) { |
| - const int patch_status = bsdiff::ApplyBinaryPatch( |
| - IPC::PlatformFileForTransitToFile(input_file), |
| - IPC::PlatformFileForTransitToFile(patch_file), |
| - IPC::PlatformFileForTransitToFile(output_file)); |
| - Send(new ChromeUtilityHostMsg_PatchFile_Finished(patch_status)); |
| - ReleaseProcessIfNeeded(); |
| -} |
| - |
| -void ChromeContentUtilityClient::OnPatchFileCourgette( |
| - const IPC::PlatformFileForTransit& input_file, |
| - const IPC::PlatformFileForTransit& patch_file, |
| - const IPC::PlatformFileForTransit& output_file) { |
| - const int patch_status = courgette::ApplyEnsemblePatch( |
| - IPC::PlatformFileForTransitToFile(input_file), |
| - IPC::PlatformFileForTransitToFile(patch_file), |
| - IPC::PlatformFileForTransitToFile(output_file)); |
| - Send(new ChromeUtilityHostMsg_PatchFile_Finished(patch_status)); |
| - ReleaseProcessIfNeeded(); |
| -} |
| - |
| #if defined(FULL_SAFE_BROWSING) |
| void ChromeContentUtilityClient::OnAnalyzeZipFileForDownloadProtection( |
| const IPC::PlatformFileForTransit& zip_file, |