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.
5 #include "chrome/browser/chromeos/app_mode/kiosk_external_update_validator.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"
15 KioskExternalUpdateValidator::KioskExternalUpdateValidator(
16 const scoped_refptr
<base::SequencedTaskRunner
>& backend_task_runner
,
17 const extensions::CRXFileInfo
& file
,
18 const base::FilePath
& crx_unpack_dir
,
19 const base::WeakPtr
<KioskExternalUpdateValidatorDelegate
>& delegate
)
20 : backend_task_runner_(backend_task_runner
),
22 crx_unpack_dir_(crx_unpack_dir
),
26 KioskExternalUpdateValidator::~KioskExternalUpdateValidator() {
29 void KioskExternalUpdateValidator::Start() {
30 scoped_refptr
<extensions::SandboxedUnpacker
> unpacker(
31 new extensions::SandboxedUnpacker(
32 extensions::Manifest::EXTERNAL_PREF
, extensions::Extension::NO_FLAGS
,
33 crx_unpack_dir_
, backend_task_runner_
.get(), this));
34 if (!backend_task_runner_
->PostTask(
35 FROM_HERE
, base::Bind(&extensions::SandboxedUnpacker::StartWithCrx
,
36 unpacker
.get(), crx_file_
))) {
41 void KioskExternalUpdateValidator::OnUnpackFailure(
42 const extensions::CrxInstallError
& error
) {
43 LOG(ERROR
) << "Failed to unpack external kiosk crx file: "
44 << crx_file_
.extension_id
<< " " << error
.message();
45 content::BrowserThread::PostTask(
46 content::BrowserThread::UI
, FROM_HERE
,
48 &KioskExternalUpdateValidatorDelegate::OnExternalUpdateUnpackFailure
,
49 delegate_
, crx_file_
.extension_id
));
52 void KioskExternalUpdateValidator::OnUnpackSuccess(
53 const base::FilePath
& temp_dir
,
54 const base::FilePath
& extension_dir
,
55 const base::DictionaryValue
* original_manifest
,
56 const extensions::Extension
* extension
,
57 const SkBitmap
& install_icon
) {
58 DCHECK(crx_file_
.extension_id
== extension
->id());
60 std::string minimum_browser_version
;
61 if (!extension
->manifest()->GetString(
62 extensions::manifest_keys::kMinimumChromeVersion
,
63 &minimum_browser_version
)) {
64 LOG(ERROR
) << "Can't find minimum browser version for app "
65 << crx_file_
.extension_id
;
66 minimum_browser_version
.clear();
69 content::BrowserThread::PostTask(
70 content::BrowserThread::UI
, FROM_HERE
,
72 &KioskExternalUpdateValidatorDelegate::OnExtenalUpdateUnpackSuccess
,
73 delegate_
, crx_file_
.extension_id
, extension
->VersionString(),
74 minimum_browser_version
, temp_dir
));
77 } // namespace chromeos