Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: chrome/browser/chromeos/app_mode/kiosk_app_update_service.cc

Issue 727363002: Fire notifications when reboot is requested, not scheduled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@managed_cros
Patch Set: Add missing run_loop.Run(); Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 16 matching lines...) Expand all
27 // How low to wait after an update is available before we force a restart. 27 // How low to wait after an update is available before we force a restart.
28 const int kForceRestartWaitTimeMs = 24 * 3600 * 1000; // 24 hours. 28 const int kForceRestartWaitTimeMs = 24 * 3600 * 1000; // 24 hours.
29 29
30 } // namespace 30 } // namespace
31 31
32 KioskAppUpdateService::KioskAppUpdateService( 32 KioskAppUpdateService::KioskAppUpdateService(
33 Profile* profile, 33 Profile* profile,
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 }
38
39 KioskAppUpdateService::~KioskAppUpdateService() {
40 }
41
42 void KioskAppUpdateService::Init(const std::string& app_id) {
43 DCHECK(app_id_.empty());
44 app_id_ = app_id;
45
37 ExtensionService* service = 46 ExtensionService* service =
38 extensions::ExtensionSystem::Get(profile_)->extension_service(); 47 extensions::ExtensionSystem::Get(profile_)->extension_service();
39 if (service) 48 if (service)
40 service->AddUpdateObserver(this); 49 service->AddUpdateObserver(this);
41 50
42 if (automatic_reboot_manager_) 51 if (automatic_reboot_manager_)
43 automatic_reboot_manager_->AddObserver(this); 52 automatic_reboot_manager_->AddObserver(this);
44 53
45 if (KioskAppManager::Get()) 54 if (KioskAppManager::Get())
46 KioskAppManager::Get()->AddObserver(this); 55 KioskAppManager::Get()->AddObserver(this);
47 }
48 56
49 KioskAppUpdateService::~KioskAppUpdateService() { 57 if (automatic_reboot_manager_->reboot_requested())
58 OnRebootRequested(automatic_reboot_manager_->reboot_reason());
50 } 59 }
51 60
52 void KioskAppUpdateService::StartAppUpdateRestartTimer() { 61 void KioskAppUpdateService::StartAppUpdateRestartTimer() {
53 if (restart_timer_.IsRunning()) 62 if (restart_timer_.IsRunning())
54 return; 63 return;
55 64
56 // Setup timer to force restart once the wait period expires. 65 // Setup timer to force restart once the wait period expires.
57 restart_timer_.Start( 66 restart_timer_.Start(
58 FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs), 67 FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs),
59 this, &KioskAppUpdateService::ForceAppUpdateRestart); 68 this, &KioskAppUpdateService::ForceAppUpdateRestart);
60 } 69 }
61 70
62 void KioskAppUpdateService::ForceAppUpdateRestart() { 71 void KioskAppUpdateService::ForceAppUpdateRestart() {
63 // Force a chrome restart (not a logout or reboot) by closing all browsers. 72 // Force a chrome restart (not a logout or reboot) by closing all browsers.
64 LOG(WARNING) << "Force closing all browsers to update kiosk app."; 73 LOG(WARNING) << "Force closing all browsers to update kiosk app.";
65 chrome::CloseAllBrowsersAndQuit(); 74 chrome::CloseAllBrowsersAndQuit();
66 } 75 }
67 76
68 void KioskAppUpdateService::Shutdown() { 77 void KioskAppUpdateService::Shutdown() {
69 ExtensionService* service = 78 ExtensionService* service =
70 extensions::ExtensionSystem::Get(profile_)->extension_service(); 79 extensions::ExtensionSystem::Get(profile_)->extension_service();
71 if (service) 80 if (service)
72 service->RemoveUpdateObserver(this); 81 service->RemoveUpdateObserver(this);
73 if (KioskAppManager::Get()) 82 if (KioskAppManager::Get())
74 KioskAppManager::Get()->RemoveObserver(this); 83 KioskAppManager::Get()->RemoveObserver(this);
84 if (automatic_reboot_manager_)
85 automatic_reboot_manager_->RemoveObserver(this);
75 } 86 }
76 87
77 void KioskAppUpdateService::OnAppUpdateAvailable( 88 void KioskAppUpdateService::OnAppUpdateAvailable(
78 const extensions::Extension* extension) { 89 const extensions::Extension* extension) {
79 if (extension->id() != app_id_) 90 if (extension->id() != app_id_)
80 return; 91 return;
81 92
82 // Clears cached app data so that it will be reloaded if update from app 93 // Clears cached app data so that it will be reloaded if update from app
83 // does not finish in this run. 94 // does not finish in this run.
84 KioskAppManager::Get()->ClearAppData(app_id_); 95 KioskAppManager::Get()->ClearAppData(app_id_);
85 KioskAppManager::Get()->UpdateAppDataFromProfile( 96 KioskAppManager::Get()->UpdateAppDataFromProfile(
86 app_id_, profile_, extension); 97 app_id_, profile_, extension);
87 98
88 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( 99 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent(
89 profile_, 100 profile_,
90 app_id_, 101 app_id_,
91 extensions::core_api::runtime::OnRestartRequired::REASON_APP_UPDATE); 102 extensions::core_api::runtime::OnRestartRequired::REASON_APP_UPDATE);
92 103
93 StartAppUpdateRestartTimer(); 104 StartAppUpdateRestartTimer();
94 } 105 }
95 106
96 void KioskAppUpdateService::OnRebootScheduled(Reason reason) { 107 void KioskAppUpdateService::OnRebootRequested(Reason reason) {
97 extensions::core_api::runtime::OnRestartRequired::Reason restart_reason = 108 extensions::core_api::runtime::OnRestartRequired::Reason restart_reason =
98 extensions::core_api::runtime::OnRestartRequired::REASON_NONE; 109 extensions::core_api::runtime::OnRestartRequired::REASON_NONE;
99 switch (reason) { 110 switch (reason) {
100 case REBOOT_REASON_OS_UPDATE: 111 case REBOOT_REASON_OS_UPDATE:
101 restart_reason = 112 restart_reason =
102 extensions::core_api::runtime::OnRestartRequired::REASON_OS_UPDATE; 113 extensions::core_api::runtime::OnRestartRequired::REASON_OS_UPDATE;
103 break; 114 break;
104 case REBOOT_REASON_PERIODIC: 115 case REBOOT_REASON_PERIODIC:
105 restart_reason = 116 restart_reason =
106 extensions::core_api::runtime::OnRestartRequired::REASON_PERIODIC; 117 extensions::core_api::runtime::OnRestartRequired::REASON_PERIODIC;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } 171 }
161 172
162 KeyedService* KioskAppUpdateServiceFactory::BuildServiceInstanceFor( 173 KeyedService* KioskAppUpdateServiceFactory::BuildServiceInstanceFor(
163 content::BrowserContext* context) const { 174 content::BrowserContext* context) const {
164 return new KioskAppUpdateService( 175 return new KioskAppUpdateService(
165 Profile::FromBrowserContext(context), 176 Profile::FromBrowserContext(context),
166 g_browser_process->platform_part()->automatic_reboot_manager()); 177 g_browser_process->platform_part()->automatic_reboot_manager());
167 } 178 }
168 179
169 } // namespace chromeos 180 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698