OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/component_updater/pnacl/pnacl_updater_observer.h" | 5 #include "chrome/browser/component_updater/pnacl/pnacl_updater_observer.h" |
6 | 6 |
7 #include "base/logging.h" | |
8 #include "chrome/browser/chrome_notification_types.h" | |
9 #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h" | 7 #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h" |
10 #include "content/public/browser/notification_service.h" | 8 #include "content/public/browser/browser_thread.h" |
11 | 9 |
12 PnaclUpdaterObserver::PnaclUpdaterObserver( | 10 using content::BrowserThread; |
13 PnaclComponentInstaller* installer) : pnacl_installer_(installer) { | 11 |
14 registrar_.Add(this, | 12 PnaclUpdaterObserver::PnaclUpdaterObserver(PnaclComponentInstaller* pci) |
15 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, | 13 : must_observe_(false), pnacl_installer_(pci) {} |
16 content::NotificationService::AllSources()); | 14 |
| 15 PnaclUpdaterObserver::~PnaclUpdaterObserver() {} |
| 16 |
| 17 void PnaclUpdaterObserver::EnsureObserving() { |
| 18 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 19 must_observe_ = true; |
17 } | 20 } |
18 | 21 |
19 PnaclUpdaterObserver::~PnaclUpdaterObserver() { } | 22 void PnaclUpdaterObserver::StopObserving() { |
| 23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 24 must_observe_ = false; |
| 25 } |
20 | 26 |
21 void PnaclUpdaterObserver::Observe( | 27 void PnaclUpdaterObserver::OnEvent(Events event, int extra) { |
22 int type, | 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
23 const content::NotificationSource& source, | 29 if (must_observe_) { |
24 const content::NotificationDetails& details) { | 30 switch (event) { |
25 if (type == chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING) { | 31 default: |
26 // If the component updater sleeps before a NotifyInstallSuccess, | 32 break; |
27 // then requests for installs were likely skipped, or an error occurred. | 33 case COMPONENT_UPDATE_READY: |
28 pnacl_installer_->NotifyInstallError(); | 34 // If the component updater says there is an UPDATE_READY w/ source |
29 return; | 35 // being the PNaCl ID, then installation is handed off to the PNaCl |
| 36 // installer and we can stop observing. The installer will be the one |
| 37 // to run the callback w/ success or failure. |
| 38 must_observe_ = false; |
| 39 break; |
| 40 case COMPONENT_UPDATER_SLEEPING: |
| 41 // If the component updater sleeps before an UPDATE_READY for this |
| 42 // component, then requests for installs were likely skipped, |
| 43 // an error occurred, or there was no new update. |
| 44 must_observe_ = false; |
| 45 pnacl_installer_->NotifyInstallError(); |
| 46 break; |
| 47 } |
30 } | 48 } |
31 } | 49 } |
OLD | NEW |