c413ee86fad09bb92c5a7620cc7fe9688320fce7
[platform/framework/web/crosswalk.git] / src / xwalk / application / common / application_file_util.h
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.
4
5 #ifndef XWALK_APPLICATION_COMMON_APPLICATION_FILE_UTIL_H_
6 #define XWALK_APPLICATION_COMMON_APPLICATION_FILE_UTIL_H_
7
8 #include <string>
9 #include <map>
10
11 #include "base/memory/ref_counted.h"
12 #include "xwalk/application/common/installer/package.h"
13 #include "xwalk/application/common/manifest.h"
14
15
16 class GURL;
17
18 namespace base {
19 class DictionaryValue;
20 class FilePath;
21 }
22
23 // Utilities for manipulating the on-disk storage of applications.
24 namespace xwalk {
25 namespace application {
26
27 class ApplicationData;
28
29 class FileDeleter {
30  public:
31   FileDeleter(const base::FilePath& path, bool recursive);
32   ~FileDeleter();
33
34   void Dismiss() { path_.clear(); }
35   const base::FilePath& path() const { return path_; }
36
37  private:
38   base::FilePath path_;
39   bool recursive_;
40 };
41
42 // Loads and validates an application from the specified directory. Returns NULL
43 // on failure, with a description of the error in |error|.
44 scoped_refptr<ApplicationData> LoadApplication(
45     const base::FilePath& application_root,
46     Manifest::SourceType source_type,
47     std::string* error);
48
49 // The same as LoadApplication except use the provided |application_id|.
50 scoped_refptr<ApplicationData> LoadApplication(
51     const base::FilePath& application_root,
52     const std::string& application_id,
53     Manifest::SourceType source_type,
54     std::string* error);
55
56 scoped_refptr<ApplicationData> LoadApplication(
57     const base::FilePath& application_root,
58     const std::string& application_id,
59     Manifest::SourceType source_type,
60     Package::Type package_type,
61     std::string* error);
62
63 // Loads an application manifest from the specified directory. Returns NULL
64 // on failure, with a description of the error in |error|.
65 base::DictionaryValue* LoadManifest(const base::FilePath& application_root,
66                                     Package::Type package_type,
67                                     std::string* error);
68
69 // Get a relative file path from an app:// URL.
70 base::FilePath ApplicationURLToRelativeFilePath(const GURL& url);
71
72 }  // namespace application
73 }  // namespace xwalk
74
75 #endif  // XWALK_APPLICATION_COMMON_APPLICATION_FILE_UTIL_H_