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 : is_observing_(false), 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 (!is_observing_) { | |
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 is_observing_ = true; | |
26 } | |
17 } | 27 } |
18 | 28 |
19 PnaclUpdaterObserver::~PnaclUpdaterObserver() { } | 29 void PnaclUpdaterObserver::StopObserving() { |
30 if (is_observing_) { | |
31 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.
| |
32 chrome::NOTIFICATION_COMPONENT_UPDATE_READY, | |
33 content::NotificationService::AllSources()); | |
34 registrar_.Remove(this, | |
35 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, | |
36 content::NotificationService::AllSources()); | |
37 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.
| |
38 } | |
39 } | |
20 | 40 |
21 void PnaclUpdaterObserver::Observe( | 41 void PnaclUpdaterObserver::Observe( |
22 int type, | 42 int type, |
23 const content::NotificationSource& source, | 43 const content::NotificationSource& source, |
24 const content::NotificationDetails& details) { | 44 const content::NotificationDetails& details) { |
45 | |
46 if (type == chrome::NOTIFICATION_COMPONENT_UPDATE_READY) { | |
47 // If the component updater says there is an UPDATE_READY w/ source | |
48 // being the PNaCl ID, then installation is handed off to the PNaCl | |
49 // installer and we can stop observing. | |
50 if (ComponentUpdateService::IsUpdateNotificationForComponent( | |
51 source, pnacl_installer_->GetCrxComponent())) { | |
52 StopObserving(); | |
53 } | |
54 return; | |
55 } | |
56 | |
25 if (type == chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING) { | 57 if (type == chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING) { |
26 // If the component updater sleeps before a NotifyInstallSuccess, | 58 // If the component updater sleeps before an UPDATE_READY for this |
27 // then requests for installs were likely skipped, or an error occurred. | 59 // component, then requests for installs were likely skipped, |
60 // or an error occurred. | |
28 pnacl_installer_->NotifyInstallError(); | 61 pnacl_installer_->NotifyInstallError(); |
62 StopObserving(); | |
29 return; | 63 return; |
30 } | 64 } |
31 } | 65 } |
OLD | NEW |