OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/chromeos/app_mode/kiosk_app_update_service.h" | 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_update_service.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/app_mode/app_mode_utils.h" | 8 #include "chrome/browser/app_mode/app_mode_utils.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/browser_process_platform_part_chromeos.h" | 10 #include "chrome/browser/browser_process_platform_part_chromeos.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 system::AutomaticRebootManager* automatic_reboot_manager) | 34 system::AutomaticRebootManager* automatic_reboot_manager) |
35 : profile_(profile), | 35 : profile_(profile), |
36 automatic_reboot_manager_(automatic_reboot_manager) { | 36 automatic_reboot_manager_(automatic_reboot_manager) { |
37 ExtensionService* service = | 37 ExtensionService* service = |
38 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 38 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
39 if (service) | 39 if (service) |
40 service->AddUpdateObserver(this); | 40 service->AddUpdateObserver(this); |
41 | 41 |
42 if (automatic_reboot_manager_) | 42 if (automatic_reboot_manager_) |
43 automatic_reboot_manager_->AddObserver(this); | 43 automatic_reboot_manager_->AddObserver(this); |
| 44 |
| 45 if (KioskAppManager::Get()) |
| 46 KioskAppManager::Get()->AddObserver(this); |
44 } | 47 } |
45 | 48 |
46 KioskAppUpdateService::~KioskAppUpdateService() { | 49 KioskAppUpdateService::~KioskAppUpdateService() { |
47 } | 50 } |
48 | 51 |
49 void KioskAppUpdateService::StartAppUpdateRestartTimer() { | 52 void KioskAppUpdateService::StartAppUpdateRestartTimer() { |
50 if (restart_timer_.IsRunning()) | 53 if (restart_timer_.IsRunning()) |
51 return; | 54 return; |
52 | 55 |
53 // Setup timer to force restart once the wait period expires. | 56 // Setup timer to force restart once the wait period expires. |
54 restart_timer_.Start( | 57 restart_timer_.Start( |
55 FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs), | 58 FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs), |
56 this, &KioskAppUpdateService::ForceAppUpdateRestart); | 59 this, &KioskAppUpdateService::ForceAppUpdateRestart); |
57 } | 60 } |
58 | 61 |
59 void KioskAppUpdateService::ForceAppUpdateRestart() { | 62 void KioskAppUpdateService::ForceAppUpdateRestart() { |
60 // Force a chrome restart (not a logout or reboot) by closing all browsers. | 63 // Force a chrome restart (not a logout or reboot) by closing all browsers. |
61 LOG(WARNING) << "Force closing all browsers to update kiosk app."; | 64 LOG(WARNING) << "Force closing all browsers to update kiosk app."; |
62 chrome::CloseAllBrowsersAndQuit(); | 65 chrome::CloseAllBrowsersAndQuit(); |
63 } | 66 } |
64 | 67 |
65 void KioskAppUpdateService::Shutdown() { | 68 void KioskAppUpdateService::Shutdown() { |
66 ExtensionService* service = | 69 ExtensionService* service = |
67 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 70 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
68 if (service) | 71 if (service) |
69 service->RemoveUpdateObserver(this); | 72 service->RemoveUpdateObserver(this); |
| 73 if (KioskAppManager::Get()) |
| 74 KioskAppManager::Get()->RemoveObserver(this); |
70 } | 75 } |
71 | 76 |
72 void KioskAppUpdateService::OnAppUpdateAvailable( | 77 void KioskAppUpdateService::OnAppUpdateAvailable( |
73 const extensions::Extension* extension) { | 78 const extensions::Extension* extension) { |
74 if (extension->id() != app_id_) | 79 if (extension->id() != app_id_) |
75 return; | 80 return; |
76 | 81 |
77 // Clears cached app data so that it will be reloaded if update from app | 82 // Clears cached app data so that it will be reloaded if update from app |
78 // does not finish in this run. | 83 // does not finish in this run. |
79 KioskAppManager::Get()->ClearAppData(app_id_); | 84 KioskAppManager::Get()->ClearAppData(app_id_); |
(...skipping 27 matching lines...) Expand all Loading... |
107 | 112 |
108 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( | 113 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( |
109 profile_, app_id_, restart_reason); | 114 profile_, app_id_, restart_reason); |
110 } | 115 } |
111 | 116 |
112 void KioskAppUpdateService::WillDestroyAutomaticRebootManager() { | 117 void KioskAppUpdateService::WillDestroyAutomaticRebootManager() { |
113 automatic_reboot_manager_->RemoveObserver(this); | 118 automatic_reboot_manager_->RemoveObserver(this); |
114 automatic_reboot_manager_ = NULL; | 119 automatic_reboot_manager_ = NULL; |
115 } | 120 } |
116 | 121 |
| 122 void KioskAppUpdateService::OnKioskAppCacheUpdated(const std::string& app_id) { |
| 123 if (app_id != app_id_) |
| 124 return; |
| 125 |
| 126 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( |
| 127 profile_, |
| 128 app_id_, |
| 129 extensions::core_api::runtime::OnRestartRequired::REASON_APP_UPDATE); |
| 130 |
| 131 StartAppUpdateRestartTimer(); |
| 132 } |
| 133 |
117 KioskAppUpdateServiceFactory::KioskAppUpdateServiceFactory() | 134 KioskAppUpdateServiceFactory::KioskAppUpdateServiceFactory() |
118 : BrowserContextKeyedServiceFactory( | 135 : BrowserContextKeyedServiceFactory( |
119 "KioskAppUpdateService", | 136 "KioskAppUpdateService", |
120 BrowserContextDependencyManager::GetInstance()) { | 137 BrowserContextDependencyManager::GetInstance()) { |
121 DependsOn( | 138 DependsOn( |
122 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 139 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
123 } | 140 } |
124 | 141 |
125 KioskAppUpdateServiceFactory::~KioskAppUpdateServiceFactory() { | 142 KioskAppUpdateServiceFactory::~KioskAppUpdateServiceFactory() { |
126 } | 143 } |
(...skipping 16 matching lines...) Expand all Loading... |
143 } | 160 } |
144 | 161 |
145 KeyedService* KioskAppUpdateServiceFactory::BuildServiceInstanceFor( | 162 KeyedService* KioskAppUpdateServiceFactory::BuildServiceInstanceFor( |
146 content::BrowserContext* context) const { | 163 content::BrowserContext* context) const { |
147 return new KioskAppUpdateService( | 164 return new KioskAppUpdateService( |
148 Profile::FromBrowserContext(context), | 165 Profile::FromBrowserContext(context), |
149 g_browser_process->platform_part()->automatic_reboot_manager()); | 166 g_browser_process->platform_part()->automatic_reboot_manager()); |
150 } | 167 } |
151 | 168 |
152 } // namespace chromeos | 169 } // namespace chromeos |
OLD | NEW |