Chromium Code Reviews| Index: chrome/browser/chromeos/app_mode/kiosk_external_update_validator.cc |
| diff --git a/chrome/browser/chromeos/app_mode/kiosk_external_update_validator.cc b/chrome/browser/chromeos/app_mode/kiosk_external_update_validator.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2d44e1674ea2794d07ab02c78cf89464ab0e2960 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/app_mode/kiosk_external_update_validator.cc |
| @@ -0,0 +1,86 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/app_mode/kiosk_external_update_validator.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/location.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "extensions/common/extension.h" |
| +#include "extensions/common/manifest_constants.h" |
| + |
| +namespace chromeos { |
| + |
| +KioskExternalUpdateValidator::KioskExternalUpdateValidator( |
| + const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner, |
| + const std::string& app_id, |
| + const base::FilePath& crx_dir, |
| + const base::FilePath& crx_unpack_dir, |
| + base::WeakPtr<KioskExternalUpdateValidatorDelegate> delegate) |
| + : backend_task_runner_(backend_task_runner), |
| + app_id_(app_id), |
| + crx_dir_(crx_dir), |
| + crx_unpack_dir_(crx_unpack_dir), |
| + delegate_(delegate) { |
| +} |
| + |
| +KioskExternalUpdateValidator::~KioskExternalUpdateValidator() { |
| +} |
| + |
| +void KioskExternalUpdateValidator::Start() { |
| + scoped_refptr<extensions::SandboxedUnpacker> unpacker( |
| + new extensions::SandboxedUnpacker(crx_dir_, |
| + extensions::Manifest::EXTERNAL_PREF, |
| + extensions::Extension::NO_FLAGS, |
| + crx_unpack_dir_, |
| + backend_task_runner_.get(), |
| + this)); |
| + if (!backend_task_runner_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&extensions::SandboxedUnpacker::Start, unpacker.get()))) { |
| + NOTREACHED(); |
| + } |
| +} |
| + |
| +void KioskExternalUpdateValidator::OnUnpackFailure( |
| + const base::string16& error_message) { |
| + LOG(ERROR) << "Failed to unpack external kiosk crx file: " << app_id_ << " " |
| + << error_message; |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind( |
| + &KioskExternalUpdateValidatorDelegate::OnExternalUpdateUnpackFailure, |
| + delegate_, |
| + app_id_)); |
| +} |
| + |
| +void KioskExternalUpdateValidator::OnUnpackSuccess( |
| + const base::FilePath& temp_dir, |
| + const base::FilePath& extension_dir, |
| + const base::DictionaryValue* original_manifest, |
| + const extensions::Extension* extension, |
| + const SkBitmap& install_icon) { |
| + DCHECK(app_id_ == extension->id()); |
| + |
| + std::string minimum_browser_version; |
| + if (!extension->manifest()->GetString( |
| + extensions::manifest_keys::kMinimumChromeVersion, |
| + &minimum_browser_version)) { |
| + LOG(ERROR) << "Can't find minimum browser version for app " << app_id_; |
|
xiyuan
2014/08/27 16:17:02
nit: minimum_browser_version.clear() to make sure
jennyz
2014/08/28 22:41:06
Done.
|
| + } |
| + |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind( |
| + &KioskExternalUpdateValidatorDelegate::OnExtenalUpdateUnpackSuccess, |
| + delegate_, |
| + app_id_, |
| + extension->VersionString(), |
| + minimum_browser_version, |
| + temp_dir)); |
| +} |
| + |
| +} // namespace chromeos |