From 2f2ead2ced6aab065e045acc7aa7fe6994fdee44 Mon Sep 17 00:00:00 2001
From: "Piotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/Samsung Electronics"
Date: Tue, 28 Jul 2020 12:38:04 +0200
Subject: [PATCH] [Common] Added cache for JS privilege checking
Commit improves the performance of asking for application privileges.
Values are cached.
[Verification]
Code compiles without errors.
Privilege TCT passrate 100%
Change-Id: Id1772d9b14e4d4ff07e6a7ca0993027b98a4f2f4
---
src/utils/utils_api.js | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/utils/utils_api.js b/src/utils/utils_api.js
index 70424a53..6e4a3dfe 100644
--- a/src/utils/utils_api.js
+++ b/src/utils/utils_api.js
@@ -253,12 +253,17 @@ Utils.prototype.repackFilter = function(filter) {
return null;
};
+var apiVersion = null;
Utils.prototype.getPkgApiVersion = function() {
+ if (apiVersion) {
+ return apiVersion;
+ }
var result = native_.callSync('UtilsGetPkgApiVersion');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
- return native_.getResultObject(result);
+ apiVersion = native_.getResultObject(result);
+ return apiVersion;
};
var isPrivilege = function(toCheck) {
@@ -268,6 +273,7 @@ var isPrivilege = function(toCheck) {
return true;
};
+var cachedPrivileges = {};
Utils.prototype.checkPrivilegeAccess = function(privilege) {
if (!isPrivilege(privilege)) {
xwalk.utils.error(
@@ -276,11 +282,15 @@ Utils.prototype.checkPrivilegeAccess = function(privilege) {
throw new WebAPIException(WebAPIException.SECURITY_ERR);
}
+ if (cachedPrivileges[privilege]) {
+ return;
+ }
var result = native_.callSync('UtilsCheckPrivilegeAccess', {
privilege: _toString(privilege)
});
-
- if (native_.isFailure(result)) {
+ var isFailure = native_.isFailure(result);
+ cachedPrivileges[privilege] = !isFailure;
+ if (isFailure) {
throw native_.getErrorObject(result);
}
};
--
2.34.1