| Index: chrome/browser/component_updater/component_patcher_operation.h
|
| diff --git a/chrome/browser/component_updater/component_patcher_operation.h b/chrome/browser/component_updater/component_patcher_operation.h
|
| index c9bc0b1690c3d62ccfb76499b3ddde8cf43ecf11..5153e604f56dc3d1dd168f4a685337b978706211 100644
|
| --- a/chrome/browser/component_updater/component_patcher_operation.h
|
| +++ b/chrome/browser/component_updater/component_patcher_operation.h
|
| @@ -7,9 +7,13 @@
|
|
|
| #include <string>
|
| #include "base/basictypes.h"
|
| +#include "base/callback.h"
|
| #include "base/compiler_specific.h"
|
| #include "base/files/file_path.h"
|
| +#include "base/memory/weak_ptr.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;
|
| @@ -18,27 +22,28 @@ class DictionaryValue;
|
| namespace component_updater {
|
|
|
| class ComponentInstaller;
|
| -class ComponentPatcher;
|
|
|
| class DeltaUpdateOp {
|
| public:
|
| -
|
| DeltaUpdateOp();
|
| virtual ~DeltaUpdateOp();
|
|
|
| - // 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);
|
| + // Parses, runs, and verifies the operation. Calls |callback| with the
|
| + // result of the operateration. The callback is called using |task_runner|.
|
| + void Run(base::DictionaryValue* command_args,
|
| + const base::FilePath& input_dir,
|
| + const base::FilePath& unpack_dir,
|
| + ComponentInstaller* installer,
|
| + bool in_process,
|
| + const base::Callback<void(ComponentUnpacker::Error, int)>& callback,
|
| + scoped_refptr<base::SequencedTaskRunner> task_runner);
|
|
|
| protected:
|
| + base::WeakPtr<DeltaUpdateOp> GetWeakPtr();
|
| +
|
| std::string output_sha256_;
|
| base::FilePath output_abs_path_;
|
| + bool in_process_;
|
|
|
| private:
|
| ComponentUnpacker::Error CheckHash();
|
| @@ -52,10 +57,19 @@ class DeltaUpdateOp {
|
| ComponentInstaller* installer) = 0;
|
|
|
| // Subclasses must override DoRun to actually perform the patching operation.
|
| - // 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;
|
| + // They must call the provided callback when they have completed their
|
| + // operations.
|
| + virtual void DoRun(
|
| + const base::Callback<void(ComponentUnpacker::Error, int)>& 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);
|
| +
|
| + base::Callback<void(ComponentUnpacker::Error, int)> callback_;
|
| + base::WeakPtrFactory<DeltaUpdateOp> ptr_factory_;
|
| + scoped_refptr<base::SequencedTaskRunner> task_runner_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOp);
|
| };
|
| @@ -74,8 +88,9 @@ class DeltaUpdateOpCopy : public DeltaUpdateOp {
|
| const base::FilePath& input_dir,
|
| ComponentInstaller* installer) OVERRIDE;
|
|
|
| - virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher,
|
| - int* error) OVERRIDE;
|
| + virtual void DoRun(
|
| + const base::Callback<void(ComponentUnpacker::Error, int)>& callback)
|
| + OVERRIDE;
|
|
|
| base::FilePath input_abs_path_;
|
|
|
| @@ -97,43 +112,44 @@ class DeltaUpdateOpCreate : public DeltaUpdateOp {
|
| const base::FilePath& input_dir,
|
| ComponentInstaller* installer) OVERRIDE;
|
|
|
| - virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher,
|
| - int* error) OVERRIDE;
|
| + virtual void DoRun(
|
| + const base::Callback<void(ComponentUnpacker::Error, int)>& callback)
|
| + OVERRIDE;
|
|
|
| base::FilePath patch_abs_path_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate);
|
| };
|
|
|
| -// 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 {
|
| +// 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 {
|
| public:
|
| - DeltaUpdateOpPatchBsdiff();
|
| + explicit DeltaUpdateOpPatch(component_updater::PatchType patch_type);
|
|
|
| - private:
|
| - // Overrides of DeltaUpdateOp.
|
| - virtual ComponentUnpacker::Error DoParseArguments(
|
| - base::DictionaryValue* command_args,
|
| - const base::FilePath& input_dir,
|
| - ComponentInstaller* installer) OVERRIDE;
|
| + virtual ~DeltaUpdateOpPatch();
|
|
|
| - virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher,
|
| - int* error) OVERRIDE;
|
| + void DonePatching(bool success, int error_code);
|
|
|
| - base::FilePath patch_abs_path_;
|
| - base::FilePath input_abs_path_;
|
| + // An inner class is used so that DeltaUpdateOpPatch does not need to derive
|
| + // from UtilityProcessHostClient (because it is refcounted).
|
| + class PatcherBridge : public content::UtilityProcessHostClient {
|
| + public:
|
| + explicit PatcherBridge(DeltaUpdateOpPatch* op);
|
| + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
|
| + virtual void OnProcessCrashed(int exit_code) OVERRIDE;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatchBsdiff);
|
| -};
|
| + private:
|
| + virtual ~PatcherBridge();
|
| + void OnPatchSucceeded();
|
| + void OnPatchFailed(int error_code);
|
| + DeltaUpdateOpPatch* op_;
|
| + DISALLOW_COPY_AND_ASSIGN(PatcherBridge);
|
| + };
|
|
|
| -// 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:
|
| - DeltaUpdateOpPatchCourgette();
|
| + base::Callback<void(ComponentUnpacker::Error, int)>callback_;
|
|
|
| private:
|
| // Overrides of DeltaUpdateOp.
|
| @@ -142,13 +158,18 @@ class DeltaUpdateOpPatchCourgette : public DeltaUpdateOp {
|
| const base::FilePath& input_dir,
|
| ComponentInstaller* installer) OVERRIDE;
|
|
|
| - virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher,
|
| - int* error) OVERRIDE;
|
| + virtual void DoRun(
|
| + const base::Callback<void(ComponentUnpacker::Error, int)>& callback)
|
| + OVERRIDE;
|
| +
|
| + void StartProcess();
|
|
|
| base::FilePath patch_abs_path_;
|
| base::FilePath input_abs_path_;
|
| + const component_updater::PatchType patch_type_;
|
| + scoped_refptr<PatcherBridge> bridge_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatchCourgette);
|
| + DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatch);
|
| };
|
|
|
| // Factory function to create DeltaUpdateOp instances.
|
|
|