#ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_
#define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_
#include <string>
#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;
}
namespace component_updater {
class ComponentInstaller;
class DeltaUpdateOp : public base::RefCountedThreadSafe<DeltaUpdateOp> {
public:
DeltaUpdateOp();
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<base::SequencedTaskRunner> task_runner);
protected:
virtual ~DeltaUpdateOp();
bool InProcess();
scoped_refptr<base::SequencedTaskRunner> GetTaskRunner();
std::string output_sha256_;
base::FilePath output_abs_path_;
private:
friend class base::RefCountedThreadSafe<DeltaUpdateOp>;
ComponentUnpacker::Error CheckHash();
virtual ComponentUnpacker::Error DoParseArguments(
const base::DictionaryValue* command_args,
const base::FilePath& input_dir,
ComponentInstaller* installer) = 0;
virtual void DoRun(const ComponentUnpacker::Callback& callback) = 0;
void DoneRunning(ComponentUnpacker::Error error, int extended_error);
bool in_process_;
ComponentUnpacker::Callback callback_;
scoped_refptr<base::SequencedTaskRunner> task_runner_;
DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOp);
};
class DeltaUpdateOpCopy : public DeltaUpdateOp {
public:
DeltaUpdateOpCopy();
private:
virtual ~DeltaUpdateOpCopy();
virtual ComponentUnpacker::Error DoParseArguments(
const base::DictionaryValue* command_args,
const base::FilePath& input_dir,
ComponentInstaller* installer) OVERRIDE;
virtual void DoRun(const ComponentUnpacker::Callback& callback) OVERRIDE;
base::FilePath input_abs_path_;
DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCopy);
};
class DeltaUpdateOpCreate : public DeltaUpdateOp {
public:
DeltaUpdateOpCreate();
private:
virtual ~DeltaUpdateOpCreate();
virtual ComponentUnpacker::Error DoParseArguments(
const base::DictionaryValue* command_args,
const base::FilePath& input_dir,
ComponentInstaller* installer) OVERRIDE;
virtual void DoRun(const ComponentUnpacker::Callback& callback) OVERRIDE;
base::FilePath patch_abs_path_;
DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate);
};
class DeltaUpdateOpPatchStrategy {
public:
virtual ~DeltaUpdateOpPatchStrategy();
virtual int GetErrorOffset() const = 0;
virtual int GetSuccessCode() const = 0;
virtual scoped_ptr<IPC::Message> GetPatchMessage(
base::FilePath input_abs_path,
base::FilePath patch_abs_path,
base::FilePath output_abs_path) = 0;
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 {
public:
DeltaUpdateOpPatchHost(scoped_refptr<DeltaUpdateOpPatch> patcher,
scoped_refptr<base::SequencedTaskRunner> task_runner);
void StartProcess(scoped_ptr<IPC::Message> message);
private:
virtual ~DeltaUpdateOpPatchHost();
void OnPatchSucceeded();
void OnPatchFailed(int error_code);
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void OnProcessCrashed(int exit_code) OVERRIDE;
scoped_refptr<DeltaUpdateOpPatch> patcher_;
scoped_refptr<base::SequencedTaskRunner> task_runner_;
};
class DeltaUpdateOpPatch : public DeltaUpdateOp {
public:
explicit DeltaUpdateOpPatch(scoped_ptr<DeltaUpdateOpPatchStrategy> strategy);
void DonePatching(ComponentUnpacker::Error error, int error_code);
private:
virtual ~DeltaUpdateOpPatch();
virtual ComponentUnpacker::Error DoParseArguments(
const base::DictionaryValue* command_args,
const base::FilePath& input_dir,
ComponentInstaller* installer) OVERRIDE;
virtual void DoRun(const ComponentUnpacker::Callback& callback) OVERRIDE;
ComponentUnpacker::Callback callback_;
base::FilePath patch_abs_path_;
base::FilePath input_abs_path_;
scoped_ptr<DeltaUpdateOpPatchStrategy> strategy_;
scoped_refptr<DeltaUpdateOpPatchHost> host_;
DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatch);
};
DeltaUpdateOp* CreateDeltaUpdateOp(const base::DictionaryValue& command);
DeltaUpdateOp* CreateDeltaUpdateOp(const std::string& operation);
}
#endif