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