From 785c71fe215f65b36d587a0b64a06aec70dee060 Mon Sep 17 00:00:00 2001 From: "erikchen@chromium.org" Date: Wed, 26 Mar 2014 23:48:19 +0000 Subject: [PATCH] Revert of Use UtilityProcessHost to patch files. (https://codereview.chromium.org/25909005/) Reason for revert: linux asan failure http://build.chromium.org/p/chromium.memory/builders/Linux%20ASan%2BLSan%20Tests%20%282%29/builds/901/steps/unit_tests/logs/DifferentialUpdateFails Original issue's description: > Use UtilityProcessHost to patch files. > > Second part of a 2-part changelist. > The first part is https://codereview.chromium.org/25883006/ > > BUG=304879 > > Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=259726 TBR=sorin@chromium.org,dgarrett@chromium.org,sky@chromium.org,cdn@chromium.org,waffles@chromium.org NOTREECHECKS=true NOTRY=true BUG=304879 Review URL: https://codereview.chromium.org/213923002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@259740 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/DEPS | 1 - chrome/browser/component_updater/DEPS | 1 - .../component_updater/component_patcher.cc | 115 +++---- .../component_updater/component_patcher.h | 92 +++-- .../component_patcher_operation.cc | 314 +++++------------- .../component_patcher_operation.h | 151 +++------ .../component_patcher_win.cc | 118 +++++++ .../component_updater/component_patcher_win.h | 28 ++ .../component_updater/component_unpacker.cc | 40 +-- .../component_updater/component_unpacker.h | 26 +- .../component_updater_configurator.cc | 20 +- .../component_updater_service.cc | 20 +- .../component_updater_service.h | 4 + chrome/browser/component_updater/test/DEPS | 1 + .../test/component_patcher_mock.h | 32 ++ .../test/component_patcher_unittest.cc | 160 ++++----- .../test/component_patcher_unittest.h | 6 +- .../component_updater_service_unittest.cc | 4 + .../test/component_updater_service_unittest.h | 2 + chrome/chrome_browser.gypi | 3 +- chrome/chrome_tests_unit.gypi | 1 + chrome/common/chrome_utility_messages.h | 25 +- chrome/utility/DEPS | 1 - .../utility/chrome_content_utility_client.cc | 43 --- .../utility/chrome_content_utility_client.h | 6 - content/content_utility.gypi | 1 - 26 files changed, 535 insertions(+), 680 deletions(-) create mode 100644 chrome/browser/component_updater/component_patcher_win.cc create mode 100644 chrome/browser/component_updater/component_patcher_win.h create mode 100644 chrome/browser/component_updater/test/component_patcher_mock.h diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 39be0d775ec1c7..1286def3ac11da 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -40,7 +40,6 @@ include_rules = [ "+components/webdata/common", "+content/public/browser", "+content/test/net", - "+courgette", "+device/bluetooth", "+device/media_transfer_protocol", "+extensions/browser", diff --git a/chrome/browser/component_updater/DEPS b/chrome/browser/component_updater/DEPS index 6452369228f83e..6858ef79d5fc18 100644 --- a/chrome/browser/component_updater/DEPS +++ b/chrome/browser/component_updater/DEPS @@ -1,5 +1,4 @@ include_rules = [ - "+courgette", "+media/cdm/ppapi/supported_cdm_versions.h", "+ppapi/shared_impl/ppapi_permissions.h", "+ppapi/thunk", diff --git a/chrome/browser/component_updater/component_patcher.cc b/chrome/browser/component_updater/component_patcher.cc index 78064300c12171..59f283aaf17580 100644 --- a/chrome/browser/component_updater/component_patcher.cc +++ b/chrome/browser/component_updater/component_patcher.cc @@ -7,15 +7,11 @@ #include #include -#include "base/basictypes.h" #include "base/file_util.h" -#include "base/files/file_path.h" #include "base/json/json_file_value_serializer.h" -#include "base/memory/weak_ptr.h" #include "base/values.h" #include "chrome/browser/component_updater/component_patcher_operation.h" #include "chrome/browser/component_updater/component_updater_service.h" -#include "content/public/browser/browser_thread.h" namespace component_updater { @@ -38,83 +34,58 @@ base::ListValue* ReadCommands(const base::FilePath& unpack_path) { } // namespace -ComponentPatcher::ComponentPatcher( - const base::FilePath& input_dir, - const base::FilePath& unpack_dir, - ComponentInstaller* installer, - bool in_process, - scoped_refptr task_runner) - : input_dir_(input_dir), - unpack_dir_(unpack_dir), - installer_(installer), - in_process_(in_process), - task_runner_(task_runner) { -} +// The patching support is not cross-platform at the moment. +ComponentPatcherCrossPlatform::ComponentPatcherCrossPlatform() {} -ComponentPatcher::~ComponentPatcher() { +ComponentUnpacker::Error ComponentPatcherCrossPlatform::Patch( + PatchType patch_type, + const base::FilePath& input_file, + const base::FilePath& patch_file, + const base::FilePath& output_file, + int* error) { + return ComponentUnpacker::kDeltaUnsupportedCommand; } -void ComponentPatcher::Start(const ComponentUnpacker::Callback& callback) { - callback_ = callback; - task_runner_->PostTask(FROM_HERE, - base::Bind(&ComponentPatcher::StartPatching, - scoped_refptr(this))); -} -void ComponentPatcher::StartPatching() { - commands_.reset(ReadCommands(input_dir_)); - if (!commands_.get()) { - DonePatching(ComponentUnpacker::kDeltaBadCommands, 0); - } else { - next_command_ = commands_->begin(); - PatchNextFile(); - } -} - -void ComponentPatcher::PatchNextFile() { - if (next_command_ == commands_->end()) { - DonePatching(ComponentUnpacker::kNone, 0); - return; - } - if (!(*next_command_)->IsType(base::Value::TYPE_DICTIONARY)) { - DonePatching(ComponentUnpacker::kDeltaBadCommands, 0); - return; - } - const base::DictionaryValue* command_args = - static_cast(*next_command_); - current_operation_ = CreateDeltaUpdateOp(*command_args); - if (!current_operation_) { - DonePatching(ComponentUnpacker::kDeltaUnsupportedCommand, 0); +// Takes the contents of a differential component update in input_dir +// and produces the contents of a full component update in unpack_dir +// using input_abs_path_ files that the installer knows about. +void DifferentialUpdatePatch( + const base::FilePath& input_dir, + const base::FilePath& unpack_dir, + ComponentPatcher* patcher, + ComponentInstaller* installer, + base::Callback callback) { + int error = 0; + scoped_ptr commands(ReadCommands(input_dir)); + if (!commands.get()) { + callback.Run(ComponentUnpacker::kDeltaBadCommands, error); return; } - current_operation_->Run( - command_args, - input_dir_, - unpack_dir_, - installer_, - in_process_, - base::Bind(&ComponentPatcher::DonePatchingFile, - scoped_refptr(this)), - task_runner_); -} -void ComponentPatcher::DonePatchingFile(ComponentUnpacker::Error error, - int extended_error) { - if (error != ComponentUnpacker::kNone) { - DonePatching(error, extended_error); - } else { - ++next_command_; - PatchNextFile(); + for (base::ValueVector::const_iterator command = commands->begin(), + end = commands->end(); command != end; command++) { + if (!(*command)->IsType(base::Value::TYPE_DICTIONARY)) { + callback.Run(ComponentUnpacker::kDeltaBadCommands, error); + return; + } + base::DictionaryValue* command_args = + static_cast(*command); + scoped_ptr operation(CreateDeltaUpdateOp(command_args)); + if (!operation) { + callback.Run(ComponentUnpacker::kDeltaUnsupportedCommand, error); + return; + } + + ComponentUnpacker::Error result = operation->Run( + command_args, input_dir, unpack_dir, patcher, installer, &error); + if (result != ComponentUnpacker::kNone) { + callback.Run(result, error); + return; + } } -} -void ComponentPatcher::DonePatching(ComponentUnpacker::Error error, - int extended_error) { - current_operation_ = NULL; - task_runner_->PostTask(FROM_HERE, base::Bind(callback_, - error, - extended_error)); - callback_.Reset(); + callback.Run(ComponentUnpacker::kNone, error); } } // namespace component_updater diff --git a/chrome/browser/component_updater/component_patcher.h b/chrome/browser/component_updater/component_patcher.h index 9269967b4abc51..6a6cb8f084cbae 100644 --- a/chrome/browser/component_updater/component_patcher.h +++ b/chrome/browser/component_updater/component_patcher.h @@ -28,9 +28,9 @@ #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ +#include "base/basictypes.h" #include "base/callback_forward.h" -#include "base/memory/ref_counted.h" -#include "base/values.h" +#include "base/compiler_specific.h" #include "chrome/browser/component_updater/component_unpacker.h" namespace base { @@ -40,61 +40,53 @@ class FilePath; namespace component_updater { class ComponentInstaller; -class DeltaUpdateOp; -// The type of a patch file. -enum PatchType { - kPatchTypeUnknown, - kPatchTypeCourgette, - kPatchTypeBsdiff, +// Applies a delta patch to a single file. Specifically, creates a file at +// |output_file| using |input_file| patched according to the algorithm +// specified by |patch_type| using |patch_file|. Sets the value of error to +// the error code of the failing patch operation, if there is such a failure. +class ComponentPatcher { + public: + // The type of a patch file. + enum PatchType { + kPatchTypeUnknown, + kPatchTypeCourgette, + kPatchTypeBsdiff, + }; + + virtual ComponentUnpacker::Error Patch(PatchType patch_type, + const base::FilePath& input_file, + const base::FilePath& patch_file, + const base::FilePath& output_file, + int* error) = 0; + virtual ~ComponentPatcher() {} }; -// Encapsulates a task for applying a differential update to a component. -class ComponentPatcher : public base::RefCountedThreadSafe { +class ComponentPatcherCrossPlatform : public ComponentPatcher { public: - // Takes an unpacked differential CRX (|input_dir|) and a component installer, - // and sets up the class to create a new (non-differential) unpacked CRX. - // If |in_process| is true, patching will be done completely within the - // existing process. Otherwise, some steps of patching may be done - // out-of-process. - ComponentPatcher(const base::FilePath& input_dir, - const base::FilePath& unpack_dir, - ComponentInstaller* installer, - bool in_process, - scoped_refptr task_runner); - - // Starts patching files. This member function returns immediately, after - // posting a task to do the patching. When patching has been completed, - // |callback| will be called with the error codes if any error codes were - // encountered. - void Start(const ComponentUnpacker::Callback& callback); - + ComponentPatcherCrossPlatform(); + virtual ComponentUnpacker::Error Patch(PatchType patch_type, + const base::FilePath& input_file, + const base::FilePath& patch_file, + const base::FilePath& output_file, + int* error) OVERRIDE; private: - friend class base::RefCountedThreadSafe; - - virtual ~ComponentPatcher(); - - void StartPatching(); - - void PatchNextFile(); - - void DonePatchingFile(ComponentUnpacker::Error error, int extended_error); - - void DonePatching(ComponentUnpacker::Error error, int extended_error); - - const base::FilePath input_dir_; - const base::FilePath unpack_dir_; - ComponentInstaller* const installer_; - const bool in_process_; - ComponentUnpacker::Callback callback_; - scoped_ptr commands_; - base::ValueVector::const_iterator next_command_; - scoped_refptr current_operation_; - scoped_refptr task_runner_; - - DISALLOW_COPY_AND_ASSIGN(ComponentPatcher); + DISALLOW_COPY_AND_ASSIGN(ComponentPatcherCrossPlatform); }; +// This function takes an unpacked differential CRX (|input_dir|) and a +// component installer, and creates a new (non-differential) unpacked CRX, which +// is then installed normally. +// The non-differential files are written into the |unpack_dir| directory. +// When finished, calls the callback, passing error codes if any errors were +// encountered. +void DifferentialUpdatePatch( + const base::FilePath& input_dir, + const base::FilePath& unpack_dir, + ComponentPatcher* component_patcher, + ComponentInstaller* installer, + base::Callback callback); + } // namespace component_updater #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ diff --git a/chrome/browser/component_updater/component_patcher_operation.cc b/chrome/browser/component_updater/component_patcher_operation.cc index ded74275da4cd6..6b86d9fc8a6dc2 100644 --- a/chrome/browser/component_updater/component_patcher_operation.cc +++ b/chrome/browser/component_updater/component_patcher_operation.cc @@ -7,7 +7,6 @@ #include #include -#include "base/bind.h" #include "base/file_util.h" #include "base/files/memory_mapped_file.h" #include "base/json/json_file_value_serializer.h" @@ -16,17 +15,11 @@ #include "base/strings/string_number_conversions.h" #include "chrome/browser/component_updater/component_patcher.h" #include "chrome/browser/component_updater/component_updater_service.h" -#include "chrome/common/chrome_utility_messages.h" #include "chrome/common/extensions/extension_constants.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/utility_process_host.h" -#include "courgette/courgette.h" -#include "courgette/third_party/bsdiff.h" #include "crypto/secure_hash.h" #include "crypto/sha2.h" #include "crypto/signature_verifier.h" #include "extensions/common/crx_file.h" -#include "ipc/ipc_message_macros.h" #include "third_party/zlib/google/zip.h" using crypto::SecureHash; @@ -41,165 +34,56 @@ const char kOutput[] = "output"; const char kPatch[] = "patch"; const char kSha256[] = "sha256"; -// The integer offset disambiguates between overlapping error ranges. -const int kCourgetteErrorOffset = 300; -const int kBsdiffErrorOffset = 600; - -class CourgetteTraits : public DeltaUpdateOpPatchStrategy { - public: - virtual int GetErrorOffset() const OVERRIDE; - virtual int GetSuccessCode() const OVERRIDE; - virtual scoped_ptr GetPatchMessage( - base::FilePath input_abs_path, - base::FilePath patch_abs_path, - base::FilePath output_abs_path) OVERRIDE; - virtual int Patch(base::FilePath input_abs_path, - base::FilePath patch_abs_path, - base::FilePath output_abs_path) OVERRIDE; -}; - -int CourgetteTraits::GetErrorOffset() const { - return kCourgetteErrorOffset; -} - -int CourgetteTraits::GetSuccessCode() const { - return courgette::C_OK; -} - -scoped_ptr CourgetteTraits::GetPatchMessage( - base::FilePath input_abs_path, - base::FilePath patch_abs_path, - base::FilePath output_abs_path) { - return scoped_ptr( - new ChromeUtilityMsg_PatchFileCourgette(input_abs_path, - patch_abs_path, - output_abs_path)); -} - -int CourgetteTraits::Patch(base::FilePath input_abs_path, - base::FilePath patch_abs_path, - base::FilePath output_abs_path) { - return courgette::ApplyEnsemblePatch(input_abs_path.value().c_str(), - patch_abs_path.value().c_str(), - output_abs_path.value().c_str()); -} - -class BsdiffTraits : public DeltaUpdateOpPatchStrategy { - public: - virtual int GetErrorOffset() const OVERRIDE; - virtual int GetSuccessCode() const OVERRIDE; - virtual scoped_ptr GetPatchMessage( - base::FilePath input_abs_path, - base::FilePath patch_abs_path, - base::FilePath output_abs_path) OVERRIDE; - virtual int Patch(base::FilePath input_abs_path, - base::FilePath patch_abs_path, - base::FilePath output_abs_path) OVERRIDE; -}; - -int BsdiffTraits::GetErrorOffset() const { - return kBsdiffErrorOffset; -} - -int BsdiffTraits::GetSuccessCode() const { - return courgette::OK; -} - -scoped_ptr BsdiffTraits::GetPatchMessage( - base::FilePath input_abs_path, - base::FilePath patch_abs_path, - base::FilePath output_abs_path) { - return scoped_ptr( - new ChromeUtilityMsg_PatchFileBsdiff(input_abs_path, - patch_abs_path, - output_abs_path)); -} - -int BsdiffTraits::Patch(base::FilePath input_abs_path, - base::FilePath patch_abs_path, - base::FilePath output_abs_path) { - return courgette::ApplyBinaryPatch(input_abs_path, - patch_abs_path, - output_abs_path); -} - } // namespace -DeltaUpdateOpPatchStrategy::~DeltaUpdateOpPatchStrategy() { -} - -DeltaUpdateOp* CreateDeltaUpdateOp(const std::string& operation) { - if (operation == "copy") { +DeltaUpdateOp* CreateDeltaUpdateOp(base::DictionaryValue* command) { + std::string operation; + if (!command->GetString(kOp, &operation)) + return NULL; + if (operation == "copy") return new DeltaUpdateOpCopy(); - } else if (operation == "create") { + else if (operation == "create") return new DeltaUpdateOpCreate(); - } else if (operation == "bsdiff") { - scoped_ptr strategy(new BsdiffTraits()); - return new DeltaUpdateOpPatch(strategy.Pass()); - } else if (operation == "courgette") { - scoped_ptr strategy(new CourgetteTraits()); - return new DeltaUpdateOpPatch(strategy.Pass()); - } + else if (operation == "bsdiff") + return new DeltaUpdateOpPatchBsdiff(); + else if (operation == "courgette") + return new DeltaUpdateOpPatchCourgette(); return NULL; } -DeltaUpdateOp* CreateDeltaUpdateOp(const base::DictionaryValue& command) { - std::string operation; - if (!command.GetString(kOp, &operation)) - return NULL; - return CreateDeltaUpdateOp(operation); -} - -DeltaUpdateOp::DeltaUpdateOp() : in_process_(false) {} +DeltaUpdateOp::DeltaUpdateOp() {} DeltaUpdateOp::~DeltaUpdateOp() {} -void DeltaUpdateOp::Run( - const base::DictionaryValue* command_args, - const base::FilePath& input_dir, - const base::FilePath& unpack_dir, - ComponentInstaller* installer, - bool in_process, - const ComponentUnpacker::Callback& callback, - scoped_refptr task_runner) { - callback_ = callback; - in_process_ = in_process; - task_runner_ = task_runner; +ComponentUnpacker::Error DeltaUpdateOp::Run(base::DictionaryValue* command_args, + const base::FilePath& input_dir, + const base::FilePath& unpack_dir, + ComponentPatcher* patcher, + ComponentInstaller* installer, + int* error) { std::string output_rel_path; if (!command_args->GetString(kOutput, &output_rel_path) || - !command_args->GetString(kSha256, &output_sha256_)) { - DoneRunning(ComponentUnpacker::kDeltaBadCommands, 0); - return; - } + !command_args->GetString(kSha256, &output_sha256_)) + return ComponentUnpacker::kDeltaBadCommands; output_abs_path_ = unpack_dir.Append( base::FilePath::FromUTF8Unsafe(output_rel_path)); ComponentUnpacker::Error parse_result = DoParseArguments( command_args, input_dir, installer); - if (parse_result != ComponentUnpacker::kNone) { - DoneRunning(parse_result, 0); - return; - } + if (parse_result != ComponentUnpacker::kNone) + return parse_result; const base::FilePath parent = output_abs_path_.DirName(); if (!base::DirectoryExists(parent)) { - if (!base::CreateDirectory(parent)) { - DoneRunning(ComponentUnpacker::kIoError, 0); - return; - } + if (!base::CreateDirectory(parent)) + return ComponentUnpacker::kIoError; } - DoRun(base::Bind(&DeltaUpdateOp::DoneRunning, - scoped_refptr(this))); -} + ComponentUnpacker::Error run_result = DoRun(patcher, error); + if (run_result != ComponentUnpacker::kNone) + return run_result; -void DeltaUpdateOp::DoneRunning(ComponentUnpacker::Error error, - int extended_error) { - if (error == ComponentUnpacker::kNone) - error = CheckHash(); - task_runner_->PostTask(FROM_HERE, - base::Bind(callback_, error, extended_error)); - callback_.Reset(); + return CheckHash(); } // Uses the hash as a checksum to confirm that the file now residing in the @@ -224,16 +108,10 @@ ComponentUnpacker::Error DeltaUpdateOp::CheckHash() { return ComponentUnpacker::kNone; } -bool DeltaUpdateOp::InProcess() { - return in_process_; -} - DeltaUpdateOpCopy::DeltaUpdateOpCopy() {} -DeltaUpdateOpCopy::~DeltaUpdateOpCopy() {} - ComponentUnpacker::Error DeltaUpdateOpCopy::DoParseArguments( - const base::DictionaryValue* command_args, + base::DictionaryValue* command_args, const base::FilePath& input_dir, ComponentInstaller* installer) { std::string input_rel_path; @@ -246,19 +124,19 @@ ComponentUnpacker::Error DeltaUpdateOpCopy::DoParseArguments( return ComponentUnpacker::kNone; } -void DeltaUpdateOpCopy::DoRun(const ComponentUnpacker::Callback& callback) { +ComponentUnpacker::Error DeltaUpdateOpCopy::DoRun(ComponentPatcher*, + int* error) { + *error = 0; if (!base::CopyFile(input_abs_path_, output_abs_path_)) - callback.Run(ComponentUnpacker::kDeltaOperationFailure, 0); - else - callback.Run(ComponentUnpacker::kNone, 0); + return ComponentUnpacker::kDeltaOperationFailure; + + return ComponentUnpacker::kNone; } DeltaUpdateOpCreate::DeltaUpdateOpCreate() {} -DeltaUpdateOpCreate::~DeltaUpdateOpCreate() {} - ComponentUnpacker::Error DeltaUpdateOpCreate::DoParseArguments( - const base::DictionaryValue* command_args, + base::DictionaryValue* command_args, const base::FilePath& input_dir, ComponentInstaller* installer) { std::string patch_rel_path; @@ -271,68 +149,51 @@ ComponentUnpacker::Error DeltaUpdateOpCreate::DoParseArguments( return ComponentUnpacker::kNone; } -void DeltaUpdateOpCreate::DoRun(const ComponentUnpacker::Callback& callback) { +ComponentUnpacker::Error DeltaUpdateOpCreate::DoRun(ComponentPatcher*, + int* error) { + *error = 0; if (!base::Move(patch_abs_path_, output_abs_path_)) - callback.Run(ComponentUnpacker::kDeltaOperationFailure, 0); - else - callback.Run(ComponentUnpacker::kNone, 0); -} - -DeltaUpdateOpPatchHost::DeltaUpdateOpPatchHost( - scoped_refptr patcher) : patcher_(patcher) { -} + return ComponentUnpacker::kDeltaOperationFailure; -DeltaUpdateOpPatchHost::~DeltaUpdateOpPatchHost() { + return ComponentUnpacker::kNone; } -void DeltaUpdateOpPatchHost::StartProcess(scoped_ptr message) { - // The DeltaUpdateOpPatchHost is not responsible for deleting the - // UtilityProcessHost object. - content::UtilityProcessHost* host = content::UtilityProcessHost::Create( - this, base::MessageLoopProxy::current().get()); - host->DisableSandbox(); - host->Send(message.get()); -} +DeltaUpdateOpPatchBsdiff::DeltaUpdateOpPatchBsdiff() {} -bool DeltaUpdateOpPatchHost::OnMessageReceived(const IPC::Message& message) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(DeltaUpdateOpPatchHost, message) - IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_PatchFile_Succeeded, - OnPatchSucceeded) - IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_PatchFile_Failed, - OnPatchFailed) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} +ComponentUnpacker::Error DeltaUpdateOpPatchBsdiff::DoParseArguments( + base::DictionaryValue* command_args, + const base::FilePath& input_dir, + ComponentInstaller* installer) { + std::string patch_rel_path; + std::string input_rel_path; + if (!command_args->GetString(kPatch, &patch_rel_path) || + !command_args->GetString(kInput, &input_rel_path)) + return ComponentUnpacker::kDeltaBadCommands; -void DeltaUpdateOpPatchHost::OnPatchSucceeded() { - patcher_->DonePatching(ComponentUnpacker::kNone, 0); - patcher_ = NULL; -} + if (!installer->GetInstalledFile(input_rel_path, &input_abs_path_)) + return ComponentUnpacker::kDeltaMissingExistingFile; -void DeltaUpdateOpPatchHost::OnPatchFailed(int error_code) { - patcher_->DonePatching(ComponentUnpacker::kDeltaOperationFailure, error_code); - patcher_ = NULL; -} + patch_abs_path_ = input_dir.Append( + base::FilePath::FromUTF8Unsafe(patch_rel_path)); -void DeltaUpdateOpPatchHost::OnProcessCrashed(int exit_code) { - patcher_->DonePatching(ComponentUnpacker::kDeltaPatchProcessFailure, - exit_code); - patcher_ = NULL; + return ComponentUnpacker::kNone; } -DeltaUpdateOpPatch::DeltaUpdateOpPatch( - scoped_ptr strategy) { - strategy_ = strategy.Pass(); - host_ = new DeltaUpdateOpPatchHost(scoped_refptr(this)); +ComponentUnpacker::Error DeltaUpdateOpPatchBsdiff::DoRun( + ComponentPatcher* patcher, + int* error) { + *error = 0; + return patcher->Patch(ComponentPatcher::kPatchTypeBsdiff, + input_abs_path_, + patch_abs_path_, + output_abs_path_, + error); } -DeltaUpdateOpPatch::~DeltaUpdateOpPatch() { -} +DeltaUpdateOpPatchCourgette::DeltaUpdateOpPatchCourgette() {} -ComponentUnpacker::Error DeltaUpdateOpPatch::DoParseArguments( - const base::DictionaryValue* command_args, +ComponentUnpacker::Error DeltaUpdateOpPatchCourgette::DoParseArguments( + base::DictionaryValue* command_args, const base::FilePath& input_dir, ComponentInstaller* installer) { std::string patch_rel_path; @@ -350,38 +211,15 @@ ComponentUnpacker::Error DeltaUpdateOpPatch::DoParseArguments( return ComponentUnpacker::kNone; } -void DeltaUpdateOpPatch::DoRun(const ComponentUnpacker::Callback& callback) { - callback_ = callback; - if (!InProcess()) { - content::BrowserThread::PostTask( - content::BrowserThread::IO, - FROM_HERE, - base::Bind(&DeltaUpdateOpPatchHost::StartProcess, - host_, - base::Passed(strategy_->GetPatchMessage(input_abs_path_, - patch_abs_path_, - output_abs_path_)))); - return; - } - const int result = strategy_->Patch(input_abs_path_, - patch_abs_path_, - output_abs_path_); - if (result == strategy_->GetSuccessCode()) - DonePatching(ComponentUnpacker::kNone, 0); - else - DonePatching(ComponentUnpacker::kDeltaOperationFailure, result); -} - -void DeltaUpdateOpPatch::DonePatching(ComponentUnpacker::Error error, - int error_code) { - host_ = NULL; - if (error != ComponentUnpacker::kNone) { - error_code += strategy_->GetErrorOffset(); - } - callback_.Run(error, error_code); - // The callback is no longer needed - it is best to release it in case it - // contains a reference to this object. - callback_.Reset(); +ComponentUnpacker::Error DeltaUpdateOpPatchCourgette::DoRun( + ComponentPatcher* patcher, + int* error) { + *error = 0; + return patcher->Patch(ComponentPatcher::kPatchTypeCourgette, + input_abs_path_, + patch_abs_path_, + output_abs_path_, + error); } } // namespace component_updater diff --git a/chrome/browser/component_updater/component_patcher_operation.h b/chrome/browser/component_updater/component_patcher_operation.h index 91c3a16e6b0d55..c9bc0b1690c3d6 100644 --- a/chrome/browser/component_updater/component_patcher_operation.h +++ b/chrome/browser/component_updater/component_patcher_operation.h @@ -6,15 +6,10 @@ #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_ #include - #include "base/basictypes.h" -#include "base/callback.h" #include "base/compiler_specific.h" #include "base/files/file_path.h" -#include "base/memory/ref_counted.h" -#include "chrome/browser/component_updater/component_patcher.h" #include "chrome/browser/component_updater/component_unpacker.h" -#include "content/public/browser/utility_process_host_client.h" namespace base { class DictionaryValue; @@ -23,56 +18,44 @@ class DictionaryValue; namespace component_updater { class ComponentInstaller; +class ComponentPatcher; -class DeltaUpdateOp : public base::RefCountedThreadSafe { +class DeltaUpdateOp { public: - DeltaUpdateOp(); - // Parses, runs, and verifies the operation. Calls |callback| with the - // result of the operation. The callback is called using |task_runner|. - void Run(const base::DictionaryValue* command_args, - const base::FilePath& input_dir, - const base::FilePath& unpack_dir, - ComponentInstaller* installer, - bool in_process, - const ComponentUnpacker::Callback& callback, - scoped_refptr task_runner); - - protected: + DeltaUpdateOp(); virtual ~DeltaUpdateOp(); - bool InProcess(); + // Parses, runs, and verifies the operation, returning an error code if an + // error is encountered, and DELTA_OK otherwise. In case of errors, + // extended error information can be returned in the |error| parameter. + ComponentUnpacker::Error Run(base::DictionaryValue* command_args, + const base::FilePath& input_dir, + const base::FilePath& unpack_dir, + ComponentPatcher* patcher, + ComponentInstaller* installer, + int* error); + protected: std::string output_sha256_; base::FilePath output_abs_path_; private: - friend class base::RefCountedThreadSafe; - - ComponentUnpacker::Error CheckHash(); // Subclasses must override DoParseArguments to parse operation-specific // arguments. DoParseArguments returns DELTA_OK on success; any other code // represents failure. virtual ComponentUnpacker::Error DoParseArguments( - const base::DictionaryValue* command_args, + base::DictionaryValue* command_args, const base::FilePath& input_dir, ComponentInstaller* installer) = 0; // Subclasses must override DoRun to actually perform the patching operation. - // They must call the provided callback when they have completed their - // operations. In practice, the provided callback is always for "DoneRunning". - virtual void DoRun(const ComponentUnpacker::Callback& callback) = 0; - - // Callback given to subclasses for when they complete their operation. - // Validates the output, and posts a task to the patching operation's - // callback. - void DoneRunning(ComponentUnpacker::Error error, int extended_error); - - bool in_process_; - ComponentUnpacker::Callback callback_; - scoped_refptr task_runner_; + // DoRun returns DELTA_OK on success; any other code represents failure. + // Additional error information can be returned in the |error| parameter. + virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, + int* error) = 0; DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOp); }; @@ -85,15 +68,14 @@ class DeltaUpdateOpCopy : public DeltaUpdateOp { DeltaUpdateOpCopy(); private: - virtual ~DeltaUpdateOpCopy(); - // Overrides of DeltaUpdateOp. virtual ComponentUnpacker::Error DoParseArguments( - const base::DictionaryValue* command_args, + base::DictionaryValue* command_args, const base::FilePath& input_dir, ComponentInstaller* installer) OVERRIDE; - virtual void DoRun(const ComponentUnpacker::Callback& callback) OVERRIDE; + virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, + int* error) OVERRIDE; base::FilePath input_abs_path_; @@ -109,101 +91,68 @@ class DeltaUpdateOpCreate : public DeltaUpdateOp { DeltaUpdateOpCreate(); private: - virtual ~DeltaUpdateOpCreate(); - // Overrides of DeltaUpdateOp. virtual ComponentUnpacker::Error DoParseArguments( - const base::DictionaryValue* command_args, + base::DictionaryValue* command_args, const base::FilePath& input_dir, ComponentInstaller* installer) OVERRIDE; - virtual void DoRun(const ComponentUnpacker::Callback& callback) OVERRIDE; + virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, + int* error) OVERRIDE; base::FilePath patch_abs_path_; DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate); }; -class DeltaUpdateOpPatchStrategy { - public: - virtual ~DeltaUpdateOpPatchStrategy(); - - // Returns an integer to add to error codes to disambiguate their source. - virtual int GetErrorOffset() const = 0; - - // Returns the "error code" that is expected in the successful install case. - virtual int GetSuccessCode() const = 0; - - // Returns an IPC message that will start patching if it is sent to a - // UtilityProcessClient. - virtual scoped_ptr GetPatchMessage( - base::FilePath input_abs_path, - base::FilePath patch_abs_path, - base::FilePath output_abs_path) = 0; - - // Does the actual patching operation, and returns an error code. - virtual int Patch(base::FilePath input_abs_path, - base::FilePath patch_abs_path, - base::FilePath output_abs_path) = 0; -}; - -class DeltaUpdateOpPatch; - -class DeltaUpdateOpPatchHost : public content::UtilityProcessHostClient { +// A 'bsdiff' operation takes an existing file on disk, and a bsdiff- +// format patch file provided in the delta update package, and runs bsdiff +// to construct an output file in the unpacking directory. +class DeltaUpdateOpPatchBsdiff : public DeltaUpdateOp { public: - explicit DeltaUpdateOpPatchHost(scoped_refptr patcher); - - void StartProcess(scoped_ptr message); + DeltaUpdateOpPatchBsdiff(); private: - virtual ~DeltaUpdateOpPatchHost(); - - void OnPatchSucceeded(); - - void OnPatchFailed(int error_code); + // Overrides of DeltaUpdateOp. + virtual ComponentUnpacker::Error DoParseArguments( + base::DictionaryValue* command_args, + const base::FilePath& input_dir, + ComponentInstaller* installer) OVERRIDE; - // Overrides of content::UtilityProcessHostClient. - virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, + int* error) OVERRIDE; - virtual void OnProcessCrashed(int exit_code) OVERRIDE; + base::FilePath patch_abs_path_; + base::FilePath input_abs_path_; - scoped_refptr patcher_; + DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatchBsdiff); }; -// Both 'bsdiff' and 'courgette' operations take an existing file on disk, -// and a bsdiff- or Courgette-format patch file provided in the delta update -// package, and run bsdiff or Courgette to construct an output file in the -// unpacking directory. -class DeltaUpdateOpPatch : public DeltaUpdateOp { +// A 'courgette' operation takes an existing file on disk, and a Courgette- +// format patch file provided in the delta update package, and runs Courgette +// to construct an output file in the unpacking directory. +class DeltaUpdateOpPatchCourgette : public DeltaUpdateOp { public: - explicit DeltaUpdateOpPatch(scoped_ptr strategy); - - void DonePatching(ComponentUnpacker::Error error, int error_code); + DeltaUpdateOpPatchCourgette(); private: - virtual ~DeltaUpdateOpPatch(); - // Overrides of DeltaUpdateOp. virtual ComponentUnpacker::Error DoParseArguments( - const base::DictionaryValue* command_args, + base::DictionaryValue* command_args, const base::FilePath& input_dir, ComponentInstaller* installer) OVERRIDE; - virtual void DoRun(const ComponentUnpacker::Callback& callback) OVERRIDE; + virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, + int* error) OVERRIDE; - ComponentUnpacker::Callback callback_; base::FilePath patch_abs_path_; base::FilePath input_abs_path_; - scoped_ptr strategy_; - scoped_refptr host_; - DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatch); + DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatchCourgette); }; -// Factory functions to create DeltaUpdateOp instances. -DeltaUpdateOp* CreateDeltaUpdateOp(const base::DictionaryValue& command); - -DeltaUpdateOp* CreateDeltaUpdateOp(const std::string& operation); +// Factory function to create DeltaUpdateOp instances. +DeltaUpdateOp* CreateDeltaUpdateOp(base::DictionaryValue* command); } // namespace component_updater diff --git a/chrome/browser/component_updater/component_patcher_win.cc b/chrome/browser/component_updater/component_patcher_win.cc new file mode 100644 index 00000000000000..ced84feee4c0e1 --- /dev/null +++ b/chrome/browser/component_updater/component_patcher_win.cc @@ -0,0 +1,118 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/component_updater/component_patcher_win.h" + +#include + +#include "base/base_paths.h" +#include "base/command_line.h" +#include "base/file_util.h" +#include "base/path_service.h" +#include "base/process/kill.h" +#include "base/process/launch.h" +#include "base/strings/string_util.h" +#include "base/strings/utf_string_conversions.h" +#include "base/win/scoped_handle.h" +#include "chrome/installer/util/util_constants.h" + +namespace component_updater { + +namespace { + +std::string PatchTypeToCommandLineSwitch( + ComponentPatcher::PatchType patch_type) { + if (patch_type == ComponentPatcher::kPatchTypeCourgette) + return std::string(installer::kCourgette); + else if (patch_type == ComponentPatcher::kPatchTypeBsdiff) + return std::string(installer::kBsdiff); + else + return std::string(); +} + +// Finds the path to the setup.exe. First, it looks for the program in the +// "installer" directory. If the program is not found there, it tries to find it +// in the directory where chrome.dll lives. Returns the path to the setup.exe, +// if the path exists, otherwise it returns an an empty path. +base::FilePath FindSetupProgram() { + base::FilePath exe_dir; + if (!PathService::Get(base::DIR_MODULE, &exe_dir)) + return base::FilePath(); + + const std::string installer_dir(base::UTF16ToASCII(installer::kInstallerDir)); + const std::string setup_exe(base::UTF16ToASCII(installer::kSetupExe)); + + base::FilePath setup_path = exe_dir; + setup_path = setup_path.AppendASCII(installer_dir); + setup_path = setup_path.AppendASCII(setup_exe); + if (base::PathExists(setup_path)) + return setup_path; + + setup_path = exe_dir; + setup_path = setup_path.AppendASCII(setup_exe); + if (base::PathExists(setup_path)) + return setup_path; + + return base::FilePath(); +} + +} // namespace + +// Applies the patch to the input file. Returns kNone if the patch was +// successfully applied, kDeltaOperationFailure if the patch operation +// encountered errors, and kDeltaPatchProcessFailure if there was an error +// when running the patch code out of process. In the error case, detailed error +// information could be returned in the error parameter. +ComponentUnpacker::Error ComponentPatcherWin::Patch( + PatchType patch_type, + const base::FilePath& input_file, + const base::FilePath& patch_file, + const base::FilePath& output_file, + int* error) { + *error = 0; + + const base::FilePath exe_path = FindSetupProgram(); + if (exe_path.empty()) + return ComponentUnpacker::kDeltaPatchProcessFailure; + + const std::string patch_type_str(PatchTypeToCommandLineSwitch(patch_type)); + + CommandLine cl(CommandLine::NO_PROGRAM); + cl.AppendSwitchASCII(installer::switches::kPatch, patch_type_str.c_str()); + cl.AppendSwitchPath(installer::switches::kInputFile, input_file); + cl.AppendSwitchPath(installer::switches::kPatchFile, patch_file); + cl.AppendSwitchPath(installer::switches::kOutputFile, output_file); + + // Create the child process in a job object. The job object prevents leaving + // child processes around when the parent process exits, either gracefully or + // accidentally. + base::win::ScopedHandle job(CreateJobObject(NULL, NULL)); + if (!job || + !base::SetJobObjectLimitFlags(job, JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE)) { + *error = GetLastError(); + return ComponentUnpacker::kDeltaPatchProcessFailure; + } + + base::LaunchOptions launch_options; + launch_options.wait = true; + launch_options.job_handle = job; + launch_options.start_hidden = true; + CommandLine setup_path(exe_path); + setup_path.AppendArguments(cl, false); + + // |ph| is closed by WaitForExitCode. + base::ProcessHandle ph = base::kNullProcessHandle; + int exit_code = 0; + if (!base::LaunchProcess(setup_path, launch_options, &ph) || + !base::WaitForExitCode(ph, &exit_code)) { + *error = GetLastError(); + return ComponentUnpacker::kDeltaPatchProcessFailure; + } + + *error = exit_code; + return *error ? ComponentUnpacker::kDeltaOperationFailure : + ComponentUnpacker::kNone; +} + +} // namespace component_updater diff --git a/chrome/browser/component_updater/component_patcher_win.h b/chrome/browser/component_updater/component_patcher_win.h new file mode 100644 index 00000000000000..5301cb5cdb3af8 --- /dev/null +++ b/chrome/browser/component_updater/component_patcher_win.h @@ -0,0 +1,28 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_WIN_H_ +#define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_WIN_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "chrome/browser/component_updater/component_patcher.h" + +namespace component_updater { + +class ComponentPatcherWin : public ComponentPatcher { + public: + ComponentPatcherWin() {} + virtual ComponentUnpacker::Error Patch(PatchType patch_type, + const base::FilePath& input_file, + const base::FilePath& patch_file, + const base::FilePath& output_file, + int* error) OVERRIDE; + private: + DISALLOW_COPY_AND_ASSIGN(ComponentPatcherWin); +}; + +} // namespace component_updater + +#endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_WIN_H_ diff --git a/chrome/browser/component_updater/component_unpacker.cc b/chrome/browser/component_updater/component_unpacker.cc index f179262ea2987f..4134b3e1beae9e 100644 --- a/chrome/browser/component_updater/component_unpacker.cc +++ b/chrome/browser/component_updater/component_unpacker.cc @@ -98,17 +98,18 @@ ComponentUnpacker::ComponentUnpacker( const std::vector& pk_hash, const base::FilePath& path, const std::string& fingerprint, + ComponentPatcher* patcher, ComponentInstaller* installer, - bool in_process, scoped_refptr task_runner) : pk_hash_(pk_hash), path_(path), is_delta_(false), fingerprint_(fingerprint), + patcher_(patcher), installer_(installer), - in_process_(in_process), error_(kNone), extended_error_(0), + ptr_factory_(this), task_runner_(task_runner) { } @@ -136,7 +137,8 @@ bool ComponentUnpacker::UnpackInternal() { return Verify() && Unzip() && BeginPatching(); } -void ComponentUnpacker::Unpack(const Callback& callback) { +void ComponentUnpacker::Unpack( + const base::Callback& callback) { callback_ = callback; if (!UnpackInternal()) Finish(); @@ -200,23 +202,20 @@ bool ComponentUnpacker::BeginPatching() { error_ = kUnzipPathError; return false; } - patcher_ = new ComponentPatcher(unpack_diff_path_, - unpack_path_, - installer_, - in_process_, - task_runner_); task_runner_->PostTask( - FROM_HERE, - base::Bind(&ComponentPatcher::Start, - patcher_, - base::Bind(&ComponentUnpacker::EndPatching, - scoped_refptr(this)))); + FROM_HERE, base::Bind(&DifferentialUpdatePatch, + unpack_diff_path_, + unpack_path_, + patcher_, + installer_, + base::Bind(&ComponentUnpacker::EndPatching, + GetWeakPtr()))); } else { - task_runner_->PostTask(FROM_HERE, - base::Bind(&ComponentUnpacker::EndPatching, - scoped_refptr(this), - kNone, - 0)); + task_runner_->PostTask( + FROM_HERE, base::Bind(&ComponentUnpacker::EndPatching, + GetWeakPtr(), + kNone, + 0)); } return true; } @@ -224,7 +223,6 @@ bool ComponentUnpacker::BeginPatching() { void ComponentUnpacker::EndPatching(Error error, int extended_error) { error_ = error; extended_error_ = extended_error; - patcher_ = NULL; if (error_ != kNone) { Finish(); return; @@ -269,6 +267,10 @@ void ComponentUnpacker::Finish() { callback_.Run(error_, extended_error_); } +base::WeakPtr ComponentUnpacker::GetWeakPtr() { + return ptr_factory_.GetWeakPtr(); +} + ComponentUnpacker::~ComponentUnpacker() { } diff --git a/chrome/browser/component_updater/component_unpacker.h b/chrome/browser/component_updater/component_unpacker.h index ffd69dd9c4adf2..ce722807d8e38d 100644 --- a/chrome/browser/component_updater/component_unpacker.h +++ b/chrome/browser/component_updater/component_unpacker.h @@ -12,8 +12,8 @@ #include "base/callback.h" #include "base/files/file_path.h" #include "base/json/json_file_value_serializer.h" -#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" #include "base/sequenced_task_runner.h" namespace component_updater { @@ -63,7 +63,7 @@ scoped_ptr ReadManifest( // // In both cases, if there is an error at any point, the remaining steps will // be skipped and Finish will be called. -class ComponentUnpacker : public base::RefCountedThreadSafe { +class ComponentUnpacker { public: // Possible error conditions. // Add only to the bottom of this enum; the order must be kept stable. @@ -88,27 +88,24 @@ class ComponentUnpacker : public base::RefCountedThreadSafe { kFingerprintWriteFailed, }; - typedef base::Callback Callback; - // Constructs an unpacker for a specific component unpacking operation. // |pk_hash| is the expected/ public key SHA256 hash. |path| is the current // location of the CRX. ComponentUnpacker(const std::vector& pk_hash, const base::FilePath& path, const std::string& fingerprint, + ComponentPatcher* patcher, ComponentInstaller* installer, - bool in_process, scoped_refptr task_runner); + virtual ~ComponentUnpacker(); + // Begins the actual unpacking of the files. May invoke a patcher if the // package is a differential update. Calls |callback| with the result. - void Unpack(const Callback& callback); + void Unpack( + const base::Callback& callback); private: - friend class base::RefCountedThreadSafe; - - virtual ~ComponentUnpacker(); - bool UnpackInternal(); // The first step of unpacking is to verify the file. Returns false if an @@ -138,18 +135,21 @@ class ComponentUnpacker : public base::RefCountedThreadSafe { // Finish is responsible for calling the callback provided in Start(). void Finish(); + // Returns a weak pointer to this object. + base::WeakPtr GetWeakPtr(); + std::vector pk_hash_; base::FilePath path_; base::FilePath unpack_path_; base::FilePath unpack_diff_path_; bool is_delta_; std::string fingerprint_; - scoped_refptr patcher_; + ComponentPatcher* patcher_; ComponentInstaller* installer_; - Callback callback_; - const bool in_process_; + base::Callback callback_; Error error_; int extended_error_; + base::WeakPtrFactory ptr_factory_; scoped_refptr task_runner_; DISALLOW_COPY_AND_ASSIGN(ComponentUnpacker); diff --git a/chrome/browser/component_updater/component_updater_configurator.cc b/chrome/browser/component_updater/component_updater_configurator.cc index 65b1f8599aafa2..87046bf1bfbf3a 100644 --- a/chrome/browser/component_updater/component_updater_configurator.cc +++ b/chrome/browser/component_updater/component_updater_configurator.cc @@ -17,6 +17,10 @@ #include "chrome/common/chrome_switches.h" #include "net/url_request/url_request_context_getter.h" +#if defined(OS_WIN) +#include "chrome/browser/component_updater/component_patcher_win.h" +#endif + namespace component_updater { namespace { @@ -49,10 +53,9 @@ const char kDefaultUrlSource[] = "https:" COMPONENT_UPDATER_SERVICE_ENDPOINT; // The url to send the pings to. const char kPingUrl[] = "http:" COMPONENT_UPDATER_SERVICE_ENDPOINT; +#if defined(OS_WIN) // Disables differential updates. const char kSwitchDisableDeltaUpdates[] = "disable-delta-updates"; - -#if defined(OS_WIN) // Disables background downloads. const char kSwitchDisableBackgroundDownloads[] = "disable-background-downloads"; #endif // defined(OS_WIN) @@ -106,6 +109,7 @@ class ChromeConfigurator : public ComponentUpdateService::Configurator { virtual size_t UrlSizeLimit() OVERRIDE; virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; virtual bool InProcess() OVERRIDE; + virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE; virtual bool DeltasEnabled() const OVERRIDE; virtual bool UseBackgroundDownloader() const OVERRIDE; @@ -132,12 +136,12 @@ ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, ",", &switch_values); fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate); pings_enabled_ = !HasSwitchValue(switch_values, kSwitchDisablePings); - deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates); - #if defined(OS_WIN) + deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates); background_downloads_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableBackgroundDownloads); #else + deltas_enabled_ = false; background_downloads_enabled_ = false; #endif @@ -198,6 +202,14 @@ bool ChromeConfigurator::InProcess() { return false; } +ComponentPatcher* ChromeConfigurator::CreateComponentPatcher() { +#if defined(OS_WIN) + return new ComponentPatcherWin(); +#else + return new ComponentPatcherCrossPlatform(); +#endif +} + bool ChromeConfigurator::DeltasEnabled() const { return deltas_enabled_; } diff --git a/chrome/browser/component_updater/component_updater_service.cc b/chrome/browser/component_updater/component_updater_service.cc index 903674a15409ab..fa04986f682951 100644 --- a/chrome/browser/component_updater/component_updater_service.cc +++ b/chrome/browser/component_updater/component_updater_service.cc @@ -21,6 +21,7 @@ #include "base/threading/sequenced_worker_pool.h" #include "base/timer/timer.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/component_updater/component_patcher.h" #include "chrome/browser/component_updater/component_unpacker.h" #include "chrome/browser/component_updater/component_updater_ping_manager.h" #include "chrome/browser/component_updater/component_updater_utils.h" @@ -251,11 +252,13 @@ class CrxUpdateService : public ComponentUpdateService { scoped_ptr config_; + scoped_ptr component_patcher_; + scoped_ptr update_checker_; scoped_ptr ping_manager_; - scoped_refptr unpacker_; + scoped_ptr unpacker_; scoped_ptr crx_downloader_; @@ -278,6 +281,7 @@ class CrxUpdateService : public ComponentUpdateService { CrxUpdateService::CrxUpdateService(ComponentUpdateService::Configurator* config) : config_(config), + component_patcher_(config->CreateComponentPatcher()), ping_manager_(new PingManager(config->PingUrl(), config->RequestContext())), blocking_task_runner_(BrowserThread::GetBlockingPool()-> @@ -852,12 +856,12 @@ void CrxUpdateService::DownloadComplete( void CrxUpdateService::Install(scoped_ptr context, const base::FilePath& crx_path) { // This function owns the file at |crx_path| and the |context| object. - unpacker_ = new ComponentUnpacker(context->pk_hash, - crx_path, - context->fingerprint, - context->installer, - config_->InProcess(), - blocking_task_runner_); + unpacker_.reset(new ComponentUnpacker(context->pk_hash, + crx_path, + context->fingerprint, + component_patcher_.get(), + context->installer, + blocking_task_runner_)); unpacker_->Unpack(base::Bind(&CrxUpdateService::EndUnpacking, base::Unretained(this), context->id, @@ -876,8 +880,6 @@ void CrxUpdateService::EndUnpacking(const std::string& component_id, base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this), component_id, error, extended_error), base::TimeDelta::FromMilliseconds(config_->StepDelay())); - // Reset the unpacker last, otherwise we free our own arguments. - unpacker_ = NULL; } // Installation has been completed. Adjust the component status and diff --git a/chrome/browser/component_updater/component_updater_service.h b/chrome/browser/component_updater/component_updater_service.h index bd9e37b4f0a420..fa59340a8b646a 100644 --- a/chrome/browser/component_updater/component_updater_service.h +++ b/chrome/browser/component_updater/component_updater_service.h @@ -30,6 +30,7 @@ class ResourceThrottle; namespace component_updater { class OnDemandTester; +class ComponentPatcher; // Component specific installers must derive from this class and implement // OnUpdateError() and Install(). A valid instance of this class must be @@ -177,6 +178,9 @@ class ComponentUpdateService { virtual net::URLRequestContextGetter* RequestContext() = 0; // True means that all ops are performed in this process. virtual bool InProcess() = 0; + // Creates a new ComponentPatcher in a platform-specific way. This is useful + // for dependency injection. + virtual ComponentPatcher* CreateComponentPatcher() = 0; // True means that this client can handle delta updates. virtual bool DeltasEnabled() const = 0; // True means that the background downloader can be used for downloading diff --git a/chrome/browser/component_updater/test/DEPS b/chrome/browser/component_updater/test/DEPS index e63018d2eb49f0..397b12e1f8c39b 100644 --- a/chrome/browser/component_updater/test/DEPS +++ b/chrome/browser/component_updater/test/DEPS @@ -1,4 +1,5 @@ include_rules = [ # For access to the ppapi test globals. "+ppapi/shared_impl", + "+courgette", ] diff --git a/chrome/browser/component_updater/test/component_patcher_mock.h b/chrome/browser/component_updater/test/component_patcher_mock.h new file mode 100644 index 00000000000000..90b066343ca909 --- /dev/null +++ b/chrome/browser/component_updater/test/component_patcher_mock.h @@ -0,0 +1,32 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_COMPONENT_UPDATER_TEST_COMPONENT_PATCHER_MOCK_H_ +#define CHROME_BROWSER_COMPONENT_UPDATER_TEST_COMPONENT_PATCHER_MOCK_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "chrome/browser/component_updater/component_patcher.h" + +namespace base { +class FilePath; +} + +namespace component_updater { + +class MockComponentPatcher : public ComponentPatcher { + public: + MockComponentPatcher() {} + virtual ComponentUnpacker::Error Patch(PatchType patch_type, + const base::FilePath& input_file, + const base::FilePath& patch_file, + const base::FilePath& output_file, + int* error) OVERRIDE; + private: + DISALLOW_COPY_AND_ASSIGN(MockComponentPatcher); +}; + +} // namespace component_updater + +#endif // CHROME_BROWSER_COMPONENT_UPDATER_TEST_COMPONENT_PATCHER_MOCK_H_ diff --git a/chrome/browser/component_updater/test/component_patcher_unittest.cc b/chrome/browser/component_updater/test/component_patcher_unittest.cc index 8769545f276048..3cc4f65610b8cb 100644 --- a/chrome/browser/component_updater/test/component_patcher_unittest.cc +++ b/chrome/browser/component_updater/test/component_patcher_unittest.cc @@ -2,55 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/bind.h" #include "base/compiler_specific.h" #include "base/file_util.h" #include "base/files/file_path.h" #include "base/files/scoped_temp_dir.h" -#include "base/message_loop/message_loop.h" #include "base/path_service.h" -#include "base/run_loop.h" #include "base/values.h" #include "chrome/browser/component_updater/component_patcher.h" #include "chrome/browser/component_updater/component_patcher_operation.h" #include "chrome/browser/component_updater/component_updater_service.h" +#include "chrome/browser/component_updater/test/component_patcher_mock.h" #include "chrome/browser/component_updater/test/component_patcher_unittest.h" #include "chrome/browser/component_updater/test/test_installer.h" #include "chrome/common/chrome_paths.h" -#include "content/public/browser/browser_thread.h" #include "courgette/courgette.h" #include "courgette/third_party/bsdiff.h" #include "testing/gtest/include/gtest/gtest.h" -namespace { - -class TestCallback { - public: - TestCallback(); - virtual ~TestCallback() {} - void Set(component_updater::ComponentUnpacker::Error error, int extra_code); - - int error_; - int extra_code_; - bool called_; - - private: - DISALLOW_COPY_AND_ASSIGN(TestCallback); -}; - -TestCallback::TestCallback() - : error_(-1), extra_code_(-1), called_(false) { -} - -void TestCallback::Set(component_updater::ComponentUnpacker::Error error, - int extra_code) { - error_ = error; - extra_code_ = extra_code; - called_ = true; -} - -} // namespace - namespace component_updater { namespace { @@ -67,14 +35,39 @@ ComponentPatcherOperationTest::ComponentPatcherOperationTest() { EXPECT_TRUE(unpack_dir_.CreateUniqueTempDir()); EXPECT_TRUE(input_dir_.CreateUniqueTempDir()); EXPECT_TRUE(installed_dir_.CreateUniqueTempDir()); + patcher_.reset(new MockComponentPatcher()); installer_.reset(new ReadOnlyTestInstaller(installed_dir_.path())); - task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread( - content::BrowserThread::FILE); } ComponentPatcherOperationTest::~ComponentPatcherOperationTest() { } +ComponentUnpacker::Error MockComponentPatcher::Patch( + PatchType patch_type, + const base::FilePath& input_file, + const base::FilePath& patch_file, + const base::FilePath& output_file, + int* error) { + *error = 0; + int exit_code; + if (patch_type == kPatchTypeCourgette) { + exit_code = courgette::ApplyEnsemblePatch(input_file.value().c_str(), + patch_file.value().c_str(), + output_file.value().c_str()); + if (exit_code == courgette::C_OK) + return ComponentUnpacker::kNone; + *error = exit_code + kCourgetteErrorOffset; + } else if (patch_type == kPatchTypeBsdiff) { + exit_code = courgette::ApplyBinaryPatch(input_file, + patch_file, + output_file); + if (exit_code == courgette::OK) + return ComponentUnpacker::kNone; + *error = exit_code + kBsdiffErrorOffset; + } + return ComponentUnpacker::kDeltaOperationFailure; +} + // Verify that a 'create' delta update operation works correctly. TEST_F(ComponentPatcherOperationTest, CheckCreateOperation) { EXPECT_TRUE(base::CopyFile( @@ -87,20 +80,17 @@ TEST_F(ComponentPatcherOperationTest, CheckCreateOperation) { command_args->SetString("op", "create"); command_args->SetString("patch", "binary_output.bin"); - TestCallback callback; - scoped_refptr op = new DeltaUpdateOpCreate(); - op->Run(command_args.get(), - input_dir_.path(), - unpack_dir_.path(), - NULL, - true, - base::Bind(&TestCallback::Set, base::Unretained(&callback)), - task_runner_); - base::RunLoop().RunUntilIdle(); - - EXPECT_EQ(true, callback.called_); - EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); - EXPECT_EQ(0, callback.extra_code_); + int error = 0; + scoped_ptr op(new DeltaUpdateOpCreate()); + ComponentUnpacker::Error result = op->Run(command_args.get(), + input_dir_.path(), + unpack_dir_.path(), + patcher_.get(), + NULL, + &error); + + EXPECT_EQ(ComponentUnpacker::kNone, result); + EXPECT_EQ(0, error); EXPECT_TRUE(base::ContentsEqual( unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), test_file("binary_output.bin"))); @@ -118,20 +108,16 @@ TEST_F(ComponentPatcherOperationTest, CheckCopyOperation) { command_args->SetString("op", "copy"); command_args->SetString("input", "binary_output.bin"); - TestCallback callback; - scoped_refptr op = new DeltaUpdateOpCopy(); - op->Run(command_args.get(), - input_dir_.path(), - unpack_dir_.path(), - installer_.get(), - true, - base::Bind(&TestCallback::Set, base::Unretained(&callback)), - task_runner_); - base::RunLoop().RunUntilIdle(); - - EXPECT_EQ(true, callback.called_); - EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); - EXPECT_EQ(0, callback.extra_code_); + int error = 0; + scoped_ptr op(new DeltaUpdateOpCopy()); + ComponentUnpacker::Error result = op->Run(command_args.get(), + input_dir_.path(), + unpack_dir_.path(), + patcher_.get(), + installer_.get(), + &error); + EXPECT_EQ(ComponentUnpacker::kNone, result); + EXPECT_EQ(0, error); EXPECT_TRUE(base::ContentsEqual( unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), test_file("binary_output.bin"))); @@ -154,20 +140,16 @@ TEST_F(ComponentPatcherOperationTest, CheckCourgetteOperation) { command_args->SetString("input", "binary_input.bin"); command_args->SetString("patch", "binary_courgette_patch.bin"); - TestCallback callback; - scoped_refptr op = CreateDeltaUpdateOp("courgette"); - op->Run(command_args.get(), - input_dir_.path(), - unpack_dir_.path(), - installer_.get(), - true, - base::Bind(&TestCallback::Set, base::Unretained(&callback)), - task_runner_); - base::RunLoop().RunUntilIdle(); - - EXPECT_EQ(true, callback.called_); - EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); - EXPECT_EQ(0, callback.extra_code_); + int error = 0; + scoped_ptr op(new DeltaUpdateOpPatchCourgette()); + ComponentUnpacker::Error result = op->Run(command_args.get(), + input_dir_.path(), + unpack_dir_.path(), + patcher_.get(), + installer_.get(), + &error); + EXPECT_EQ(ComponentUnpacker::kNone, result); + EXPECT_EQ(0, error); EXPECT_TRUE(base::ContentsEqual( unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), test_file("binary_output.bin"))); @@ -189,20 +171,16 @@ TEST_F(ComponentPatcherOperationTest, CheckBsdiffOperation) { command_args->SetString("input", "binary_input.bin"); command_args->SetString("patch", "binary_bsdiff_patch.bin"); - TestCallback callback; - scoped_refptr op = CreateDeltaUpdateOp("bsdiff"); - op->Run(command_args.get(), - input_dir_.path(), - unpack_dir_.path(), - installer_.get(), - true, - base::Bind(&TestCallback::Set, base::Unretained(&callback)), - task_runner_); - base::RunLoop().RunUntilIdle(); - - EXPECT_EQ(true, callback.called_); - EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); - EXPECT_EQ(0, callback.extra_code_); + int error = 0; + scoped_ptr op(new DeltaUpdateOpPatchBsdiff()); + ComponentUnpacker::Error result = op->Run(command_args.get(), + input_dir_.path(), + unpack_dir_.path(), + patcher_.get(), + installer_.get(), + &error); + EXPECT_EQ(ComponentUnpacker::kNone, result); + EXPECT_EQ(0, error); EXPECT_TRUE(base::ContentsEqual( unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), test_file("binary_output.bin"))); diff --git a/chrome/browser/component_updater/test/component_patcher_unittest.h b/chrome/browser/component_updater/test/component_patcher_unittest.h index de6dd24baeec42..ac30f35a95f42d 100644 --- a/chrome/browser/component_updater/test/component_patcher_unittest.h +++ b/chrome/browser/component_updater/test/component_patcher_unittest.h @@ -9,7 +9,6 @@ #include "base/files/scoped_temp_dir.h" #include "base/memory/scoped_ptr.h" #include "chrome/common/chrome_paths.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "courgette/courgette.h" #include "courgette/third_party/bsdiff.h" #include "testing/gtest/include/gtest/gtest.h" @@ -36,11 +35,8 @@ class ComponentPatcherOperationTest : public testing::Test { base::ScopedTempDir input_dir_; base::ScopedTempDir installed_dir_; base::ScopedTempDir unpack_dir_; + scoped_ptr patcher_; scoped_ptr installer_; - scoped_refptr task_runner_; - - private: - content::TestBrowserThreadBundle thread_bundle_; }; } // namespace component_updater diff --git a/chrome/browser/component_updater/test/component_updater_service_unittest.cc b/chrome/browser/component_updater/test/component_updater_service_unittest.cc index 4fa28f77b1ab2f..a08ad224493c62 100644 --- a/chrome/browser/component_updater/test/component_updater_service_unittest.cc +++ b/chrome/browser/component_updater/test/component_updater_service_unittest.cc @@ -108,6 +108,10 @@ net::URLRequestContextGetter* TestConfigurator::RequestContext() { // Don't use the utility process to run code out-of-process. bool TestConfigurator::InProcess() { return true; } +ComponentPatcher* TestConfigurator::CreateComponentPatcher() { + return new MockComponentPatcher(); +} + bool TestConfigurator::DeltasEnabled() const { return true; } diff --git a/chrome/browser/component_updater/test/component_updater_service_unittest.h b/chrome/browser/component_updater/test/component_updater_service_unittest.h index 23ae170e888b39..435510bc196673 100644 --- a/chrome/browser/component_updater/test/component_updater_service_unittest.h +++ b/chrome/browser/component_updater/test/component_updater_service_unittest.h @@ -17,6 +17,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "chrome/browser/component_updater/component_updater_service.h" +#include "chrome/browser/component_updater/test/component_patcher_mock.h" #include "chrome/browser/component_updater/test/url_request_post_interceptor.h" #include "content/public/test/test_browser_thread_bundle.h" #include "content/test/net/url_request_prepackaged_interceptor.h" @@ -90,6 +91,7 @@ class TestConfigurator : public ComponentUpdateService::Configurator { virtual size_t UrlSizeLimit() OVERRIDE; virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; virtual bool InProcess() OVERRIDE; + virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE; virtual bool DeltasEnabled() const OVERRIDE; virtual bool UseBackgroundDownloader() const OVERRIDE; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 99458e030b03b0..fd91384cfaca40 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -51,7 +51,6 @@ '../components/components.gyp:webdata_common', '../content/content.gyp:content_browser', '../content/content.gyp:content_common', - '../courgette/courgette.gyp:courgette_lib', '../crypto/crypto.gyp:crypto', '../google_apis/gcm/gcm.gyp:gcm', '../google_apis/google_apis.gyp:google_apis', @@ -493,6 +492,8 @@ 'browser/component_updater/component_patcher.h', 'browser/component_updater/component_patcher_operation.cc', 'browser/component_updater/component_patcher_operation.h', + 'browser/component_updater/component_patcher_win.cc', + 'browser/component_updater/component_patcher_win.h', 'browser/component_updater/component_updater_configurator.cc', 'browser/component_updater/component_updater_configurator.h', 'browser/component_updater/component_unpacker.cc', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index a3c454730abf44..f433afa254e92a 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -786,6 +786,7 @@ 'browser/chromeos/version_loader_unittest.cc', 'browser/command_updater_unittest.cc', 'browser/component_updater/test/component_installers_unittest.cc', + 'browser/component_updater/test/component_patcher_mock.h', 'browser/component_updater/test/component_patcher_unittest.cc', 'browser/component_updater/test/component_updater_ping_manager_unittest.cc', 'browser/component_updater/test/component_updater_service_unittest.cc', diff --git a/chrome/common/chrome_utility_messages.h b/chrome/common/chrome_utility_messages.h index e1d367d8ba65ea..2c2acbcb1b90f0 100644 --- a/chrome/common/chrome_utility_messages.h +++ b/chrome/common/chrome_utility_messages.h @@ -142,7 +142,7 @@ IPC_STRUCT_TRAITS_END() // Utility process messages: // These are messages from the browser to the utility process. -// Tells the utility process to unpack the given extension file in its +// Tell the utility process to unpack the given extension file in its // directory and verify that it is valid. IPC_MESSAGE_CONTROL4(ChromeUtilityMsg_UnpackExtension, base::FilePath /* extension_filename */, @@ -205,22 +205,6 @@ IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_GetPrinterCapsAndDefaults, IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults, std::string /* printer name */) -// Tell the utility process to patch the given |input_file| using |patch_file| -// and place the output in |output_file|. The patch should use the bsdiff -// algorithm (Courgette's version). -IPC_MESSAGE_CONTROL3(ChromeUtilityMsg_PatchFileBsdiff, - base::FilePath /* input_file */, - base::FilePath /* patch_file */, - base::FilePath /* output_file */) - -// Tell the utility process to patch the given |input_file| using |patch_file| -// and place the output in |output_file|. The patch should use the Courgette -// algorithm. -IPC_MESSAGE_CONTROL3(ChromeUtilityMsg_PatchFileCourgette, - base::FilePath /* input_file */, - base::FilePath /* patch_file */, - base::FilePath /* output_file */) - #if defined(OS_CHROMEOS) // Tell the utility process to create a zip file on the given list of files. IPC_MESSAGE_CONTROL3(ChromeUtilityMsg_CreateZipFile, @@ -395,13 +379,6 @@ IPC_MESSAGE_CONTROL2( printing::PrinterSemanticCapsAndDefaults) #endif -// Reply when a file has been patched successfully. -IPC_MESSAGE_CONTROL0(ChromeUtilityHostMsg_PatchFile_Succeeded) - -// Reply when patching a file failed. -IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_PatchFile_Failed, - int /* error code */) - // Reply when the utility process has failed to obtain the printer // capabilities and defaults. IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Failed, diff --git a/chrome/utility/DEPS b/chrome/utility/DEPS index 0a3ce2671f4b77..c3d40c31b2ee54 100644 --- a/chrome/utility/DEPS +++ b/chrome/utility/DEPS @@ -2,7 +2,6 @@ include_rules = [ "+content/public/child", "+content/public/utility", "+components/wifi", - "+courgette", "+extensions/common", # For generated headers. diff --git a/chrome/utility/chrome_content_utility_client.cc b/chrome/utility/chrome_content_utility_client.cc index 8b2a018ffa408c..f4569b2cc4d3af 100644 --- a/chrome/utility/chrome_content_utility_client.cc +++ b/chrome/utility/chrome_content_utility_client.cc @@ -31,8 +31,6 @@ #include "content/public/common/content_paths.h" #include "content/public/common/content_switches.h" #include "content/public/utility/utility_thread.h" -#include "courgette/courgette.h" -#include "courgette/third_party/bsdiff.h" #include "extensions/common/extension.h" #include "extensions/common/manifest.h" #include "media/base/media.h" @@ -373,10 +371,6 @@ bool ChromeContentUtilityClient::OnMessageReceived( OnGetPrinterCapsAndDefaults) IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults, OnGetPrinterSemanticCapsAndDefaults) - IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff, - OnPatchFileBsdiff) - IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileCourgette, - OnPatchFileCourgette) IPC_MESSAGE_HANDLER(ChromeUtilityMsg_StartupPing, OnStartupPing) IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, OnAnalyzeZipFileForDownloadProtection) @@ -807,43 +801,6 @@ void ChromeContentUtilityClient::OnGetPrinterSemanticCapsAndDefaults( ReleaseProcessIfNeeded(); } -void ChromeContentUtilityClient::OnPatchFileBsdiff( - const base::FilePath& input_file, - const base::FilePath& patch_file, - const base::FilePath& output_file) { - if (input_file.empty() || patch_file.empty() || output_file.empty()) { - Send(new ChromeUtilityHostMsg_PatchFile_Failed(-1)); - } else { - const int patch_status = courgette::ApplyBinaryPatch(input_file, - patch_file, - output_file); - if (patch_status != courgette::OK) - Send(new ChromeUtilityHostMsg_PatchFile_Failed(patch_status)); - else - Send(new ChromeUtilityHostMsg_PatchFile_Succeeded()); - } - ReleaseProcessIfNeeded(); -} - -void ChromeContentUtilityClient::OnPatchFileCourgette( - const base::FilePath& input_file, - const base::FilePath& patch_file, - const base::FilePath& output_file) { - if (input_file.empty() || patch_file.empty() || output_file.empty()) { - Send(new ChromeUtilityHostMsg_PatchFile_Failed(-1)); - } else { - const int patch_status = courgette::ApplyEnsemblePatch( - input_file.value().c_str(), - patch_file.value().c_str(), - output_file.value().c_str()); - if (patch_status != courgette::C_OK) - Send(new ChromeUtilityHostMsg_PatchFile_Failed(patch_status)); - else - Send(new ChromeUtilityHostMsg_PatchFile_Succeeded()); - } - ReleaseProcessIfNeeded(); -} - void ChromeContentUtilityClient::OnStartupPing() { Send(new ChromeUtilityHostMsg_ProcessStarted); // Don't release the process, we assume further messages are on the way. diff --git a/chrome/utility/chrome_content_utility_client.h b/chrome/utility/chrome_content_utility_client.h index ad7c9535fb5ffe..4f6b33f2932301 100644 --- a/chrome/utility/chrome_content_utility_client.h +++ b/chrome/utility/chrome_content_utility_client.h @@ -92,12 +92,6 @@ class ChromeContentUtilityClient : public content::ContentUtilityClient { void OnGetPrinterCapsAndDefaults(const std::string& printer_name); void OnGetPrinterSemanticCapsAndDefaults(const std::string& printer_name); - void OnPatchFileBsdiff(const base::FilePath& input_file, - const base::FilePath& patch_file, - const base::FilePath& output_file); - void OnPatchFileCourgette(const base::FilePath& input_file, - const base::FilePath& patch_file, - const base::FilePath& output_file); void OnStartupPing(); void OnAnalyzeZipFileForDownloadProtection( const IPC::PlatformFileForTransit& zip_file); diff --git a/content/content_utility.gypi b/content/content_utility.gypi index 2d2a7c02681a54..47be4e0e38357f 100644 --- a/content/content_utility.gypi +++ b/content/content_utility.gypi @@ -5,7 +5,6 @@ { 'dependencies': [ '../base/base.gyp:base', - '../courgette/courgette.gyp:courgette_lib', ], 'sources': [ 'public/utility/content_utility_client.cc',