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 crx_file_
, extensions::Manifest::EXTERNAL_PREF
,
33 extensions::Extension::NO_FLAGS
, crx_unpack_dir_
,
34 backend_task_runner_
.get(), this));
35 if (!backend_task_runner_
->PostTask(
37 base::Bind(&extensions::SandboxedUnpacker::Start
, unpacker
.get()))) {
42 void KioskExternalUpdateValidator::OnUnpackFailure(
43 const extensions::CrxInstallError
& error
) {
44 LOG(ERROR
) << "Failed to unpack external kiosk crx file: "
45 << crx_file_
.extension_id
<< " " << error
.message();
46 content::BrowserThread::PostTask(
47 content::BrowserThread::UI
, FROM_HERE
,
49 &KioskExternalUpdateValidatorDelegate::OnExternalUpdateUnpackFailure
,
50 delegate_
, crx_file_
.extension_id
));
53 void KioskExternalUpdateValidator::OnUnpackSuccess(
54 const base::FilePath
& temp_dir
,
55 const base::FilePath
& extension_dir
,
56 const base::DictionaryValue
* original_manifest
,
57 const extensions::Extension
* extension
,
58 const SkBitmap
& install_icon
) {
59 DCHECK(crx_file_
.extension_id
== extension
->id());
61 std::string minimum_browser_version
;
62 if (!extension
->manifest()->GetString(
63 extensions::manifest_keys::kMinimumChromeVersion
,
64 &minimum_browser_version
)) {
65 LOG(ERROR
) << "Can't find minimum browser version for app "
66 << crx_file_
.extension_id
;
67 minimum_browser_version
.clear();
70 content::BrowserThread::PostTask(
71 content::BrowserThread::UI
, FROM_HERE
,
73 &KioskExternalUpdateValidatorDelegate::OnExtenalUpdateUnpackSuccess
,
74 delegate_
, crx_file_
.extension_id
, extension
->VersionString(),
75 minimum_browser_version
, temp_dir
));
78 } // namespace chromeos