| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_external_updater.h" | 5 #include "chrome/browser/chromeos/app_mode/kiosk_external_updater.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
| 10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 void KioskExternalUpdater::ProcessParsedManifest( | 235 void KioskExternalUpdater::ProcessParsedManifest( |
| 236 ExternalUpdateErrorCode* parsing_error, | 236 ExternalUpdateErrorCode* parsing_error, |
| 237 const base::FilePath& external_update_dir, | 237 const base::FilePath& external_update_dir, |
| 238 base::DictionaryValue* parsed_manifest) { | 238 base::DictionaryValue* parsed_manifest) { |
| 239 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 239 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 240 | 240 |
| 241 if (*parsing_error == ERROR_NO_MANIFEST) { | 241 if (*parsing_error == ERROR_NO_MANIFEST) { |
| 242 NotifyKioskUpdateProgress( | 242 NotifyKioskUpdateProgress( |
| 243 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | 243 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
| 244 IDS_KIOSK_EXTERNAL_UPDATE_NO_MANIFEST)); | 244 IDS_KIOSK_EXTERNAL_UPDATE_NO_MANIFEST)); |
| 245 KioskAppManager::Get()->OnKioskAppExternalUpdateComplete(false); |
| 245 return; | 246 return; |
| 246 } else if (*parsing_error == ERROR_INVALID_MANIFEST) { | 247 } else if (*parsing_error == ERROR_INVALID_MANIFEST) { |
| 247 NotifyKioskUpdateProgress( | 248 NotifyKioskUpdateProgress( |
| 248 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | 249 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
| 249 IDS_KIOSK_EXTERNAL_UPDATE_INVALID_MANIFEST)); | 250 IDS_KIOSK_EXTERNAL_UPDATE_INVALID_MANIFEST)); |
| 251 KioskAppManager::Get()->OnKioskAppExternalUpdateComplete(false); |
| 250 return; | 252 return; |
| 251 } | 253 } |
| 252 | 254 |
| 253 external_update_path_ = external_update_dir; | 255 external_update_path_ = external_update_dir; |
| 254 for (base::DictionaryValue::Iterator it(*parsed_manifest); !it.IsAtEnd(); | 256 for (base::DictionaryValue::Iterator it(*parsed_manifest); !it.IsAtEnd(); |
| 255 it.Advance()) { | 257 it.Advance()) { |
| 256 std::string app_id = it.key(); | 258 std::string app_id = it.key(); |
| 257 std::string cached_version_str; | 259 std::string cached_version_str; |
| 258 base::FilePath cached_crx; | 260 base::FilePath cached_crx; |
| 259 if (!KioskAppManager::Get()->GetCachedCrx( | 261 if (!KioskAppManager::Get()->GetCachedCrx( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 } | 296 } |
| 295 update.external_crx = external_update_path_.AppendASCII(external_crx_str); | 297 update.external_crx = external_update_path_.AppendASCII(external_crx_str); |
| 296 update.update_status = PENDING; | 298 update.update_status = PENDING; |
| 297 external_updates_[app_id] = update; | 299 external_updates_[app_id] = update; |
| 298 } | 300 } |
| 299 | 301 |
| 300 if (external_updates_.empty()) { | 302 if (external_updates_.empty()) { |
| 301 NotifyKioskUpdateProgress( | 303 NotifyKioskUpdateProgress( |
| 302 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | 304 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
| 303 IDS_KIOSK_EXTERNAL_UPDATE_NO_UPDATES)); | 305 IDS_KIOSK_EXTERNAL_UPDATE_NO_UPDATES)); |
| 306 KioskAppManager::Get()->OnKioskAppExternalUpdateComplete(false); |
| 304 return; | 307 return; |
| 305 } | 308 } |
| 306 | 309 |
| 307 ValidateExternalUpdates(); | 310 ValidateExternalUpdates(); |
| 308 } | 311 } |
| 309 | 312 |
| 310 bool KioskExternalUpdater::CheckExternalUpdateInterrupted() { | 313 bool KioskExternalUpdater::CheckExternalUpdateInterrupted() { |
| 311 if (external_updates_.empty()) { | 314 if (external_updates_.empty()) { |
| 312 // This could happen if user pulls out the usb stick before the updating | 315 // This could happen if user pulls out the usb stick before the updating |
| 313 // operation is completed. | 316 // operation is completed. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 340 for (ExternalUpdateMap::iterator it = external_updates_.begin(); | 343 for (ExternalUpdateMap::iterator it = external_updates_.begin(); |
| 341 it != external_updates_.end(); | 344 it != external_updates_.end(); |
| 342 ++it) { | 345 ++it) { |
| 343 if (it->second.update_status == PENDING) { | 346 if (it->second.update_status == PENDING) { |
| 344 return true; | 347 return true; |
| 345 } | 348 } |
| 346 } | 349 } |
| 347 return false; | 350 return false; |
| 348 } | 351 } |
| 349 | 352 |
| 353 bool KioskExternalUpdater::IsAllExternalUpdatesSucceeded() { |
| 354 for (ExternalUpdateMap::iterator it = external_updates_.begin(); |
| 355 it != external_updates_.end(); |
| 356 ++it) { |
| 357 if (it->second.update_status != SUCCESS) { |
| 358 return false; |
| 359 } |
| 360 } |
| 361 return true; |
| 362 } |
| 363 |
| 350 bool KioskExternalUpdater::ShouldDoExternalUpdate( | 364 bool KioskExternalUpdater::ShouldDoExternalUpdate( |
| 351 const std::string& app_id, | 365 const std::string& app_id, |
| 352 const std::string& version, | 366 const std::string& version, |
| 353 const std::string& min_browser_version) { | 367 const std::string& min_browser_version) { |
| 354 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 368 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 355 | 369 |
| 356 std::string existing_version_str; | 370 std::string existing_version_str; |
| 357 base::FilePath existing_path; | 371 base::FilePath existing_path; |
| 358 bool cached = KioskAppManager::Get()->GetCachedCrx( | 372 bool cached = KioskAppManager::Get()->GetCachedCrx( |
| 359 app_id, &existing_path, &existing_version_str); | 373 app_id, &existing_path, &existing_version_str); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 else | 447 else |
| 434 MayBeNotifyKioskAppUpdate(); | 448 MayBeNotifyKioskAppUpdate(); |
| 435 } | 449 } |
| 436 | 450 |
| 437 void KioskExternalUpdater::MayBeNotifyKioskAppUpdate() { | 451 void KioskExternalUpdater::MayBeNotifyKioskAppUpdate() { |
| 438 if (IsExternalUpdatePending()) | 452 if (IsExternalUpdatePending()) |
| 439 return; | 453 return; |
| 440 | 454 |
| 441 NotifyKioskUpdateProgress(GetUpdateReportMessage()); | 455 NotifyKioskUpdateProgress(GetUpdateReportMessage()); |
| 442 NotifyKioskAppUpdateAvailable(); | 456 NotifyKioskAppUpdateAvailable(); |
| 457 KioskAppManager::Get()->OnKioskAppExternalUpdateComplete( |
| 458 IsAllExternalUpdatesSucceeded()); |
| 443 } | 459 } |
| 444 | 460 |
| 445 void KioskExternalUpdater::NotifyKioskAppUpdateAvailable() { | 461 void KioskExternalUpdater::NotifyKioskAppUpdateAvailable() { |
| 446 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 462 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 447 for (ExternalUpdateMap::iterator it = external_updates_.begin(); | 463 for (ExternalUpdateMap::iterator it = external_updates_.begin(); |
| 448 it != external_updates_.end(); | 464 it != external_updates_.end(); |
| 449 ++it) { | 465 ++it) { |
| 450 if (it->second.update_status == SUCCESS) { | 466 if (it->second.update_status == SUCCESS) { |
| 451 KioskAppManager::Get()->OnKioskAppCacheUpdated(it->first); | 467 KioskAppManager::Get()->OnKioskAppCacheUpdated(it->first); |
| 452 } | 468 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 if (failed) { | 524 if (failed) { |
| 509 failed_app_msg = ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | 525 failed_app_msg = ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
| 510 IDS_KIOSK_EXTERNAL_UPDATE_FAILED_UPDATED_APPS) + | 526 IDS_KIOSK_EXTERNAL_UPDATE_FAILED_UPDATED_APPS) + |
| 511 base::ASCIIToUTF16("\n") + failed_apps; | 527 base::ASCIIToUTF16("\n") + failed_apps; |
| 512 message = message + base::ASCIIToUTF16("\n") + failed_app_msg; | 528 message = message + base::ASCIIToUTF16("\n") + failed_app_msg; |
| 513 } | 529 } |
| 514 return message; | 530 return message; |
| 515 } | 531 } |
| 516 | 532 |
| 517 } // namespace chromeos | 533 } // namespace chromeos |
| OLD | NEW |