Commit e260af75 authored by tommycli@chromium.org's avatar tommycli@chromium.org

Componentize component_updater: Decouple in-process DeltaUpdateOp from out-of-process version.

The in-process DeltaUpdateOps don't require content/ and can be eventually used on iOS, whereas the out-of-process version needs to stay in chrome/.

Part 1d in design doc here: https://docs.google.com/document/d/1F76yNZCnPnGzgNXhI-sCFKlXulwx_s_OKTGbJS5NhbA/edit?usp=sharing

BUG=371463

Review URL: https://codereview.chromium.org/420503002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287484 0039d316-1c4b-4281-b951-d872f2087c98
parent bf322e97
...@@ -44,12 +44,12 @@ ComponentPatcher::ComponentPatcher( ...@@ -44,12 +44,12 @@ ComponentPatcher::ComponentPatcher(
const base::FilePath& input_dir, const base::FilePath& input_dir,
const base::FilePath& unpack_dir, const base::FilePath& unpack_dir,
ComponentInstaller* installer, ComponentInstaller* installer,
bool in_process, scoped_refptr<OutOfProcessPatcher> out_of_process_patcher,
scoped_refptr<base::SequencedTaskRunner> task_runner) scoped_refptr<base::SequencedTaskRunner> task_runner)
: input_dir_(input_dir), : input_dir_(input_dir),
unpack_dir_(unpack_dir), unpack_dir_(unpack_dir),
installer_(installer), installer_(installer),
in_process_(in_process), out_of_process_patcher_(out_of_process_patcher),
task_runner_(task_runner) { task_runner_(task_runner) {
} }
...@@ -84,7 +84,13 @@ void ComponentPatcher::PatchNextFile() { ...@@ -84,7 +84,13 @@ void ComponentPatcher::PatchNextFile() {
} }
const base::DictionaryValue* command_args = const base::DictionaryValue* command_args =
static_cast<base::DictionaryValue*>(*next_command_); static_cast<base::DictionaryValue*>(*next_command_);
current_operation_ = CreateDeltaUpdateOp(*command_args);
std::string operation;
if (command_args->GetString(kOp, &operation)) {
current_operation_ =
CreateDeltaUpdateOp(operation, out_of_process_patcher_);
}
if (!current_operation_) { if (!current_operation_) {
DonePatching(ComponentUnpacker::kDeltaUnsupportedCommand, 0); DonePatching(ComponentUnpacker::kDeltaUnsupportedCommand, 0);
return; return;
...@@ -93,7 +99,6 @@ void ComponentPatcher::PatchNextFile() { ...@@ -93,7 +99,6 @@ void ComponentPatcher::PatchNextFile() {
input_dir_, input_dir_,
unpack_dir_, unpack_dir_,
installer_, installer_,
in_process_,
base::Bind(&ComponentPatcher::DonePatchingFile, base::Bind(&ComponentPatcher::DonePatchingFile,
scoped_refptr<ComponentPatcher>(this)), scoped_refptr<ComponentPatcher>(this)),
task_runner_); task_runner_);
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/component_updater/component_unpacker.h" #include "chrome/browser/component_updater/component_unpacker.h"
...@@ -40,6 +41,7 @@ namespace component_updater { ...@@ -40,6 +41,7 @@ namespace component_updater {
class ComponentInstaller; class ComponentInstaller;
class DeltaUpdateOp; class DeltaUpdateOp;
class OutOfProcessPatcher;
// The type of a patch file. // The type of a patch file.
enum PatchType { enum PatchType {
...@@ -59,7 +61,7 @@ class ComponentPatcher : public base::RefCountedThreadSafe<ComponentPatcher> { ...@@ -59,7 +61,7 @@ class ComponentPatcher : public base::RefCountedThreadSafe<ComponentPatcher> {
ComponentPatcher(const base::FilePath& input_dir, ComponentPatcher(const base::FilePath& input_dir,
const base::FilePath& unpack_dir, const base::FilePath& unpack_dir,
ComponentInstaller* installer, ComponentInstaller* installer,
bool in_process, scoped_refptr<OutOfProcessPatcher> out_of_process_patcher,
scoped_refptr<base::SequencedTaskRunner> task_runner); scoped_refptr<base::SequencedTaskRunner> task_runner);
// Starts patching files. This member function returns immediately, after // Starts patching files. This member function returns immediately, after
...@@ -84,7 +86,7 @@ class ComponentPatcher : public base::RefCountedThreadSafe<ComponentPatcher> { ...@@ -84,7 +86,7 @@ class ComponentPatcher : public base::RefCountedThreadSafe<ComponentPatcher> {
const base::FilePath input_dir_; const base::FilePath input_dir_;
const base::FilePath unpack_dir_; const base::FilePath unpack_dir_;
ComponentInstaller* const installer_; ComponentInstaller* const installer_;
const bool in_process_; scoped_refptr<OutOfProcessPatcher> out_of_process_patcher_;
ComponentUnpacker::Callback callback_; ComponentUnpacker::Callback callback_;
scoped_ptr<base::ListValue> commands_; scoped_ptr<base::ListValue> commands_;
base::ValueVector::const_iterator next_command_; base::ValueVector::const_iterator next_command_;
......
...@@ -12,9 +12,7 @@ ...@@ -12,9 +12,7 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "chrome/browser/component_updater/component_patcher.h"
#include "chrome/browser/component_updater/component_unpacker.h" #include "chrome/browser/component_updater/component_unpacker.h"
#include "content/public/browser/utility_process_host_client.h"
namespace base { namespace base {
class DictionaryValue; class DictionaryValue;
...@@ -22,6 +20,12 @@ class DictionaryValue; ...@@ -22,6 +20,12 @@ class DictionaryValue;
namespace component_updater { namespace component_updater {
extern const char kOp[];
extern const char kBsdiff[];
extern const char kCourgette[];
extern const char kInput[];
extern const char kPatch[];
class ComponentInstaller; class ComponentInstaller;
class DeltaUpdateOp : public base::RefCountedThreadSafe<DeltaUpdateOp> { class DeltaUpdateOp : public base::RefCountedThreadSafe<DeltaUpdateOp> {
...@@ -34,15 +38,12 @@ class DeltaUpdateOp : public base::RefCountedThreadSafe<DeltaUpdateOp> { ...@@ -34,15 +38,12 @@ class DeltaUpdateOp : public base::RefCountedThreadSafe<DeltaUpdateOp> {
const base::FilePath& input_dir, const base::FilePath& input_dir,
const base::FilePath& unpack_dir, const base::FilePath& unpack_dir,
ComponentInstaller* installer, ComponentInstaller* installer,
bool in_process,
const ComponentUnpacker::Callback& callback, const ComponentUnpacker::Callback& callback,
scoped_refptr<base::SequencedTaskRunner> task_runner); scoped_refptr<base::SequencedTaskRunner> task_runner);
protected: protected:
virtual ~DeltaUpdateOp(); virtual ~DeltaUpdateOp();
bool InProcess();
scoped_refptr<base::SequencedTaskRunner> GetTaskRunner(); scoped_refptr<base::SequencedTaskRunner> GetTaskRunner();
std::string output_sha256_; std::string output_sha256_;
...@@ -71,7 +72,6 @@ class DeltaUpdateOp : public base::RefCountedThreadSafe<DeltaUpdateOp> { ...@@ -71,7 +72,6 @@ class DeltaUpdateOp : public base::RefCountedThreadSafe<DeltaUpdateOp> {
// callback. // callback.
void DoneRunning(ComponentUnpacker::Error error, int extended_error); void DoneRunning(ComponentUnpacker::Error error, int extended_error);
bool in_process_;
ComponentUnpacker::Callback callback_; ComponentUnpacker::Callback callback_;
scoped_refptr<base::SequencedTaskRunner> task_runner_; scoped_refptr<base::SequencedTaskRunner> task_runner_;
...@@ -125,52 +125,21 @@ class DeltaUpdateOpCreate : public DeltaUpdateOp { ...@@ -125,52 +125,21 @@ class DeltaUpdateOpCreate : public DeltaUpdateOp {
DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate); DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate);
}; };
class DeltaUpdateOpPatchStrategy { // An interface an embedder may fulfill to enable out-of-process patching.
class OutOfProcessPatcher
: public base::RefCountedThreadSafe<OutOfProcessPatcher> {
public: public:
virtual ~DeltaUpdateOpPatchStrategy(); virtual void Patch(const std::string& operation,
scoped_refptr<base::SequencedTaskRunner> task_runner,
// Returns an integer to add to error codes to disambiguate their source. base::FilePath& input_abs_path,
virtual int GetErrorOffset() const = 0; base::FilePath& patch_abs_path,
base::FilePath& output_abs_path,
// Returns the "error code" that is expected in the successful install case. base::Callback<void(int result)> callback) = 0;
virtual int GetSuccessCode() const = 0;
// Returns an IPC message that will start patching if it is sent to a
// UtilityProcessClient.
virtual scoped_ptr<IPC::Message> 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 {
public:
DeltaUpdateOpPatchHost(scoped_refptr<DeltaUpdateOpPatch> patcher,
scoped_refptr<base::SequencedTaskRunner> task_runner);
void StartProcess(scoped_ptr<IPC::Message> message);
private: protected:
virtual ~DeltaUpdateOpPatchHost(); friend class base::RefCountedThreadSafe<OutOfProcessPatcher>;
void OnPatchSucceeded();
void OnPatchFailed(int error_code);
// Overrides of content::UtilityProcessHostClient.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void OnProcessCrashed(int exit_code) OVERRIDE;
scoped_refptr<DeltaUpdateOpPatch> patcher_; virtual ~OutOfProcessPatcher() {}
scoped_refptr<base::SequencedTaskRunner> task_runner_;
}; };
// Both 'bsdiff' and 'courgette' operations take an existing file on disk, // Both 'bsdiff' and 'courgette' operations take an existing file on disk,
...@@ -179,9 +148,9 @@ class DeltaUpdateOpPatchHost : public content::UtilityProcessHostClient { ...@@ -179,9 +148,9 @@ class DeltaUpdateOpPatchHost : public content::UtilityProcessHostClient {
// unpacking directory. // unpacking directory.
class DeltaUpdateOpPatch : public DeltaUpdateOp { class DeltaUpdateOpPatch : public DeltaUpdateOp {
public: public:
explicit DeltaUpdateOpPatch(scoped_ptr<DeltaUpdateOpPatchStrategy> strategy); // |out_of_process_patcher| may be NULL.
DeltaUpdateOpPatch(const std::string& operation,
void DonePatching(ComponentUnpacker::Error error, int error_code); scoped_refptr<OutOfProcessPatcher> out_of_process_patcher);
private: private:
virtual ~DeltaUpdateOpPatch(); virtual ~DeltaUpdateOpPatch();
...@@ -194,19 +163,21 @@ class DeltaUpdateOpPatch : public DeltaUpdateOp { ...@@ -194,19 +163,21 @@ class DeltaUpdateOpPatch : public DeltaUpdateOp {
virtual void DoRun(const ComponentUnpacker::Callback& callback) OVERRIDE; virtual void DoRun(const ComponentUnpacker::Callback& callback) OVERRIDE;
ComponentUnpacker::Callback callback_; // |success_code| is the code that indicates a successful patch.
// |result| is the code the patching operation returned.
void DonePatching(const ComponentUnpacker::Callback& callback, int result);
std::string operation_;
scoped_refptr<OutOfProcessPatcher> out_of_process_patcher_;
base::FilePath patch_abs_path_; base::FilePath patch_abs_path_;
base::FilePath input_abs_path_; base::FilePath input_abs_path_;
scoped_ptr<DeltaUpdateOpPatchStrategy> strategy_;
scoped_refptr<DeltaUpdateOpPatchHost> host_;
DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatch); DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatch);
}; };
// Factory functions to create DeltaUpdateOp instances. DeltaUpdateOp* CreateDeltaUpdateOp(
DeltaUpdateOp* CreateDeltaUpdateOp(const base::DictionaryValue& command); const std::string& operation,
scoped_refptr<OutOfProcessPatcher> out_of_process_patcher);
DeltaUpdateOp* CreateDeltaUpdateOp(const std::string& operation);
} // namespace component_updater } // namespace component_updater
......
// 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_operation_out_of_process.h"
#include <vector>
#include "base/bind.h"
#include "chrome/browser/component_updater/component_updater_service.h"
#include "chrome/common/chrome_utility_messages.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/utility_process_host.h"
#include "content/public/browser/utility_process_host_client.h"
#include "courgette/courgette.h"
#include "courgette/third_party/bsdiff.h"
#include "ipc/ipc_message_macros.h"
namespace component_updater {
class PatchHost : public content::UtilityProcessHostClient {
public:
PatchHost(base::Callback<void(int result)> callback,
scoped_refptr<base::SequencedTaskRunner> task_runner);
void StartProcess(scoped_ptr<IPC::Message> message);
private:
virtual ~PatchHost();
void OnPatchFinished(int result);
// Overrides of content::UtilityProcessHostClient.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void OnProcessCrashed(int exit_code) OVERRIDE;
base::Callback<void(int result)> callback_;
scoped_refptr<base::SequencedTaskRunner> task_runner_;
};
PatchHost::PatchHost(base::Callback<void(int result)> callback,
scoped_refptr<base::SequencedTaskRunner> task_runner)
: callback_(callback), task_runner_(task_runner) {
}
PatchHost::~PatchHost() {
}
void PatchHost::StartProcess(scoped_ptr<IPC::Message> 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.release());
}
bool PatchHost::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PatchHost, message)
IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_PatchFile_Finished, OnPatchFinished)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void PatchHost::OnPatchFinished(int result) {
task_runner_->PostTask(FROM_HERE, base::Bind(callback_, result));
task_runner_ = NULL;
}
void PatchHost::OnProcessCrashed(int exit_code) {
task_runner_->PostTask(FROM_HERE, base::Bind(callback_, -1));
task_runner_ = NULL;
}
ChromeOutOfProcessPatcher::ChromeOutOfProcessPatcher() {
}
ChromeOutOfProcessPatcher::~ChromeOutOfProcessPatcher() {
}
void ChromeOutOfProcessPatcher::Patch(
const std::string& operation,
scoped_refptr<base::SequencedTaskRunner> task_runner,
base::FilePath& input_abs_path,
base::FilePath& patch_abs_path,
base::FilePath& output_abs_path,
base::Callback<void(int result)> callback) {
host_ = new PatchHost(callback, task_runner);
scoped_ptr<IPC::Message> patch_message;
if (operation == kBsdiff) {
patch_message.reset(new ChromeUtilityMsg_PatchFileBsdiff(
input_abs_path, patch_abs_path, output_abs_path));
} else if (operation == kCourgette) {
patch_message.reset(new ChromeUtilityMsg_PatchFileCourgette(
input_abs_path, patch_abs_path, output_abs_path));
} else {
NOTREACHED();
}
content::BrowserThread::PostTask(
content::BrowserThread::IO,
FROM_HERE,
base::Bind(
&PatchHost::StartProcess, host_, base::Passed(&patch_message)));
}
} // namespace component_updater
// 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_OPERATION_OUT_OF_PROCESS_H_
#define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_OUT_OF_PROCESS_H_
#include <string>
#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "chrome/browser/component_updater/component_patcher_operation.h"
namespace component_updater {
class PatchHost;
// Implements the DeltaUpdateOpPatch out-of-process patching.
class ChromeOutOfProcessPatcher : public OutOfProcessPatcher {
public:
ChromeOutOfProcessPatcher();
// DeltaUpdateOpPatch::OutOfProcessPatcher implementation.
virtual void Patch(const std::string& operation,
scoped_refptr<base::SequencedTaskRunner> task_runner,
base::FilePath& input_abs_path,
base::FilePath& patch_abs_path,
base::FilePath& output_abs_path,
base::Callback<void(int result)> callback) OVERRIDE;
private:
virtual ~ChromeOutOfProcessPatcher();
scoped_refptr<PatchHost> host_;
DISALLOW_COPY_AND_ASSIGN(ChromeOutOfProcessPatcher);
};
} // namespace component_updater
#endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_OUT_OF_PROCESS_H_
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/component_updater/component_patcher.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/component_updater_service.h"
#include "crypto/secure_hash.h" #include "crypto/secure_hash.h"
#include "crypto/signature_verifier.h" #include "crypto/signature_verifier.h"
...@@ -101,14 +102,14 @@ ComponentUnpacker::ComponentUnpacker( ...@@ -101,14 +102,14 @@ ComponentUnpacker::ComponentUnpacker(
const base::FilePath& path, const base::FilePath& path,
const std::string& fingerprint, const std::string& fingerprint,
ComponentInstaller* installer, ComponentInstaller* installer,
bool in_process, scoped_refptr<OutOfProcessPatcher> out_of_process_patcher,
scoped_refptr<base::SequencedTaskRunner> task_runner) scoped_refptr<base::SequencedTaskRunner> task_runner)
: pk_hash_(pk_hash), : pk_hash_(pk_hash),
path_(path), path_(path),
is_delta_(false), is_delta_(false),
fingerprint_(fingerprint), fingerprint_(fingerprint),
installer_(installer), installer_(installer),
in_process_(in_process), out_of_process_patcher_(out_of_process_patcher),
error_(kNone), error_(kNone),
extended_error_(0), extended_error_(0),
task_runner_(task_runner) { task_runner_(task_runner) {
...@@ -211,7 +212,7 @@ bool ComponentUnpacker::BeginPatching() { ...@@ -211,7 +212,7 @@ bool ComponentUnpacker::BeginPatching() {
patcher_ = new ComponentPatcher(unpack_diff_path_, patcher_ = new ComponentPatcher(unpack_diff_path_,
unpack_path_, unpack_path_,
installer_, installer_,
in_process_, out_of_process_patcher_,
task_runner_); task_runner_);
task_runner_->PostTask( task_runner_->PostTask(
FROM_HERE, FROM_HERE,
......
...@@ -20,6 +20,7 @@ namespace component_updater { ...@@ -20,6 +20,7 @@ namespace component_updater {
class ComponentInstaller; class ComponentInstaller;
class ComponentPatcher; class ComponentPatcher;
class OutOfProcessPatcher;
// Deserializes the CRX manifest. The top level must be a dictionary. // Deserializes the CRX manifest. The top level must be a dictionary.
scoped_ptr<base::DictionaryValue> ReadManifest( scoped_ptr<base::DictionaryValue> ReadManifest(
...@@ -97,7 +98,7 @@ class ComponentUnpacker : public base::RefCountedThreadSafe<ComponentUnpacker> { ...@@ -97,7 +98,7 @@ class ComponentUnpacker : public base::RefCountedThreadSafe<ComponentUnpacker> {
const base::FilePath& path, const base::FilePath& path,
const std::string& fingerprint, const std::string& fingerprint,
ComponentInstaller* installer, ComponentInstaller* installer,
bool in_process, scoped_refptr<OutOfProcessPatcher> out_of_process_patcher,
scoped_refptr<base::SequencedTaskRunner> task_runner); scoped_refptr<base::SequencedTaskRunner> task_runner);
// Begins the actual unpacking of the files. May invoke a patcher if the // Begins the actual unpacking of the files. May invoke a patcher if the
...@@ -147,7 +148,7 @@ class ComponentUnpacker : public base::RefCountedThreadSafe<ComponentUnpacker> { ...@@ -147,7 +148,7 @@ class ComponentUnpacker : public base::RefCountedThreadSafe<ComponentUnpacker> {
scoped_refptr<ComponentPatcher> patcher_; scoped_refptr<ComponentPatcher> patcher_;
ComponentInstaller* installer_; ComponentInstaller* installer_;
Callback callback_; Callback callback_;
const bool in_process_; scoped_refptr<OutOfProcessPatcher> out_of_process_patcher_;
Error error_; Error error_;
int extended_error_; int extended_error_;
scoped_refptr<base::SequencedTaskRunner> task_runner_; scoped_refptr<base::SequencedTaskRunner> task_runner_;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/version.h" #include "base/version.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/component_updater/component_patcher_operation_out_of_process.h"
#include "chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.h" #include "chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.h"
#include "chrome/common/chrome_version_info.h" #include "chrome/common/chrome_version_info.h"
#include "components/component_updater/component_updater_switches.h" #include "components/component_updater/component_updater_switches.h"
...@@ -112,7 +113,8 @@ class ChromeConfigurator : public Configurator { ...@@ -112,7 +113,8 @@ class ChromeConfigurator : public Configurator {
virtual std::string ExtraRequestParams() const OVERRIDE; virtual std::string ExtraRequestParams() const OVERRIDE;
virtual size_t UrlSizeLimit() const OVERRIDE; virtual size_t UrlSizeLimit() const OVERRIDE;
virtual net::URLRequestContextGetter* RequestContext() const OVERRIDE; virtual net::URLRequestContextGetter* RequestContext() const OVERRIDE;
virtual bool InProcess() const OVERRIDE; virtual scoped_refptr<OutOfProcessPatcher> CreateOutOfProcessPatcher()
const OVERRIDE;
virtual bool DeltasEnabled() const OVERRIDE; virtual bool DeltasEnabled() const OVERRIDE;
virtual bool UseBackgroundDownloader() const OVERRIDE; virtual bool UseBackgroundDownloader() const OVERRIDE;
virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner()
...@@ -223,8 +225,9 @@ net::URLRequestContextGetter* ChromeConfigurator::RequestContext() const { ...@@ -223,8 +225,9 @@ net::URLRequestContextGetter* ChromeConfigurator::RequestContext() const {
return url_request_getter_; return url_request_getter_;
} }
bool ChromeConfigurator::InProcess() const { scoped_refptr<OutOfProcessPatcher>
return false; ChromeConfigurator::CreateOutOfProcessPatcher() const {
return make_scoped_refptr(new ChromeOutOfProcessPatcher);
} }
bool ChromeConfigurator::DeltasEnabled() const { bool ChromeConfigurator::DeltasEnabled() const {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <string> #include <string>
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
class GURL; class GURL;
...@@ -24,6 +25,8 @@ class URLRequestContextGetter; ...@@ -24,6 +25,8 @@ class URLRequestContextGetter;
namespace component_updater { namespace component_updater {
class OutOfProcessPatcher;
// Controls the component updater behavior. // Controls the component updater behavior.
class Configurator { class Configurator {
public: public:
...@@ -84,8 +87,10 @@ class Configurator { ...@@ -84,8 +87,10 @@ class Configurator {
// The source of contexts for all the url requests. // The source of contexts for all the url requests.
virtual net::URLRequestContextGetter* RequestContext() const = 0; virtual net::URLRequestContextGetter* RequestContext() const = 0;
// True means that all ops are performed in this process. // Returns a new out of process patcher. May be NULL for implementations
virtual bool InProcess() const = 0; // that patch in-process.
virtual scoped_refptr<OutOfProcessPatcher> CreateOutOfProcessPatcher()
const = 0;
// True means that this client can handle delta updates. // True means that this client can handle delta updates.
virtual bool DeltasEnabled() const = 0; virtual bool DeltasEnabled() const = 0;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/component_updater/component_patcher_operation.h"
#include "chrome/browser/component_updater/component_unpacker.h" #include "chrome/browser/component_updater/component_unpacker.h"
#include "chrome/browser/component_updater/component_updater_configurator.h" #include "chrome/browser/component_updater/component_updater_configurator.h"
#include "chrome/browser/component_updater/component_updater_ping_manager.h" #include "chrome/browser/component_updater/component_updater_ping_manager.h"
...@@ -874,7 +875,7 @@ void CrxUpdateService::Install(scoped_ptr<CRXContext> context, ...@@ -874,7 +875,7 @@ void CrxUpdateService::Install(scoped_ptr<CRXContext> context,
crx_path, crx_path,
context->fingerprint, context->fingerprint,
context->installer, context->installer,
config_->InProcess(), config_->CreateOutOfProcessPatcher(),
blocking_task_runner_); blocking_task_runner_);
unpacker_->Unpack(base::Bind(&CrxUpdateService::EndUnpacking, unpacker_->Unpack(base::Bind(&CrxUpdateService::EndUnpacking,
base::Unretained(this), base::Unretained(this),
......
...@@ -92,7 +92,6 @@ TEST_F(ComponentPatcherOperationTest, CheckCreateOperation) { ...@@ -92,7 +92,6 @@ TEST_F(ComponentPatcherOperationTest, CheckCreateOperation) {
input_dir_.path(), input_dir_.path(),
unpack_dir_.path(), unpack_dir_.path(),
NULL, NULL,
true,
base::Bind(&TestCallback::Set, base::Unretained(&callback)), base::Bind(&TestCallback::Set, base::Unretained(&callback)),
task_runner_); task_runner_);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -123,7 +122,6 @@ TEST_F(ComponentPatcherOperationTest, CheckCopyOperation) { ...@@ -123,7 +122,6 @@ TEST_F(ComponentPatcherOperationTest, CheckCopyOperation) {
input_dir_.path(), input_dir_.path(),
unpack_dir_.path(), unpack_dir_.path(),
installer_.get(), installer_.get(),
true,
base::Bind(&TestCallback::Set, base::Unretained(&callback)), base::Bind(&TestCallback::Set, base::Unretained(&callback)),
task_runner_); task_runner_);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -153,12 +151,12 @@ TEST_F(ComponentPatcherOperationTest, CheckCourgetteOperation) { ...@@ -153,12 +151,12 @@ TEST_F(ComponentPatcherOperationTest, CheckCourgetteOperation) {
command_args->SetString("patch", "binary_courgette_patch.bin"); command_args->SetString("patch", "binary_courgette_patch.bin");
TestCallback callback; TestCallback callback;
scoped_refptr<DeltaUpdateOp> op = CreateDeltaUpdateOp("courgette"); scoped_refptr<DeltaUpdateOp> op =
CreateDeltaUpdateOp("courgette", NULL /* out_of_process_patcher */);
op->Run(command_args.get(), op->Run(command_args.get(),
input_dir_.path(), input_dir_.path(),
unpack_dir_.path(), unpack_dir_.path(),
installer_.get(), installer_.get(),
true,
base::Bind(&TestCallback::Set, base::Unretained(&callback)), base::Bind(&TestCallback::Set, base::Unretained(&callback)),
task_runner_); task_runner_);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -188,12 +186,12 @@ TEST_F(ComponentPatcherOperationTest, CheckBsdiffOperation) { ...@@ -188,12 +186,12 @@ TEST_F(ComponentPatcherOperationTest, CheckBsdiffOperation) {
command_args->SetString("patch", "binary_bsdiff_patch.bin"); command_args->SetString("patch", "binary_bsdiff_patch.bin");
TestCallback callback; TestCallback callback;
scoped_refptr<DeltaUpdateOp> op = CreateDeltaUpdateOp("bsdiff"); scoped_refptr<DeltaUpdateOp> op =
CreateDeltaUpdateOp("bsdiff", NULL /* out_of_process_patcher */);
op->Run(command_args.get(), op->Run(command_args.get(),
input_dir_.path(), input_dir_.path(),
unpack_dir_.path(), unpack_dir_.path(),
installer_.get(), installer_.get(),
true,
base::Bind(&TestCallback::Set, base::Unretained(&callback)), base::Bind(&TestCallback::Set, base::Unretained(&callback)),
task_runner_); task_runner_);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
......
...@@ -22,11 +22,6 @@ class ReadOnlyTestInstaller; ...@@ -22,11 +22,6 @@ class ReadOnlyTestInstaller;
const char binary_output_hash[] = const char binary_output_hash[] =
"599aba6d15a7da390621ef1bacb66601ed6aed04dadc1f9b445dcfe31296142a"; "599aba6d15a7da390621ef1bacb66601ed6aed04dadc1f9b445dcfe31296142a";
// These constants are duplicated from chrome/installer/util/util_constants.h,
// to avoid introducing a dependency from the unit tests to the installer.
const int kCourgetteErrorOffset = 300;
const int kBsdiffErrorOffset = 600;
class ComponentPatcherOperationTest : public testing::Test { class ComponentPatcherOperationTest : public testing::Test {
public: public:
explicit ComponentPatcherOperationTest(); explicit ComponentPatcherOperationTest();
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/version.h" #include "base/version.h"
#include "chrome/browser/component_updater/component_patcher_operation.h"
#include "chrome/browser/component_updater/test/test_configurator.h" #include "chrome/browser/component_updater/test/test_configurator.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -96,9 +97,9 @@ net::URLRequestContextGetter* TestConfigurator::RequestContext() const { ...@@ -96,9 +97,9 @@ net::URLRequestContextGetter* TestConfigurator::RequestContext() const {
return context_.get(); return context_.get();
} }
// Don't use the utility process to run code out-of-process. scoped_refptr<OutOfProcessPatcher> TestConfigurator::CreateOutOfProcessPatcher()
bool TestConfigurator::InProcess() const { const {
return true; return NULL;
} }
bool TestConfigurator::DeltasEnabled() const { bool TestConfigurator::DeltasEnabled() const {
......
...@@ -44,7 +44,8 @@ class TestConfigurator : public Configurator { ...@@ -44,7 +44,8 @@ class TestConfigurator : public Configurator {
virtual std::string ExtraRequestParams() const OVERRIDE; virtual std::string ExtraRequestParams() const OVERRIDE;
virtual size_t UrlSizeLimit() const OVERRIDE; virtual size_t UrlSizeLimit() const OVERRIDE;
virtual net::URLRequestContextGetter* RequestContext() const OVERRIDE; virtual net::URLRequestContextGetter* RequestContext() const OVERRIDE;
virtual bool InProcess() const OVERRIDE; virtual scoped_refptr<OutOfProcessPatcher> CreateOutOfProcessPatcher()
const OVERRIDE;
virtual bool DeltasEnabled() const OVERRIDE; virtual bool DeltasEnabled() const OVERRIDE;
virtual bool UseBackgroundDownloader() const OVERRIDE; virtual bool UseBackgroundDownloader() const OVERRIDE;
virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner()
......
...@@ -273,6 +273,8 @@ ...@@ -273,6 +273,8 @@
'browser/component_updater/component_patcher.h', 'browser/component_updater/component_patcher.h',
'browser/component_updater/component_patcher_operation.cc', 'browser/component_updater/component_patcher_operation.cc',
'browser/component_updater/component_patcher_operation.h', 'browser/component_updater/component_patcher_operation.h',
'browser/component_updater/component_patcher_operation_out_of_process.cc',
'browser/component_updater/component_patcher_operation_out_of_process.h',
'browser/component_updater/component_updater_configurator.cc', 'browser/component_updater/component_updater_configurator.cc',
'browser/component_updater/component_updater_configurator.h', 'browser/component_updater/component_updater_configurator.h',
'browser/component_updater/component_unpacker.cc', 'browser/component_updater/component_unpacker.cc',
......
...@@ -108,12 +108,8 @@ IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_DecodeImage_Succeeded, ...@@ -108,12 +108,8 @@ IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_DecodeImage_Succeeded,
// Reply when an error occurred decoding the image. // Reply when an error occurred decoding the image.
IPC_MESSAGE_CONTROL0(ChromeUtilityHostMsg_DecodeImage_Failed) IPC_MESSAGE_CONTROL0(ChromeUtilityHostMsg_DecodeImage_Failed)
// Reply when a file has been patched successfully. // Reply when a file has been patched.
IPC_MESSAGE_CONTROL0(ChromeUtilityHostMsg_PatchFile_Succeeded) IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_PatchFile_Finished, int /* result */)
// Reply when patching a file failed.
IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_PatchFile_Failed,
int /* error code */)
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Reply when the utility process has succeeded in creating the zip file. // Reply when the utility process has succeeded in creating the zip file.
......
...@@ -251,15 +251,12 @@ void ChromeContentUtilityClient::OnPatchFileBsdiff( ...@@ -251,15 +251,12 @@ void ChromeContentUtilityClient::OnPatchFileBsdiff(
const base::FilePath& patch_file, const base::FilePath& patch_file,
const base::FilePath& output_file) { const base::FilePath& output_file) {
if (input_file.empty() || patch_file.empty() || output_file.empty()) { if (input_file.empty() || patch_file.empty() || output_file.empty()) {
Send(new ChromeUtilityHostMsg_PatchFile_Failed(-1)); Send(new ChromeUtilityHostMsg_PatchFile_Finished(-1));
} else { } else {
const int patch_status = courgette::ApplyBinaryPatch(input_file, const int patch_status = courgette::ApplyBinaryPatch(input_file,
patch_file, patch_file,
output_file); output_file);
if (patch_status != courgette::OK) Send(new ChromeUtilityHostMsg_PatchFile_Finished(patch_status));
Send(new ChromeUtilityHostMsg_PatchFile_Failed(patch_status));
else
Send(new ChromeUtilityHostMsg_PatchFile_Succeeded());
} }
ReleaseProcessIfNeeded(); ReleaseProcessIfNeeded();
} }
...@@ -269,16 +266,13 @@ void ChromeContentUtilityClient::OnPatchFileCourgette( ...@@ -269,16 +266,13 @@ void ChromeContentUtilityClient::OnPatchFileCourgette(
const base::FilePath& patch_file, const base::FilePath& patch_file,
const base::FilePath& output_file) { const base::FilePath& output_file) {
if (input_file.empty() || patch_file.empty() || output_file.empty()) { if (input_file.empty() || patch_file.empty() || output_file.empty()) {
Send(new ChromeUtilityHostMsg_PatchFile_Failed(-1)); Send(new ChromeUtilityHostMsg_PatchFile_Finished(-1));
} else { } else {
const int patch_status = courgette::ApplyEnsemblePatch( const int patch_status = courgette::ApplyEnsemblePatch(
input_file.value().c_str(), input_file.value().c_str(),
patch_file.value().c_str(), patch_file.value().c_str(),
output_file.value().c_str()); output_file.value().c_str());
if (patch_status != courgette::C_OK) Send(new ChromeUtilityHostMsg_PatchFile_Finished(patch_status));
Send(new ChromeUtilityHostMsg_PatchFile_Failed(patch_status));
else
Send(new ChromeUtilityHostMsg_PatchFile_Succeeded());
} }
ReleaseProcessIfNeeded(); ReleaseProcessIfNeeded();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment