Fix invalid licenses
[platform/framework/web/crosswalk-tizen.git] / src / common / resource_manager.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #ifndef WRT_COMMON_RESOURCE_MANAGER_H_
18 #define WRT_COMMON_RESOURCE_MANAGER_H_
19
20 #include <string>
21 #include <map>
22 #include <memory>
23
24 namespace wgt {
25
26 namespace parse {
27
28 class AppControlInfo;
29
30 }  // namespace parse
31
32 }  // namespace wgt
33
34 namespace wrt {
35
36 class ApplicationData;
37 class LocaleManager;
38 class AppControl;
39
40 class ResourceManager {
41  public:
42   class Resource {
43    public:
44     explicit Resource(const std::string& uri);
45     Resource(const std::string& uri, const std::string& mime);
46     Resource(const std::string& uri, const std::string& mime,
47              bool should_reset);
48     Resource(const Resource& res);
49     ~Resource() {}
50
51     Resource& operator=(const Resource& res);
52     bool operator==(const Resource& res);
53
54     void set_uri(const std::string& uri) { uri_ = uri; }
55     void set_mime(const std::string& mime) { mime_ = mime; }
56     void set_should_reset(bool should_reset) { should_reset_ = should_reset; }
57
58     std::string uri() const { return uri_; }
59     std::string mime() const { return mime_; }
60     bool should_reset() const { return should_reset_; }
61
62    private:
63     std::string uri_;
64     std::string mime_;
65     bool should_reset_;
66   };
67
68   ResourceManager(ApplicationData* application_data,
69                   LocaleManager* locale_manager);
70   ~ResourceManager() {}
71
72   // input : file:///..... , app://[appid]/....
73   // output : /[system path]/.../locales/.../
74   std::string GetLocalizedPath(const std::string& origin);
75   std::unique_ptr<Resource> GetStartResource(const AppControl* app_control);
76
77   void set_base_resource_path(const std::string& base_path);
78
79  private:
80   std::string GetMatchedSrcOrUri(const wgt::parse::AppControlInfo&);
81   std::string GetDefaultOrEmpty();
82   // for localization
83   bool Exists(const std::string& path);
84
85   std::string resource_base_path_;
86   std::string appid_;
87   std::map<const std::string, bool> file_existed_cache_;
88   std::map<const std::string, std::string> locale_cache_;
89
90   ApplicationData* application_data_;
91   LocaleManager* locale_manager_;
92 };
93
94 }  // namespace wrt
95
96 #endif  // WRT_COMMON_RESOURCE_MANAGER_H_