summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbauerb <bauerb@chromium.org>2015-02-04 17:09:10 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-05 01:09:55 +0000
commit810e60f487982e8edc208b78b0b4b2b2a12a77a0 (patch)
treef76a8cb2498a8e32804fd0a9eb04703ed7a84127
parentabfbde8049ea4726e3c750a15aad66c5ab9f5093 (diff)
downloadchromium_src-810e60f487982e8edc208b78b0b4b2b2a12a77a0.zip
chromium_src-810e60f487982e8edc208b78b0b4b2b2a12a77a0.tar.gz
chromium_src-810e60f487982e8edc208b78b0b4b2b2a12a77a0.tar.bz2
Make ComponentInstaller refcounted.
Before this CL, component installers were leaked in almost all cases. If we allow uninstalling components (see https://codereview.chromium.org/879993005/), we need to fix those leaks. BUG=436459 Review URL: https://codereview.chromium.org/897873002 Cr-Commit-Position: refs/heads/master@{#314701}
-rw-r--r--chrome/browser/browser_process_impl.cc10
-rw-r--r--chrome/browser/browser_process_impl.h2
-rw-r--r--chrome/browser/component_updater/pepper_flash_component_installer.cc5
-rw-r--r--chrome/browser/component_updater/pnacl/pnacl_component_installer.cc18
-rw-r--r--chrome/browser/component_updater/pnacl/pnacl_component_installer.h6
-rw-r--r--chrome/browser/component_updater/recovery_component_installer.cc4
-rw-r--r--chrome/browser/component_updater/supervised_user_whitelist_installer.cc5
-rw-r--r--chrome/browser/component_updater/swiftshader_component_installer.cc5
-rw-r--r--chrome/browser/component_updater/test/component_updater_service_unittest.cc174
-rw-r--r--chrome/browser/component_updater/test/component_updater_service_unittest.h2
-rw-r--r--chrome/browser/component_updater/test/supervised_user_whitelist_installer_unittest.cc5
-rw-r--r--chrome/browser/net/crl_set_fetcher.h3
-rw-r--r--components/component_updater/component_updater_service.cc2
-rw-r--r--components/component_updater/default_component_installer.cc20
-rw-r--r--components/component_updater/default_component_installer.h3
-rw-r--r--components/update_client/component_patcher.cc3
-rw-r--r--components/update_client/component_patcher.h4
-rw-r--r--components/update_client/component_patcher_operation.cc21
-rw-r--r--components/update_client/component_patcher_operation.h27
-rw-r--r--components/update_client/component_unpacker.cc6
-rw-r--r--components/update_client/component_unpacker.h15
-rw-r--r--components/update_client/test/component_patcher_unittest.cc2
-rw-r--r--components/update_client/test/component_patcher_unittest.h2
-rw-r--r--components/update_client/test/test_installer.cc7
-rw-r--r--components/update_client/test/test_installer.h18
-rw-r--r--components/update_client/update_client.h9
26 files changed, 201 insertions, 177 deletions
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index c64b40e..6a719e8 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -878,7 +878,7 @@ BrowserProcessImpl::component_updater() {
}
CRLSetFetcher* BrowserProcessImpl::crl_set_fetcher() {
- if (!crl_set_fetcher_.get())
+ if (!crl_set_fetcher_)
crl_set_fetcher_ = new CRLSetFetcher();
return crl_set_fetcher_.get();
}
@@ -886,13 +886,13 @@ CRLSetFetcher* BrowserProcessImpl::crl_set_fetcher() {
component_updater::PnaclComponentInstaller*
BrowserProcessImpl::pnacl_component_installer() {
#if !defined(DISABLE_NACL)
- if (!pnacl_component_installer_.get()) {
- pnacl_component_installer_.reset(
- new component_updater::PnaclComponentInstaller());
+ if (!pnacl_component_installer_) {
+ pnacl_component_installer_ =
+ new component_updater::PnaclComponentInstaller();
}
return pnacl_component_installer_.get();
#else
- return NULL;
+ return nullptr;
#endif
}
diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h
index 3a7848c..95655db 100644
--- a/chrome/browser/browser_process_impl.h
+++ b/chrome/browser/browser_process_impl.h
@@ -277,7 +277,7 @@ class BrowserProcessImpl : public BrowserProcess,
scoped_refptr<CRLSetFetcher> crl_set_fetcher_;
#if !defined(DISABLE_NACL)
- scoped_ptr<component_updater::PnaclComponentInstaller>
+ scoped_refptr<component_updater::PnaclComponentInstaller>
pnacl_component_installer_;
#endif
diff --git a/chrome/browser/component_updater/pepper_flash_component_installer.cc b/chrome/browser/component_updater/pepper_flash_component_installer.cc
index fc9b092..e811a99 100644
--- a/chrome/browser/component_updater/pepper_flash_component_installer.cc
+++ b/chrome/browser/component_updater/pepper_flash_component_installer.cc
@@ -335,8 +335,7 @@ class PepperFlashComponentInstaller : public update_client::ComponentInstaller {
public:
explicit PepperFlashComponentInstaller(const Version& version);
- ~PepperFlashComponentInstaller() override {}
-
+ // ComponentInstaller implementation:
void OnUpdateError(int error) override;
bool Install(const base::DictionaryValue& manifest,
@@ -346,6 +345,8 @@ class PepperFlashComponentInstaller : public update_client::ComponentInstaller {
base::FilePath* installed_file) override;
private:
+ ~PepperFlashComponentInstaller() override {}
+
Version current_version_;
};
diff --git a/chrome/browser/component_updater/pnacl/pnacl_component_installer.cc b/chrome/browser/component_updater/pnacl/pnacl_component_installer.cc
index 6667dc8..785df6a 100644
--- a/chrome/browser/component_updater/pnacl/pnacl_component_installer.cc
+++ b/chrome/browser/component_updater/pnacl/pnacl_component_installer.cc
@@ -92,7 +92,7 @@ void OverrideDirPnaclComponent(const base::FilePath& base_path) {
PathService::Override(chrome::DIR_PNACL_COMPONENT, GetPlatformDir(base_path));
}
-bool GetLatestPnaclDirectory(PnaclComponentInstaller* pci,
+bool GetLatestPnaclDirectory(const scoped_refptr<PnaclComponentInstaller>& pci,
base::FilePath* latest_dir,
Version* latest_version,
std::vector<base::FilePath>* older_dirs) {
@@ -293,9 +293,10 @@ CrxComponent PnaclComponentInstaller::GetCrxComponent() {
namespace {
-void FinishPnaclUpdateRegistration(const Version& current_version,
- const std::string& current_fingerprint,
- PnaclComponentInstaller* pci) {
+void FinishPnaclUpdateRegistration(
+ const Version& current_version,
+ const std::string& current_fingerprint,
+ const scoped_refptr<PnaclComponentInstaller>& pci) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
pci->set_current_version(current_version);
CheckVersionCompatiblity(current_version);
@@ -312,7 +313,8 @@ void FinishPnaclUpdateRegistration(const Version& current_version,
// Check if there is an existing version on disk first to know when
// a hosted version is actually newer.
-void StartPnaclUpdateRegistration(PnaclComponentInstaller* pci) {
+void StartPnaclUpdateRegistration(
+ const scoped_refptr<PnaclComponentInstaller>& pci) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
base::FilePath path = pci->GetPnaclBaseDirectory();
if (!base::PathExists(path)) {
@@ -365,9 +367,9 @@ void StartPnaclUpdateRegistration(PnaclComponentInstaller* pci) {
void PnaclComponentInstaller::RegisterPnaclComponent(
ComponentUpdateService* cus) {
cus_ = cus;
- BrowserThread::PostTask(BrowserThread::FILE,
- FROM_HERE,
- base::Bind(&StartPnaclUpdateRegistration, this));
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&StartPnaclUpdateRegistration, make_scoped_refptr(this)));
}
} // namespace component_updater
diff --git a/chrome/browser/component_updater/pnacl/pnacl_component_installer.h b/chrome/browser/component_updater/pnacl/pnacl_component_installer.h
index a5683bb..b8e256d 100644
--- a/chrome/browser/component_updater/pnacl/pnacl_component_installer.h
+++ b/chrome/browser/component_updater/pnacl/pnacl_component_installer.h
@@ -41,8 +41,7 @@ class PnaclComponentInstaller : public update_client::ComponentInstaller {
public:
PnaclComponentInstaller();
- ~PnaclComponentInstaller() override;
-
+ // ComponentInstaller implementation:
void OnUpdateError(int error) override;
bool Install(const base::DictionaryValue& manifest,
@@ -74,9 +73,12 @@ class PnaclComponentInstaller : public update_client::ComponentInstaller {
ComponentUpdateService* cus() const { return cus_; }
private:
+ ~PnaclComponentInstaller() override;
+
base::Version current_version_;
std::string current_fingerprint_;
ComponentUpdateService* cus_;
+
DISALLOW_COPY_AND_ASSIGN(PnaclComponentInstaller);
};
diff --git a/chrome/browser/component_updater/recovery_component_installer.cc b/chrome/browser/component_updater/recovery_component_installer.cc
index 2173f05..696ab432 100644
--- a/chrome/browser/component_updater/recovery_component_installer.cc
+++ b/chrome/browser/component_updater/recovery_component_installer.cc
@@ -176,8 +176,8 @@ void ElevatedInstallRecoveryComponent(const base::FilePath& installer_path) {
class RecoveryComponentInstaller : public update_client::ComponentInstaller {
public:
RecoveryComponentInstaller(const Version& version, PrefService* prefs);
- ~RecoveryComponentInstaller() override {}
+ // ComponentInstaller implementation:
void OnUpdateError(int error) override;
bool Install(const base::DictionaryValue& manifest,
@@ -187,6 +187,8 @@ class RecoveryComponentInstaller : public update_client::ComponentInstaller {
base::FilePath* installed_file) override;
private:
+ ~RecoveryComponentInstaller() override {}
+
bool RunInstallCommand(const base::CommandLine& cmdline,
const base::FilePath& installer_folder) const;
diff --git a/chrome/browser/component_updater/supervised_user_whitelist_installer.cc b/chrome/browser/component_updater/supervised_user_whitelist_installer.cc
index 603242f..55b0860 100644
--- a/chrome/browser/component_updater/supervised_user_whitelist_installer.cc
+++ b/chrome/browser/component_updater/supervised_user_whitelist_installer.cc
@@ -139,10 +139,9 @@ void SupervisedUserWhitelistInstallerImpl::RegisterWhitelist(
scoped_ptr<ComponentInstallerTraits> traits(
new SupervisedUserWhitelistComponentInstallerTraits(crx_id, name,
callback));
- DefaultComponentInstaller* installer =
- new DefaultComponentInstaller(traits.Pass());
+ scoped_refptr<DefaultComponentInstaller> installer(
+ new DefaultComponentInstaller(traits.Pass()));
- // Takes ownership of |installer|.
installer->Register(cus_);
if (newly_added)
diff --git a/chrome/browser/component_updater/swiftshader_component_installer.cc b/chrome/browser/component_updater/swiftshader_component_installer.cc
index bea146a..917a3ca 100644
--- a/chrome/browser/component_updater/swiftshader_component_installer.cc
+++ b/chrome/browser/component_updater/swiftshader_component_installer.cc
@@ -100,8 +100,7 @@ class SwiftShaderComponentInstaller : public update_client::ComponentInstaller {
public:
explicit SwiftShaderComponentInstaller(const Version& version);
- ~SwiftShaderComponentInstaller() override {}
-
+ // ComponentInstaller implementation:
void OnUpdateError(int error) override;
bool Install(const base::DictionaryValue& manifest,
@@ -111,6 +110,8 @@ class SwiftShaderComponentInstaller : public update_client::ComponentInstaller {
base::FilePath* installed_file) override;
private:
+ ~SwiftShaderComponentInstaller() override {}
+
Version current_version_;
};
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 7957c74..9e65310 100644
--- a/chrome/browser/component_updater/test/component_updater_service_unittest.cc
+++ b/chrome/browser/component_updater/test/component_updater_service_unittest.cc
@@ -116,16 +116,23 @@ ComponentUpdateService::Status ComponentUpdaterTest::RegisterComponent(
CrxComponent* com,
TestComponents component,
const Version& version,
- TestInstaller* installer) {
- if (component == kTestComponent_abag) {
- com->name = "test_abag";
- com->pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash));
- } else if (component == kTestComponent_jebg) {
- com->name = "test_jebg";
- com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash));
- } else {
- com->name = "test_ihfo";
- com->pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash));
+ const scoped_refptr<TestInstaller>& installer) {
+ switch (component) {
+ case kTestComponent_abag: {
+ com->name = "test_abag";
+ com->pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash));
+ break;
+ }
+ case kTestComponent_jebg: {
+ com->name = "test_jebg";
+ com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash));
+ break;
+ }
+ case kTestComponent_ihfo: {
+ com->name = "test_ihfo";
+ com->pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash));
+ break;
+ }
}
com->version = version;
com->installer = installer;
@@ -190,20 +197,20 @@ TEST_F(ComponentUpdaterTest, CheckCrxSleep) {
EXPECT_TRUE(post_interceptor_->ExpectRequest(
new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
- TestInstaller installer;
+ scoped_refptr<TestInstaller> installer(new TestInstaller);
CrxComponent com;
component_updater()->AddObserver(&observer);
EXPECT_EQ(
ComponentUpdateService::kOk,
- RegisterComponent(&com, kTestComponent_abag, Version("1.1"), &installer));
+ RegisterComponent(&com, kTestComponent_abag, Version("1.1"), installer));
// We loop twice, but there are no updates so we expect two sleep messages.
test_configurator()->SetLoopCount(2);
component_updater()->Start();
RunThreads();
- EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
+ EXPECT_EQ(0, installer->error());
+ EXPECT_EQ(0, installer->install_count());
// Expect to see the two update check requests and no other requests,
// including pings.
@@ -248,8 +255,8 @@ TEST_F(ComponentUpdaterTest, CheckCrxSleep) {
component_updater()->Start();
RunThreads();
- EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
+ EXPECT_EQ(0, installer->error());
+ EXPECT_EQ(0, installer->install_count());
EXPECT_EQ(2, post_interceptor_->GetHitCount())
<< post_interceptor_->GetRequestsAsString();
@@ -335,21 +342,21 @@ TEST_F(ComponentUpdaterTest, InstallCrx) {
component_updater()->AddObserver(&observer);
- TestInstaller installer1;
+ scoped_refptr<TestInstaller> installer1(new TestInstaller);
CrxComponent com1;
- RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1);
- TestInstaller installer2;
+ RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), installer1);
+ scoped_refptr<TestInstaller> installer2(new TestInstaller);
CrxComponent com2;
- RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2);
+ RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), installer2);
test_configurator()->SetLoopCount(2);
component_updater()->Start();
RunThreads();
- EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
- EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
+ EXPECT_EQ(0, installer1->error());
+ EXPECT_EQ(1, installer1->install_count());
+ EXPECT_EQ(0, installer2->error());
+ EXPECT_EQ(0, installer2->install_count());
// Expect three request in total: two update checks and one ping.
EXPECT_EQ(3, post_interceptor_->GetHitCount())
@@ -440,9 +447,9 @@ TEST_F(ComponentUpdaterTest, ProdVersionCheck) {
GURL(expected_crx_url),
test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
- TestInstaller installer;
+ scoped_refptr<TestInstaller> installer(new TestInstaller);
CrxComponent com;
- RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer);
+ RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), installer);
test_configurator()->SetLoopCount(1);
component_updater()->Start();
@@ -457,8 +464,8 @@ TEST_F(ComponentUpdaterTest, ProdVersionCheck) {
// Expect no download to occur.
EXPECT_EQ(0, get_interceptor_->GetHitCount());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
+ EXPECT_EQ(0, installer->error());
+ EXPECT_EQ(0, installer->install_count());
component_updater()->Stop();
}
@@ -530,12 +537,12 @@ TEST_F(ComponentUpdaterTest, MAYBE_OnDemandUpdate) {
component_updater()->AddObserver(&observer);
- TestInstaller installer1;
+ scoped_refptr<TestInstaller> installer1(new TestInstaller);
CrxComponent com1;
- RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1);
- TestInstaller installer2;
+ RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), installer1);
+ scoped_refptr<TestInstaller> installer2(new TestInstaller);
CrxComponent com2;
- RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2);
+ RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), installer2);
// No update normally.
test_configurator()->SetLoopCount(1);
@@ -563,10 +570,10 @@ TEST_F(ComponentUpdaterTest, MAYBE_OnDemandUpdate) {
component_updater()->Start();
RunThreads();
- EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
- EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count());
+ EXPECT_EQ(0, installer1->error());
+ EXPECT_EQ(0, installer1->install_count());
+ EXPECT_EQ(0, installer2->error());
+ EXPECT_EQ(1, installer2->install_count());
EXPECT_EQ(2, post_interceptor_->GetHitCount())
<< post_interceptor_->GetRequestsAsString();
@@ -742,12 +749,12 @@ TEST_F(ComponentUpdaterTest, CheckReRegistration) {
component_updater()->AddObserver(&observer);
- TestInstaller installer1;
+ scoped_refptr<TestInstaller> installer1(new TestInstaller);
CrxComponent com1;
- RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1);
- TestInstaller installer2;
+ RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), installer1);
+ scoped_refptr<TestInstaller> installer2(new TestInstaller);
CrxComponent com2;
- RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2);
+ RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), installer2);
// Loop twice to issue two checks: (1) with original 0.9 version, update to
// 1.0, and do the second check (2) with the updated 1.0 version.
@@ -755,10 +762,10 @@ TEST_F(ComponentUpdaterTest, CheckReRegistration) {
component_updater()->Start();
RunThreads();
- EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
- EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
+ EXPECT_EQ(0, installer1->error());
+ EXPECT_EQ(1, installer1->install_count());
+ EXPECT_EQ(0, installer2->error());
+ EXPECT_EQ(0, installer2->install_count());
EXPECT_EQ(3, post_interceptor_->GetHitCount())
<< post_interceptor_->GetRequestsAsString();
@@ -810,10 +817,10 @@ TEST_F(ComponentUpdaterTest, CheckReRegistration) {
EXPECT_TRUE(post_interceptor_->ExpectRequest(
new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
- TestInstaller installer3;
+ scoped_refptr<TestInstaller> installer3(new TestInstaller);
EXPECT_EQ(ComponentUpdateService::kReplaced,
- RegisterComponent(
- &com1, kTestComponent_jebg, Version("2.2"), &installer3));
+ RegisterComponent(&com1, kTestComponent_jebg, Version("2.2"),
+ installer3));
// Loop once just to notice the check happening with the re-register version.
test_configurator()->SetLoopCount(1);
@@ -821,10 +828,10 @@ TEST_F(ComponentUpdaterTest, CheckReRegistration) {
RunThreads();
// We created a new installer, so the counts go back to 0.
- EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
+ EXPECT_EQ(0, installer3->error());
+ EXPECT_EQ(0, installer3->install_count());
+ EXPECT_EQ(0, installer2->error());
+ EXPECT_EQ(0, installer2->install_count());
// One update check and no additional pings are expected.
EXPECT_EQ(1, post_interceptor_->GetHitCount())
@@ -873,16 +880,16 @@ TEST_F(ComponentUpdaterTest, DifferentialUpdate) {
"ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"),
test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"));
- VersionedTestInstaller installer;
+ scoped_refptr<TestInstaller> installer(new VersionedTestInstaller);
CrxComponent com;
- RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer);
+ RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), installer);
test_configurator()->SetLoopCount(3);
component_updater()->Start();
RunThreads();
- EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
- EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
+ EXPECT_EQ(0, installer->error());
+ EXPECT_EQ(2, installer->install_count());
EXPECT_EQ(5, post_interceptor_->GetHitCount())
<< post_interceptor_->GetRequestsAsString();
@@ -962,17 +969,17 @@ TEST_F(ComponentUpdaterTest, MAYBE_DifferentialUpdateFails) {
GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"),
test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
- TestInstaller installer;
+ scoped_refptr<TestInstaller> installer(new TestInstaller);
CrxComponent com;
- RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer);
+ RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), installer);
test_configurator()->SetLoopCount(2);
component_updater()->Start();
RunThreads();
// A failed differential update does not count as a failed install.
- EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
- EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count());
+ EXPECT_EQ(0, installer->error());
+ EXPECT_EQ(1, installer->install_count());
EXPECT_EQ(3, post_interceptor_->GetHitCount())
<< post_interceptor_->GetRequestsAsString();
@@ -1013,14 +1020,17 @@ TEST_F(ComponentUpdaterTest, MAYBE_DifferentialUpdateFails) {
// Verify that a failed installation causes an install failure ping.
TEST_F(ComponentUpdaterTest, MAYBE_CheckFailedInstallPing) {
// This test installer reports installation failure.
- class : public TestInstaller {
+ class FailingTestInstaller : public TestInstaller {
bool Install(const base::DictionaryValue& manifest,
const base::FilePath& unpack_path) override {
++install_count_;
base::DeleteFile(unpack_path, true);
return false;
}
- } installer;
+ private:
+ ~FailingTestInstaller() override {}
+ };
+ scoped_refptr<FailingTestInstaller> installer(new FailingTestInstaller);
EXPECT_TRUE(post_interceptor_->ExpectRequest(
new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
@@ -1036,7 +1046,7 @@ TEST_F(ComponentUpdaterTest, MAYBE_CheckFailedInstallPing) {
// Loop twice to issue two checks: (1) with original 0.9 version
// and (2), which should retry with 0.9.
CrxComponent com;
- RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer);
+ RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), installer);
test_configurator()->SetLoopCount(2);
component_updater()->Start();
@@ -1087,8 +1097,8 @@ TEST_F(ComponentUpdaterTest, MAYBE_CheckFailedInstallPing) {
component_updater()->Start();
RunThreads();
- EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
- EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
+ EXPECT_EQ(0, installer->error());
+ EXPECT_EQ(2, installer->install_count());
EXPECT_EQ(1, post_interceptor_->GetHitCount())
<< post_interceptor_->GetRequestsAsString();
@@ -1136,17 +1146,17 @@ TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) {
GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"),
test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
- VersionedTestInstaller installer;
+ scoped_refptr<TestInstaller> installer(new VersionedTestInstaller);
CrxComponent com;
- RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer);
+ RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), installer);
test_configurator()->SetLoopCount(3);
component_updater()->Start();
RunThreads();
component_updater()->Stop();
- EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
- EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
+ EXPECT_EQ(0, installer->error());
+ EXPECT_EQ(2, installer->install_count());
EXPECT_EQ(5, post_interceptor_->GetHitCount())
<< post_interceptor_->GetRequestsAsString();
@@ -1249,12 +1259,12 @@ TEST_F(ComponentUpdaterTest, ResourceThrottleDeletedNoUpdate) {
EXPECT_TRUE(post_interceptor_->ExpectRequest(
new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
- TestInstaller installer;
+ scoped_refptr<TestInstaller> installer(new TestInstaller);
CrxComponent com;
component_updater()->AddObserver(&observer);
EXPECT_EQ(
ComponentUpdateService::kOk,
- RegisterComponent(&com, kTestComponent_abag, Version("1.1"), &installer));
+ RegisterComponent(&com, kTestComponent_abag, Version("1.1"), installer));
// The following two calls ensure that we don't do an update check via the
// timer, so the only update check should be the on-demand one.
test_configurator()->SetInitialDelay(1000000);
@@ -1275,8 +1285,8 @@ TEST_F(ComponentUpdaterTest, ResourceThrottleDeletedNoUpdate) {
RunThreads();
EXPECT_EQ(1, post_interceptor_->GetHitCount());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
+ EXPECT_EQ(0, installer->error());
+ EXPECT_EQ(0, installer->install_count());
component_updater()->Stop();
}
@@ -1349,12 +1359,12 @@ TEST_F(ComponentUpdaterTest, ResourceThrottleLiveNoUpdate) {
EXPECT_TRUE(post_interceptor_->ExpectRequest(
new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
- TestInstaller installer;
+ scoped_refptr<TestInstaller> installer(new TestInstaller);
CrxComponent com;
component_updater()->AddObserver(&observer);
- EXPECT_EQ(
- ComponentUpdateService::kOk,
- RegisterComponent(&com, kTestComponent_abag, Version("1.1"), &installer));
+ EXPECT_EQ(ComponentUpdateService::kOk,
+ RegisterComponent(&com, kTestComponent_abag, Version("1.1"),
+ installer));
// The following two calls ensure that we don't do an update check via the
// timer, so the only update check should be the on-demand one.
test_configurator()->SetInitialDelay(1000000);
@@ -1381,8 +1391,8 @@ TEST_F(ComponentUpdaterTest, ResourceThrottleLiveNoUpdate) {
RunThreads();
EXPECT_EQ(1, post_interceptor_->GetHitCount());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
+ EXPECT_EQ(0, installer->error());
+ EXPECT_EQ(0, installer->install_count());
component_updater()->Stop();
}
@@ -1407,8 +1417,8 @@ TEST_F(ComponentUpdaterTest, ResourceThrottleLiveNoUpdate) {
RunThreads();
EXPECT_EQ(1, post_interceptor_->GetHitCount());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
- EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
+ EXPECT_EQ(0, installer->error());
+ EXPECT_EQ(0, installer->install_count());
component_updater()->Stop();
}
@@ -1466,11 +1476,11 @@ TEST_F(ComponentUpdaterTest, Observer) {
component_updater()->AddObserver(&observer1);
component_updater()->AddObserver(&observer2);
- TestInstaller installer;
+ scoped_refptr<TestInstaller> installer(new TestInstaller);
CrxComponent com;
EXPECT_EQ(
ComponentUpdateService::kOk,
- RegisterComponent(&com, kTestComponent_abag, Version("1.1"), &installer));
+ RegisterComponent(&com, kTestComponent_abag, Version("1.1"), installer));
test_configurator()->SetLoopCount(1);
component_updater()->Start();
RunThreads();
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 4955041..bb035ce 100644
--- a/chrome/browser/component_updater/test/component_updater_service_unittest.h
+++ b/chrome/browser/component_updater/test/component_updater_service_unittest.h
@@ -60,7 +60,7 @@ class ComponentUpdaterTest : public testing::Test {
update_client::CrxComponent* com,
TestComponents component,
const Version& version,
- update_client::TestInstaller* installer);
+ const scoped_refptr<update_client::TestInstaller>& installer);
protected:
void RunThreads();
diff --git a/chrome/browser/component_updater/test/supervised_user_whitelist_installer_unittest.cc b/chrome/browser/component_updater/test/supervised_user_whitelist_installer_unittest.cc
index 1f0ef1f..d633447 100644
--- a/chrome/browser/component_updater/test/supervised_user_whitelist_installer_unittest.cc
+++ b/chrome/browser/component_updater/test/supervised_user_whitelist_installer_unittest.cc
@@ -58,10 +58,7 @@ class MockComponentUpdateService : public ComponentUpdateService {
const scoped_refptr<base::SequencedTaskRunner>& task_runner)
: task_runner_(task_runner) {}
- ~MockComponentUpdateService() override {
- if (component_)
- delete component_->installer;
- }
+ ~MockComponentUpdateService() override {}
MockOnDemandUpdater& on_demand_updater() { return on_demand_updater_; }
diff --git a/chrome/browser/net/crl_set_fetcher.h b/chrome/browser/net/crl_set_fetcher.h
index 3568df3..ac4be19 100644
--- a/chrome/browser/net/crl_set_fetcher.h
+++ b/chrome/browser/net/crl_set_fetcher.h
@@ -25,8 +25,7 @@ namespace component_updater {
class ComponentUpdateService;
}
-class CRLSetFetcher : public update_client::ComponentInstaller,
- public base::RefCountedThreadSafe<CRLSetFetcher> {
+class CRLSetFetcher : public update_client::ComponentInstaller {
public:
CRLSetFetcher();
diff --git a/components/component_updater/component_updater_service.cc b/components/component_updater/component_updater_service.cc
index 4b97bae..89195c4 100644
--- a/components/component_updater/component_updater_service.cc
+++ b/components/component_updater/component_updater_service.cc
@@ -108,7 +108,7 @@ class CrxUpdateService : public ComponentUpdateService, public OnDemandUpdater {
// Context for a crx download url request.
struct CRXContext {
- ComponentInstaller* installer;
+ scoped_refptr<ComponentInstaller> installer;
std::vector<uint8_t> pk_hash;
std::string id;
std::string fingerprint;
diff --git a/components/component_updater/default_component_installer.cc b/components/component_updater/default_component_installer.cc
index 6588973..d73b4fc 100644
--- a/components/component_updater/default_component_installer.cc
+++ b/components/component_updater/default_component_installer.cc
@@ -55,8 +55,7 @@ void DefaultComponentInstaller::Register(ComponentUpdateService* cus) {
task_runner_->PostTask(
FROM_HERE,
base::Bind(&DefaultComponentInstaller::StartRegistration,
- base::Unretained(this),
- cus));
+ this, cus));
}
void DefaultComponentInstaller::OnUpdateError(int error) {
@@ -103,11 +102,8 @@ bool DefaultComponentInstaller::Install(const base::DictionaryValue& manifest,
current_manifest_->DeepCopy());
main_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&ComponentInstallerTraits::ComponentReady,
- base::Unretained(installer_traits_.get()),
- current_version_,
- GetInstallDirectory(),
- base::Passed(&manifest_copy)));
+ base::Bind(&DefaultComponentInstaller::ComponentReady,
+ this, base::Passed(&manifest_copy)));
return true;
}
@@ -197,8 +193,7 @@ void DefaultComponentInstaller::StartRegistration(ComponentUpdateService* cus) {
main_task_runner_->PostTask(
FROM_HERE,
base::Bind(&DefaultComponentInstaller::FinishRegistration,
- base::Unretained(this),
- cus));
+ this, cus));
}
base::FilePath DefaultComponentInstaller::GetInstallDirectory() {
@@ -230,8 +225,13 @@ void DefaultComponentInstaller::FinishRegistration(
scoped_ptr<base::DictionaryValue> manifest_copy(
current_manifest_->DeepCopy());
+ ComponentReady(manifest_copy.Pass());
+}
+
+void DefaultComponentInstaller::ComponentReady(
+ scoped_ptr<base::DictionaryValue> manifest) {
installer_traits_->ComponentReady(
- current_version_, GetInstallDirectory(), manifest_copy.Pass());
+ current_version_, GetInstallDirectory(), manifest.Pass());
}
} // namespace component_updater
diff --git a/components/component_updater/default_component_installer.h b/components/component_updater/default_component_installer.h
index 120d3a5..8a39993 100644
--- a/components/component_updater/default_component_installer.h
+++ b/components/component_updater/default_component_installer.h
@@ -99,15 +99,16 @@ class DefaultComponentInstaller : public update_client::ComponentInstaller {
bool GetInstalledFile(const std::string& file,
base::FilePath* installed_file) override;
+ private:
~DefaultComponentInstaller() override;
- private:
base::FilePath GetInstallDirectory();
bool InstallHelper(const base::DictionaryValue& manifest,
const base::FilePath& unpack_path,
const base::FilePath& install_path);
void StartRegistration(ComponentUpdateService* cus);
void FinishRegistration(ComponentUpdateService* cus);
+ void ComponentReady(scoped_ptr<base::DictionaryValue> manifest);
base::Version current_version_;
std::string current_fingerprint_;
diff --git a/components/update_client/component_patcher.cc b/components/update_client/component_patcher.cc
index 651756e..3077bc4 100644
--- a/components/update_client/component_patcher.cc
+++ b/components/update_client/component_patcher.cc
@@ -16,6 +16,7 @@
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "components/update_client/component_patcher_operation.h"
+#include "components/update_client/update_client.h"
namespace update_client {
@@ -42,7 +43,7 @@ base::ListValue* ReadCommands(const base::FilePath& unpack_path) {
ComponentPatcher::ComponentPatcher(
const base::FilePath& input_dir,
const base::FilePath& unpack_dir,
- ComponentInstaller* installer,
+ scoped_refptr<ComponentInstaller> installer,
scoped_refptr<OutOfProcessPatcher> out_of_process_patcher,
scoped_refptr<base::SequencedTaskRunner> task_runner)
: input_dir_(input_dir),
diff --git a/components/update_client/component_patcher.h b/components/update_client/component_patcher.h
index b7dd216..394edfe 100644
--- a/components/update_client/component_patcher.h
+++ b/components/update_client/component_patcher.h
@@ -61,7 +61,7 @@ class ComponentPatcher : public base::RefCountedThreadSafe<ComponentPatcher> {
// out-of-process.
ComponentPatcher(const base::FilePath& input_dir,
const base::FilePath& unpack_dir,
- ComponentInstaller* installer,
+ scoped_refptr<ComponentInstaller> installer,
scoped_refptr<OutOfProcessPatcher> out_of_process_patcher,
scoped_refptr<base::SequencedTaskRunner> task_runner);
@@ -86,7 +86,7 @@ class ComponentPatcher : public base::RefCountedThreadSafe<ComponentPatcher> {
const base::FilePath input_dir_;
const base::FilePath unpack_dir_;
- ComponentInstaller* const installer_;
+ scoped_refptr<ComponentInstaller> installer_;
scoped_refptr<OutOfProcessPatcher> out_of_process_patcher_;
ComponentUnpacker::Callback callback_;
scoped_ptr<base::ListValue> commands_;
diff --git a/components/update_client/component_patcher_operation.cc b/components/update_client/component_patcher_operation.cc
index adb5b8f..c5e7437 100644
--- a/components/update_client/component_patcher_operation.cc
+++ b/components/update_client/component_patcher_operation.cc
@@ -43,7 +43,7 @@ const char kPatch[] = "patch";
DeltaUpdateOp* CreateDeltaUpdateOp(
const std::string& operation,
- scoped_refptr<OutOfProcessPatcher> out_of_process_patcher) {
+ const scoped_refptr<OutOfProcessPatcher>& out_of_process_patcher) {
if (operation == "copy") {
return new DeltaUpdateOpCopy();
} else if (operation == "create") {
@@ -60,12 +60,13 @@ DeltaUpdateOp::DeltaUpdateOp() {
DeltaUpdateOp::~DeltaUpdateOp() {
}
-void DeltaUpdateOp::Run(const base::DictionaryValue* command_args,
- const base::FilePath& input_dir,
- const base::FilePath& unpack_dir,
- ComponentInstaller* installer,
- const ComponentUnpacker::Callback& callback,
- scoped_refptr<base::SequencedTaskRunner> task_runner) {
+void DeltaUpdateOp::Run(
+ const base::DictionaryValue* command_args,
+ const base::FilePath& input_dir,
+ const base::FilePath& unpack_dir,
+ const scoped_refptr<ComponentInstaller>& installer,
+ const ComponentUnpacker::Callback& callback,
+ const scoped_refptr<base::SequencedTaskRunner>& task_runner) {
callback_ = callback;
task_runner_ = task_runner;
std::string output_rel_path;
@@ -140,7 +141,7 @@ DeltaUpdateOpCopy::~DeltaUpdateOpCopy() {
ComponentUnpacker::Error DeltaUpdateOpCopy::DoParseArguments(
const base::DictionaryValue* command_args,
const base::FilePath& input_dir,
- ComponentInstaller* installer) {
+ const scoped_refptr<ComponentInstaller>& installer) {
std::string input_rel_path;
if (!command_args->GetString(kInput, &input_rel_path))
return ComponentUnpacker::kDeltaBadCommands;
@@ -167,7 +168,7 @@ DeltaUpdateOpCreate::~DeltaUpdateOpCreate() {
ComponentUnpacker::Error DeltaUpdateOpCreate::DoParseArguments(
const base::DictionaryValue* command_args,
const base::FilePath& input_dir,
- ComponentInstaller* installer) {
+ const scoped_refptr<ComponentInstaller>& installer) {
std::string patch_rel_path;
if (!command_args->GetString(kPatch, &patch_rel_path))
return ComponentUnpacker::kDeltaBadCommands;
@@ -198,7 +199,7 @@ DeltaUpdateOpPatch::~DeltaUpdateOpPatch() {
ComponentUnpacker::Error DeltaUpdateOpPatch::DoParseArguments(
const base::DictionaryValue* command_args,
const base::FilePath& input_dir,
- ComponentInstaller* installer) {
+ const scoped_refptr<ComponentInstaller>& installer) {
std::string patch_rel_path;
std::string input_rel_path;
if (!command_args->GetString(kPatch, &patch_rel_path) ||
diff --git a/components/update_client/component_patcher_operation.h b/components/update_client/component_patcher_operation.h
index 8f31c04..0771757 100644
--- a/components/update_client/component_patcher_operation.h
+++ b/components/update_client/component_patcher_operation.h
@@ -37,9 +37,9 @@ class DeltaUpdateOp : public base::RefCountedThreadSafe<DeltaUpdateOp> {
void Run(const base::DictionaryValue* command_args,
const base::FilePath& input_dir,
const base::FilePath& unpack_dir,
- ComponentInstaller* installer,
+ const scoped_refptr<ComponentInstaller>& installer,
const ComponentUnpacker::Callback& callback,
- scoped_refptr<base::SequencedTaskRunner> task_runner);
+ const scoped_refptr<base::SequencedTaskRunner>& task_runner);
protected:
virtual ~DeltaUpdateOp();
@@ -60,7 +60,7 @@ class DeltaUpdateOp : public base::RefCountedThreadSafe<DeltaUpdateOp> {
virtual ComponentUnpacker::Error DoParseArguments(
const base::DictionaryValue* command_args,
const base::FilePath& input_dir,
- ComponentInstaller* installer) = 0;
+ const scoped_refptr<ComponentInstaller>& installer) = 0;
// Subclasses must override DoRun to actually perform the patching operation.
// They must call the provided callback when they have completed their
@@ -92,7 +92,7 @@ class DeltaUpdateOpCopy : public DeltaUpdateOp {
ComponentUnpacker::Error DoParseArguments(
const base::DictionaryValue* command_args,
const base::FilePath& input_dir,
- ComponentInstaller* installer) override;
+ const scoped_refptr<ComponentInstaller>& installer) override;
void DoRun(const ComponentUnpacker::Callback& callback) override;
@@ -116,7 +116,7 @@ class DeltaUpdateOpCreate : public DeltaUpdateOp {
ComponentUnpacker::Error DoParseArguments(
const base::DictionaryValue* command_args,
const base::FilePath& input_dir,
- ComponentInstaller* installer) override;
+ const scoped_refptr<ComponentInstaller>& installer) override;
void DoRun(const ComponentUnpacker::Callback& callback) override;
@@ -129,12 +129,13 @@ class DeltaUpdateOpCreate : public DeltaUpdateOp {
class OutOfProcessPatcher
: public base::RefCountedThreadSafe<OutOfProcessPatcher> {
public:
- virtual void Patch(const std::string& operation,
- scoped_refptr<base::SequencedTaskRunner> task_runner,
- const base::FilePath& input_abs_path,
- const base::FilePath& patch_abs_path,
- const base::FilePath& output_abs_path,
- base::Callback<void(int result)> callback) = 0;
+ virtual void Patch(
+ const std::string& operation,
+ scoped_refptr<base::SequencedTaskRunner> task_runner,
+ const base::FilePath& input_abs_path,
+ const base::FilePath& patch_abs_path,
+ const base::FilePath& output_abs_path,
+ base::Callback<void(int result)> callback) = 0;
protected:
friend class base::RefCountedThreadSafe<OutOfProcessPatcher>;
@@ -159,7 +160,7 @@ class DeltaUpdateOpPatch : public DeltaUpdateOp {
ComponentUnpacker::Error DoParseArguments(
const base::DictionaryValue* command_args,
const base::FilePath& input_dir,
- ComponentInstaller* installer) override;
+ const scoped_refptr<ComponentInstaller>& installer) override;
void DoRun(const ComponentUnpacker::Callback& callback) override;
@@ -177,7 +178,7 @@ class DeltaUpdateOpPatch : public DeltaUpdateOp {
DeltaUpdateOp* CreateDeltaUpdateOp(
const std::string& operation,
- scoped_refptr<OutOfProcessPatcher> out_of_process_patcher);
+ const scoped_refptr<OutOfProcessPatcher>& out_of_process_patcher);
} // namespace update_client
diff --git a/components/update_client/component_unpacker.cc b/components/update_client/component_unpacker.cc
index 27d75b9..eb1b2d8 100644
--- a/components/update_client/component_unpacker.cc
+++ b/components/update_client/component_unpacker.cc
@@ -102,9 +102,9 @@ ComponentUnpacker::ComponentUnpacker(
const std::vector<uint8_t>& pk_hash,
const base::FilePath& path,
const std::string& fingerprint,
- ComponentInstaller* installer,
- scoped_refptr<OutOfProcessPatcher> oop_patcher,
- scoped_refptr<base::SequencedTaskRunner> task_runner)
+ const scoped_refptr<ComponentInstaller>& installer,
+ const scoped_refptr<OutOfProcessPatcher>& oop_patcher,
+ const scoped_refptr<base::SequencedTaskRunner>& task_runner)
: pk_hash_(pk_hash),
path_(path),
is_delta_(false),
diff --git a/components/update_client/component_unpacker.h b/components/update_client/component_unpacker.h
index 7c2b6ef..033fd33 100644
--- a/components/update_client/component_unpacker.h
+++ b/components/update_client/component_unpacker.h
@@ -95,12 +95,13 @@ class ComponentUnpacker : public base::RefCountedThreadSafe<ComponentUnpacker> {
// 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<uint8_t>& pk_hash,
- const base::FilePath& path,
- const std::string& fingerprint,
- ComponentInstaller* installer,
- scoped_refptr<OutOfProcessPatcher> oop_patcher,
- scoped_refptr<base::SequencedTaskRunner> task_runner);
+ ComponentUnpacker(
+ const std::vector<uint8_t>& pk_hash,
+ const base::FilePath& path,
+ const std::string& fingerprint,
+ const scoped_refptr<ComponentInstaller>& installer,
+ const scoped_refptr<OutOfProcessPatcher>& oop_patcher,
+ const scoped_refptr<base::SequencedTaskRunner>& task_runner);
// Begins the actual unpacking of the files. May invoke a patcher if the
// package is a differential update. Calls |callback| with the result.
@@ -147,7 +148,7 @@ class ComponentUnpacker : public base::RefCountedThreadSafe<ComponentUnpacker> {
bool is_delta_;
std::string fingerprint_;
scoped_refptr<ComponentPatcher> patcher_;
- ComponentInstaller* installer_;
+ scoped_refptr<ComponentInstaller> installer_;
Callback callback_;
scoped_refptr<OutOfProcessPatcher> oop_patcher_;
Error error_;
diff --git a/components/update_client/test/component_patcher_unittest.cc b/components/update_client/test/component_patcher_unittest.cc
index ce6e7a1..4f5e143 100644
--- a/components/update_client/test/component_patcher_unittest.cc
+++ b/components/update_client/test/component_patcher_unittest.cc
@@ -69,7 +69,7 @@ ComponentPatcherOperationTest::ComponentPatcherOperationTest() {
EXPECT_TRUE(unpack_dir_.CreateUniqueTempDir());
EXPECT_TRUE(input_dir_.CreateUniqueTempDir());
EXPECT_TRUE(installed_dir_.CreateUniqueTempDir());
- installer_.reset(new ReadOnlyTestInstaller(installed_dir_.path()));
+ installer_ = new ReadOnlyTestInstaller(installed_dir_.path());
task_runner_ = base::MessageLoop::current()->task_runner();
}
diff --git a/components/update_client/test/component_patcher_unittest.h b/components/update_client/test/component_patcher_unittest.h
index f7a4aea..2fcd5f5 100644
--- a/components/update_client/test/component_patcher_unittest.h
+++ b/components/update_client/test/component_patcher_unittest.h
@@ -30,7 +30,7 @@ class ComponentPatcherOperationTest : public testing::Test {
base::ScopedTempDir input_dir_;
base::ScopedTempDir installed_dir_;
base::ScopedTempDir unpack_dir_;
- scoped_ptr<ReadOnlyTestInstaller> installer_;
+ scoped_refptr<ReadOnlyTestInstaller> installer_;
scoped_refptr<base::SequencedTaskRunner> task_runner_;
private:
diff --git a/components/update_client/test/test_installer.cc b/components/update_client/test/test_installer.cc
index b6a3f84..de32b1f 100644
--- a/components/update_client/test/test_installer.cc
+++ b/components/update_client/test/test_installer.cc
@@ -30,12 +30,7 @@ bool TestInstaller::GetInstalledFile(const std::string& file,
return false;
}
-int TestInstaller::error() const {
- return error_;
-}
-
-int TestInstaller::install_count() const {
- return install_count_;
+TestInstaller::~TestInstaller() {
}
ReadOnlyTestInstaller::ReadOnlyTestInstaller(const base::FilePath& install_dir)
diff --git a/components/update_client/test/test_installer.h b/components/update_client/test/test_installer.h
index 933fe21..2d9ae9f 100644
--- a/components/update_client/test/test_installer.h
+++ b/components/update_client/test/test_installer.h
@@ -31,11 +31,17 @@ class TestInstaller : public ComponentInstaller {
bool GetInstalledFile(const std::string& file,
base::FilePath* installed_file) override;
- int error() const;
+ int error() const {
+ return error_;
+ }
- int install_count() const;
+ int install_count() const {
+ return install_count_;
+ }
protected:
+ ~TestInstaller() override;
+
int error_;
int install_count_;
};
@@ -46,12 +52,12 @@ class ReadOnlyTestInstaller : public TestInstaller {
public:
explicit ReadOnlyTestInstaller(const base::FilePath& installed_path);
- ~ReadOnlyTestInstaller() override;
-
bool GetInstalledFile(const std::string& file,
base::FilePath* installed_file) override;
private:
+ ~ReadOnlyTestInstaller() override;
+
base::FilePath install_directory_;
};
@@ -61,8 +67,6 @@ class VersionedTestInstaller : public TestInstaller {
public:
VersionedTestInstaller();
- ~VersionedTestInstaller() override;
-
bool Install(const base::DictionaryValue& manifest,
const base::FilePath& unpack_path) override;
@@ -70,6 +74,8 @@ class VersionedTestInstaller : public TestInstaller {
base::FilePath* installed_file) override;
private:
+ ~VersionedTestInstaller() override;
+
base::FilePath install_directory_;
Version current_version_;
};
diff --git a/components/update_client/update_client.h b/components/update_client/update_client.h
index 07b5617..28b69c0 100644
--- a/components/update_client/update_client.h
+++ b/components/update_client/update_client.h
@@ -9,6 +9,7 @@
#include <string>
#include <vector>
+#include "base/memory/ref_counted.h"
#include "base/version.h"
namespace base {
@@ -21,7 +22,8 @@ namespace update_client {
// Component specific installers must derive from this class and implement
// OnUpdateError() and Install(). A valid instance of this class must be
// given to ComponentUpdateService::RegisterComponent().
-class ComponentInstaller {
+class ComponentInstaller
+ : public base::RefCountedThreadSafe<ComponentInstaller> {
public:
// Called by the component updater on the main thread when there was a
// problem unpacking or verifying the component. |error| is a non-zero
@@ -43,6 +45,9 @@ class ComponentInstaller {
virtual bool GetInstalledFile(const std::string& file,
base::FilePath* installed_file) = 0;
+ protected:
+ friend class base::RefCountedThreadSafe<ComponentInstaller>;
+
virtual ~ComponentInstaller() {}
};
@@ -57,7 +62,7 @@ class ComponentInstaller {
// the issue 340448 is resolved.
struct CrxComponent {
std::vector<uint8_t> pk_hash;
- ComponentInstaller* installer;
+ scoped_refptr<ComponentInstaller> installer;
Version version;
std::string fingerprint;
std::string name;