Index: chrome/browser/component_updater/pnacl/pnacl_updater_observer.cc |
diff --git a/chrome/browser/component_updater/pnacl/pnacl_updater_observer.cc b/chrome/browser/component_updater/pnacl/pnacl_updater_observer.cc |
index 2a3a6fa891914eb5e626177235f414a1f71fce20..d0bf30e8950ef007cdc376b1c4648ceb84ae8407 100644 |
--- a/chrome/browser/component_updater/pnacl/pnacl_updater_observer.cc |
+++ b/chrome/browser/component_updater/pnacl/pnacl_updater_observer.cc |
@@ -9,23 +9,57 @@ |
#include "chrome/common/chrome_notification_types.h" |
#include "content/public/browser/notification_service.h" |
-PnaclUpdaterObserver::PnaclUpdaterObserver( |
- PnaclComponentInstaller* installer) : pnacl_installer_(installer) { |
- registrar_.Add(this, |
- chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, |
- content::NotificationService::AllSources()); |
+PnaclUpdaterObserver::PnaclUpdaterObserver(PnaclComponentInstaller* installer) |
+ : is_observing_(false), pnacl_installer_(installer) {} |
+ |
+PnaclUpdaterObserver::~PnaclUpdaterObserver() {} |
+ |
+void PnaclUpdaterObserver::EnsureObserving() { |
+ if (!is_observing_) { |
+ registrar_.Add(this, |
+ chrome::NOTIFICATION_COMPONENT_UPDATE_READY, |
+ content::NotificationService::AllSources()); |
+ registrar_.Add(this, |
+ chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, |
+ content::NotificationService::AllSources()); |
+ is_observing_ = true; |
+ } |
} |
-PnaclUpdaterObserver::~PnaclUpdaterObserver() { } |
+void PnaclUpdaterObserver::StopObserving() { |
+ if (is_observing_) { |
+ registrar_.Remove(this, |
cpu_(ooo_6.6-7.5)
2013/07/01 18:30:22
registrar_. RemoveAll() ?
jvoung (off chromium)
2013/07/02 01:04:26
Ah yes, Done.
|
+ chrome::NOTIFICATION_COMPONENT_UPDATE_READY, |
+ content::NotificationService::AllSources()); |
+ registrar_.Remove(this, |
+ chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, |
+ content::NotificationService::AllSources()); |
+ is_observing_ = false; |
cpu_(ooo_6.6-7.5)
2013/07/01 18:30:22
registrar_ IsEmpty()?
jvoung (off chromium)
2013/07/02 01:04:26
Done.
|
+ } |
+} |
void PnaclUpdaterObserver::Observe( |
int type, |
const content::NotificationSource& source, |
const content::NotificationDetails& details) { |
+ |
+ if (type == chrome::NOTIFICATION_COMPONENT_UPDATE_READY) { |
+ // If the component updater says there is an UPDATE_READY w/ source |
+ // being the PNaCl ID, then installation is handed off to the PNaCl |
+ // installer and we can stop observing. |
+ if (ComponentUpdateService::IsUpdateNotificationForComponent( |
+ source, pnacl_installer_->GetCrxComponent())) { |
+ StopObserving(); |
+ } |
+ return; |
+ } |
+ |
if (type == chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING) { |
- // If the component updater sleeps before a NotifyInstallSuccess, |
- // then requests for installs were likely skipped, or an error occurred. |
+ // If the component updater sleeps before an UPDATE_READY for this |
+ // component, then requests for installs were likely skipped, |
+ // or an error occurred. |
pnacl_installer_->NotifyInstallError(); |
+ StopObserving(); |
return; |
} |
} |