OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/app_mode/kiosk_external_update_validator.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/location.h" |
| 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "extensions/common/extension.h" |
| 11 #include "extensions/common/manifest_constants.h" |
| 12 |
| 13 namespace chromeos { |
| 14 |
| 15 KioskExternalUpdateValidator::KioskExternalUpdateValidator( |
| 16 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner, |
| 17 const std::string& app_id, |
| 18 const base::FilePath& crx_dir, |
| 19 const base::FilePath& crx_unpack_dir, |
| 20 const base::WeakPtr<KioskExternalUpdateValidatorDelegate>& delegate) |
| 21 : backend_task_runner_(backend_task_runner), |
| 22 app_id_(app_id), |
| 23 crx_dir_(crx_dir), |
| 24 crx_unpack_dir_(crx_unpack_dir), |
| 25 delegate_(delegate) { |
| 26 } |
| 27 |
| 28 KioskExternalUpdateValidator::~KioskExternalUpdateValidator() { |
| 29 } |
| 30 |
| 31 void KioskExternalUpdateValidator::Start() { |
| 32 scoped_refptr<extensions::SandboxedUnpacker> unpacker( |
| 33 new extensions::SandboxedUnpacker(crx_dir_, |
| 34 extensions::Manifest::EXTERNAL_PREF, |
| 35 extensions::Extension::NO_FLAGS, |
| 36 crx_unpack_dir_, |
| 37 backend_task_runner_.get(), |
| 38 this)); |
| 39 if (!backend_task_runner_->PostTask( |
| 40 FROM_HERE, |
| 41 base::Bind(&extensions::SandboxedUnpacker::Start, unpacker.get()))) { |
| 42 NOTREACHED(); |
| 43 } |
| 44 } |
| 45 |
| 46 void KioskExternalUpdateValidator::OnUnpackFailure( |
| 47 const base::string16& error_message) { |
| 48 LOG(ERROR) << "Failed to unpack external kiosk crx file: " << app_id_ << " " |
| 49 << error_message; |
| 50 content::BrowserThread::PostTask( |
| 51 content::BrowserThread::UI, |
| 52 FROM_HERE, |
| 53 base::Bind( |
| 54 &KioskExternalUpdateValidatorDelegate::OnExternalUpdateUnpackFailure, |
| 55 delegate_, |
| 56 app_id_)); |
| 57 } |
| 58 |
| 59 void KioskExternalUpdateValidator::OnUnpackSuccess( |
| 60 const base::FilePath& temp_dir, |
| 61 const base::FilePath& extension_dir, |
| 62 const base::DictionaryValue* original_manifest, |
| 63 const extensions::Extension* extension, |
| 64 const SkBitmap& install_icon) { |
| 65 DCHECK(app_id_ == extension->id()); |
| 66 |
| 67 std::string minimum_browser_version; |
| 68 if (!extension->manifest()->GetString( |
| 69 extensions::manifest_keys::kMinimumChromeVersion, |
| 70 &minimum_browser_version)) { |
| 71 LOG(ERROR) << "Can't find minimum browser version for app " << app_id_; |
| 72 minimum_browser_version.clear(); |
| 73 } |
| 74 |
| 75 content::BrowserThread::PostTask( |
| 76 content::BrowserThread::UI, |
| 77 FROM_HERE, |
| 78 base::Bind( |
| 79 &KioskExternalUpdateValidatorDelegate::OnExtenalUpdateUnpackSuccess, |
| 80 delegate_, |
| 81 app_id_, |
| 82 extension->VersionString(), |
| 83 minimum_browser_version, |
| 84 temp_dir)); |
| 85 } |
| 86 |
| 87 } // namespace chromeos |
OLD | NEW |