Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(910)

Unified Diff: chrome/browser/component_updater/pnacl/pnacl_component_installer.cc

Issue 18006003: Consistently use notifications from component updater w/ on-demand PNaCl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more cleanup Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/component_updater/pnacl/pnacl_component_installer.cc
diff --git a/chrome/browser/component_updater/pnacl/pnacl_component_installer.cc b/chrome/browser/component_updater/pnacl/pnacl_component_installer.cc
index 30d24561a3795988d4b478f192f361ebe8d4ae05..36225c4d46fa4d29613a82724ba03408c0a196a8 100644
--- a/chrome/browser/component_updater/pnacl/pnacl_component_installer.cc
+++ b/chrome/browser/component_updater/pnacl/pnacl_component_installer.cc
@@ -137,8 +137,6 @@ base::DictionaryValue* ReadComponentManifest(
return ReadJSONManifest(manifest_path);
}
-} // namespace
-
// Check that the component's manifest is for PNaCl, and check the
// PNaCl manifest indicates this is the correct arch-specific package.
bool CheckPnaclComponentManifest(const base::DictionaryValue& manifest,
@@ -188,11 +186,12 @@ bool CheckPnaclComponentManifest(const base::DictionaryValue& manifest,
return true;
}
+} // namespace
+
PnaclComponentInstaller::PnaclComponentInstaller()
: per_user_(false),
updates_disabled_(false),
- cus_(NULL),
- callback_nums_(0) {
+ cus_(NULL) {
#if defined(OS_CHROMEOS)
per_user_ = true;
#endif
@@ -299,65 +298,56 @@ bool PnaclComponentInstaller::GetInstalledFile(
return true;
}
-void PnaclComponentInstaller::AddInstallCallback(
- const InstallCallback& cb) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- int num = ++callback_nums_;
- install_callbacks_.push_back(std::make_pair(cb, num));
-}
-
-void PnaclComponentInstaller::CancelCallback(int num) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- for (std::list<std::pair<InstallCallback, int> >::iterator
- i = install_callbacks_.begin(),
- e = install_callbacks_.end(); i != e; ++i) {
- if (i->second == num) {
- i->first.Run(false);
- install_callbacks_.erase(i);
- return;
- }
- }
-}
-
-void PnaclComponentInstaller::NotifyAllWithResult(bool status) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- while (!install_callbacks_.empty()) {
- install_callbacks_.front().first.Run(status);
- install_callbacks_.pop_front();
- }
-}
-
void PnaclComponentInstaller::NotifyInstallError() {
- if (!install_callbacks_.empty()) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(&PnaclComponentInstaller::NotifyAllWithResult,
+ base::Bind(&PnaclComponentInstaller::NotifyInstallError,
// Unretained because installer lives until process shutdown.
- base::Unretained(this), false));
+ base::Unretained(this)));
+ return;
+ }
+ if (!install_callback_.is_null()) {
+ install_callback_.Run(false);
+ install_callback_.Reset();
+ updater_observer_->StopObserving();
}
}
void PnaclComponentInstaller::NotifyInstallSuccess() {
- if (!install_callbacks_.empty()) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(&PnaclComponentInstaller::NotifyAllWithResult,
+ base::Bind(&PnaclComponentInstaller::NotifyInstallSuccess,
// Unretained because installer lives until process shutdown.
- base::Unretained(this), true));
+ base::Unretained(this)));
+ return;
+ }
+ if (!install_callback_.is_null()) {
+ install_callback_.Run(true);
+ install_callback_.Reset();
+ updater_observer_->StopObserving();
}
}
+CrxComponent PnaclComponentInstaller::GetCrxComponent() {
+ CrxComponent pnacl_component;
+ pnacl_component.version = current_version();
+ pnacl_component.name = "pnacl";
+ pnacl_component.installer = this;
+ pnacl_component.observer = updater_observer_.get();
+ SetPnaclHash(&pnacl_component);
+
+ return pnacl_component;
+}
+
namespace {
void FinishPnaclUpdateRegistration(const Version& current_version,
PnaclComponentInstaller* pci) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- CrxComponent pnacl_component;
- pnacl_component.version = current_version;
- pnacl_component.name = "pnacl";
- pnacl_component.installer = pci;
pci->set_current_version(current_version);
- SetPnaclHash(&pnacl_component);
+ CrxComponent pnacl_component = pci->GetCrxComponent();
ComponentUpdateService::Status status =
pci->cus()->RegisterComponent(pnacl_component);
@@ -481,22 +471,22 @@ void PnaclComponentInstaller::ReRegisterPnacl() {
base::Bind(&GetProfileInformation, this));
}
-void RequestFirstInstall(ComponentUpdateService* cus,
- PnaclComponentInstaller* pci,
- const base::Callback<void(bool)>& installed) {
+void PnaclComponentInstaller::RequestFirstInstall(
Sorin Jianu 2013/08/05 19:24:58 does the argument fit on the line above?
jvoung (off chromium) 2013/08/05 20:36:03 Done.
+ const InstallCallback& cb) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- Version null_version(kNullVersion);
- CrxComponent pnacl_component;
- pci->set_current_version(null_version);
- pnacl_component.version = null_version;
- pnacl_component.name = "pnacl";
- pnacl_component.installer = pci;
- SetPnaclHash(&pnacl_component);
- ComponentUpdateService::Status status = cus->CheckForUpdateSoon(
+ // Only one request can happen at once.
+ if (!install_callback_.is_null()) {
+ cb.Run(false);
+ return;
+ }
+ set_current_version(Version(kNullVersion));
+ CrxComponent pnacl_component = GetCrxComponent();
+ ComponentUpdateService::Status status = cus_->CheckForUpdateSoon(
pnacl_component);
if (status != ComponentUpdateService::kOk) {
- installed.Run(false);
+ cb.Run(false);
return;
}
- pci->AddInstallCallback(installed);
+ install_callback_ = cb;
+ updater_observer_->EnsureObserving();
}

Powered by Google App Engine
This is Rietveld 408576698