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