Upstream version 9.38.205.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / common / tizen / application_storage_impl.cc
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.
4
5 #include "xwalk/application/common/tizen/application_storage_impl.h"
6
7 #include <ail.h>
8 #include <pkgmgr-info.h>
9
10 #include <string>
11 #include <vector>
12
13 #include "base/file_util.h"
14 #include "third_party/re2/re2/re2.h"
15 #include "xwalk/application/common/application_file_util.h"
16 #include "xwalk/application/common/id_util.h"
17 #include "xwalk/application/common/tizen/application_storage.h"
18 #include "xwalk/application/common/tizen/package_path.h"
19
20 namespace {
21
22 ail_cb_ret_e appinfo_get_app_id_cb(
23     const ail_appinfo_h appinfo, void* user_data) {
24   std::vector<std::string>* app_ids =
25     static_cast<std::vector<std::string>*>(user_data);
26   char* app_id;
27   ail_appinfo_get_str(appinfo, AIL_PROP_X_SLP_APPID_STR, &app_id);
28   if (app_id)
29     app_ids->push_back(app_id);
30
31   return AIL_CB_RET_CONTINUE;
32 }
33
34 const char kXWalkPackageType[] = "wgt";
35
36 }  // namespace
37
38 namespace xwalk {
39 namespace application {
40
41 ApplicationStorageImpl::ApplicationStorageImpl(const base::FilePath& path) {
42 }
43
44 ApplicationStorageImpl::~ApplicationStorageImpl() {
45 }
46
47 bool ApplicationStorageImpl::Init() {
48   return true;
49 }
50
51 scoped_refptr<ApplicationData> ApplicationStorageImpl::GetApplicationData(
52     const std::string& app_id) {
53   base::FilePath app_path = GetApplicationPath(app_id);
54
55   std::string error_str;
56   return LoadApplication(
57       app_path, app_id, ApplicationData::INTERNAL, &error_str);
58 }
59
60 bool ApplicationStorageImpl::GetInstalledApplicationIDs(
61   std::vector<std::string>& app_ids) {  // NOLINT
62   ail_filter_h filter;
63   int count;
64   uid_t uid = getuid();
65
66   ail_error_e ret = ail_filter_new(&filter);
67   if (ret != AIL_ERROR_OK) {
68     LOG(ERROR) << "Failed to create AIL filter.";
69     return false;
70   }
71   // Filters out web apps (installed from WGT and XPK packages).
72   ret = ail_filter_add_str(
73       filter, AIL_PROP_X_SLP_PACKAGETYPE_STR, kXWalkPackageType);
74   if (ret != AIL_ERROR_OK) {
75     LOG(ERROR) << "Failed to init AIL filter.";
76     ail_filter_destroy(filter);
77     return false;
78   }
79
80   if (uid != GLOBAL_USER)
81     ret = ail_filter_count_usr_appinfo(filter, &count, uid);
82   else
83     ret = ail_filter_count_appinfo(filter, &count);
84
85   if (ret != AIL_ERROR_OK) {
86     LOG(ERROR) << "Failed to count AIL app info.";
87     ail_filter_destroy(filter);
88     return false;
89   }
90
91   if (count > 0) {
92     if (uid != GLOBAL_USER)
93       ail_filter_list_usr_appinfo_foreach(filter, appinfo_get_app_id_cb,
94           &app_ids, uid);
95     else
96       ail_filter_list_appinfo_foreach(filter, appinfo_get_app_id_cb, &app_ids);
97   }
98
99   ail_filter_destroy(filter);
100   return true;
101 }
102
103 bool ApplicationStorageImpl::AddApplication(const ApplicationData* application,
104                                             const base::Time& install_time) {
105   return true;
106 }
107
108 bool ApplicationStorageImpl::UpdateApplication(
109     ApplicationData* application, const base::Time& install_time) {
110   return true;
111 }
112
113 bool ApplicationStorageImpl::RemoveApplication(const std::string& id) {
114   return true;
115 }
116
117 bool ApplicationStorageImpl::ContainsApplication(const std::string& app_id) {
118   return !GetApplicationPath(app_id).empty();
119 }
120
121 }  // namespace application
122 }  // namespace xwalk