1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_
6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_
11 #include "base/basictypes.h"
12 #include "base/files/file_path.h"
13 #include "base/json/json_file_value_serializer.h"
14 #include "base/memory/scoped_ptr.h"
16 namespace component_updater {
18 class ComponentInstaller;
19 class ComponentPatcher;
21 // Deserializes the CRX manifest. The top level must be a dictionary.
22 scoped_ptr<base::DictionaryValue> ReadManifest(
23 const base::FilePath& unpack_path);
25 // In charge of unpacking the component CRX package and verifying that it is
26 // well formed and the cryptographic signature is correct. If there is no
27 // error the component specific installer will be invoked to proceed with
28 // the component installation or update.
30 // This class should be used only by the component updater. It is inspired
31 // and overlaps with code in the extension's SandboxedUnpacker.
32 // The main differences are:
33 // - The public key hash is full SHA256.
34 // - Does not use a sandboxed unpacker. A valid component is fully trusted.
35 // - The manifest can have different attributes and resources are not
37 class ComponentUnpacker {
39 // Possible error conditions.
40 // Add only to the bottom of this enum; the order must be kept stable.
53 kDeltaVerificationFailure,
55 kDeltaUnsupportedCommand,
56 kDeltaOperationFailure,
57 kDeltaPatchProcessFailure,
58 kDeltaMissingExistingFile,
59 kFingerprintWriteFailed,
61 // Unpacks, verifies and calls the installer. |pk_hash| is the expected
62 // public key SHA256 hash. |path| is the current location of the CRX.
63 ComponentUnpacker(const std::vector<uint8>& pk_hash,
64 const base::FilePath& path,
65 const std::string& fingerprint,
66 ComponentPatcher* patcher,
67 ComponentInstaller* installer);
69 // If something went wrong during unpacking or installer invocation, the
70 // destructor will delete the unpacked CRX files.
73 Error error() const { return error_; }
75 int extended_error() const { return extended_error_; }
78 base::FilePath unpack_path_;
80 int extended_error_; // Provides additional error information.
83 } // namespace component_updater
85 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_