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" | 7 #include "base/logging.h" |
8 #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h" | 8 #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h" |
9 #include "chrome/common/chrome_notification_types.h" | 9 #include "chrome/common/chrome_notification_types.h" |
10 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
11 | 11 |
12 PnaclUpdaterObserver::PnaclUpdaterObserver( | 12 PnaclUpdaterObserver::PnaclUpdaterObserver(PnaclComponentInstaller* installer) |
13 PnaclComponentInstaller* installer) : pnacl_installer_(installer) { | 13 : pnacl_installer_(installer) {} |
14 registrar_.Add(this, | 14 |
15 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, | 15 PnaclUpdaterObserver::~PnaclUpdaterObserver() {} |
16 content::NotificationService::AllSources()); | 16 |
17 void PnaclUpdaterObserver::EnsureObserving() { | |
18 if (registrar_.IsEmpty()) { | |
19 registrar_.Add(this, | |
20 chrome::NOTIFICATION_COMPONENT_UPDATE_READY, | |
21 content::NotificationService::AllSources()); | |
22 registrar_.Add(this, | |
23 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, | |
24 content::NotificationService::AllSources()); | |
25 } | |
17 } | 26 } |
18 | 27 |
19 PnaclUpdaterObserver::~PnaclUpdaterObserver() { } | 28 void PnaclUpdaterObserver::StopObserving() { |
29 registrar_.RemoveAll(); | |
30 } | |
20 | 31 |
21 void PnaclUpdaterObserver::Observe( | 32 void PnaclUpdaterObserver::Observe( |
22 int type, | 33 int type, |
23 const content::NotificationSource& source, | 34 const content::NotificationSource& source, |
24 const content::NotificationDetails& details) { | 35 const content::NotificationDetails& details) { |
36 | |
37 if (type == chrome::NOTIFICATION_COMPONENT_UPDATE_READY) { | |
38 // If the component updater says there is an UPDATE_READY w/ source | |
39 // being the PNaCl ID, then installation is handed off to the PNaCl | |
40 // installer and we can stop observing. | |
41 if (ComponentUpdateService::IsUpdateNotificationForComponent( | |
42 source, pnacl_installer_->GetCrxComponent())) { | |
43 StopObserving(); | |
44 } | |
45 return; | |
46 } | |
47 | |
25 if (type == chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING) { | 48 if (type == chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING) { |
26 // If the component updater sleeps before a NotifyInstallSuccess, | 49 // If the component updater sleeps before an UPDATE_READY for this |
27 // then requests for installs were likely skipped, or an error occurred. | 50 // component, then requests for installs were likely skipped, |
51 // or an error occurred. | |
cpu_(ooo_6.6-7.5)
2013/07/03 18:04:53
or you are up to date..
jvoung (off chromium)
2013/07/03 22:51:51
Done.
| |
28 pnacl_installer_->NotifyInstallError(); | 52 pnacl_installer_->NotifyInstallError(); |
53 StopObserving(); | |
29 return; | 54 return; |
30 } | 55 } |
31 } | 56 } |
OLD | NEW |