[WRTjs] Refactor popup
[platform/framework/web/chromium-efl.git] / wrt / src / browser / wrt_quota_permission_context.cc
1 #include "wrt/src/browser/wrt_quota_permission_context.h"
2
3 #if BUILDFLAG(IS_TIZEN_TV)
4 #include <tzplatform_config.h>
5
6 #include "base/files/file_path.h"
7 #include "base/system/sys_info.h"
8 #include "wrt/src/base/platform_info.h"
9 #include "wrt/src/common/privilege.h"
10 #endif
11
12 namespace wrt {
13
14 namespace {
15
16 #if BUILDFLAG(IS_TIZEN_TV)
17 const char* kStoragePrivilege = "http://tizen.org/privilege/unlimitedstorage";
18
19 bool IsOverThanHalfFreeSpace(
20     int64_t requested_size) {
21   base::FilePath tz_sys_user(tzplatform_getenv(TZ_SYS_USER));
22   int64_t available = base::SysInfo::AmountOfFreeDiskSpace(tz_sys_user);
23   available /= 2;
24
25   LOG(INFO) << "requested_size : " << requested_size
26             << ", available : " << available;
27   if (requested_size > available)
28     return true;
29   else
30     return false;
31 }
32 #endif
33
34 }  // namespace
35
36 WRTQuotaPermissionContext::WRTQuotaPermissionContext() {}
37
38 WRTQuotaPermissionContext::~WRTQuotaPermissionContext() {}
39
40 void WRTQuotaPermissionContext::RequestQuotaPermission(
41     const content::StorageQuotaParams& params,
42     int render_process_id,
43     PermissionCallback callback) {
44 #if BUILDFLAG(IS_TIZEN_TV)
45   if (privilege::FindPrivilegeFromConfig(kStoragePrivilege)) {
46     if (HasLimitQuotaPermission() &&
47         IsOverThanHalfFreeSpace(params.requested_size))
48       std::move(callback).Run(QUOTA_PERMISSION_RESPONSE_DISALLOW);
49     else
50       std::move(callback).Run(QUOTA_PERMISSION_RESPONSE_ALLOW);
51   } else
52 #endif
53     std::move(callback).Run(QUOTA_PERMISSION_RESPONSE_CANCELLED);
54 }
55
56 }  // namespace wrt