1 // Copyright (c) 2013 Intel Corporation. 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 XWALK_APPLICATION_COMMON_PACKAGE_PACKAGE_H_
6 #define XWALK_APPLICATION_COMMON_PACKAGE_PACKAGE_H_
11 #include "base/files/file_path.h"
12 #include "base/files/scoped_file.h"
13 #include "base/files/scoped_temp_dir.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "xwalk/application/common/manifest.h"
18 namespace application {
20 // Base class for all types of packages (right now .wgt and .xpk)
21 // The actual zip file, id, is_valid_, source_path_ are common in all packages
22 // specifics like signature checking for XPK are taken care of in
23 // XPKPackage::Validate()
27 bool IsValid() const { return is_valid_; }
28 const std::string& Id() const { return id_; }
29 const std::string& name() const { return name_; }
30 // Returns the type of the manifest which the package contains.
31 Manifest::Type manifest_type() const { return manifest_type_; }
32 // Factory method for creating a package
33 static scoped_ptr<Package> Create(const base::FilePath& path);
34 // The function will unzip the XPK/WGT file and return the target path where
35 // to decompress by the parameter |target_path|.
36 virtual bool ExtractToTemporaryDir(base::FilePath* result_path);
37 // The function will unzip the XPK/WGT file to the given folder.
38 virtual bool ExtractTo(const base::FilePath& target_path);
41 explicit Package(const base::FilePath& source_path);
42 // Unzipping of the zipped file happens in a temporary directory
43 bool CreateTempDirectory();
44 scoped_ptr<base::ScopedFILE> file_;
47 base::FilePath source_path_;
50 // Temporary directory for unpacking.
51 base::ScopedTempDir temp_dir_;
52 // Represent if the package has been extracted.
54 Manifest::Type manifest_type_;
57 } // namespace application
60 #endif // XWALK_APPLICATION_COMMON_PACKAGE_PACKAGE_H_