From: DongHyun Song Date: Wed, 14 Dec 2022 07:04:10 +0000 (+0900) Subject: Ignore TaskQueue::DeleteJobs when worker terminated X-Git-Tag: accepted/tizen/unified/20230202.015309~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3f743e319889eefce19e73b3d181232cde185368;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git Ignore TaskQueue::DeleteJobs when worker terminated From Tizen 7.0, tizen.ml is enabled in web worker. Because 'tizen' and 'xwalk' extensions are loaded on web worker. Global TaskQueue can be truncated at 'xwalk' instance is deleted. This singleton TaskQueue should be truncated when main JS context is destroyed, not by web worker. Change-Id: I078a7217622d107799a9a47786d1680db5bed5db Signed-off-by: DongHyun Song --- diff --git a/src/common/extension.h b/src/common/extension.h index 7e6cf3f1..6c5d9166 100644 --- a/src/common/extension.h +++ b/src/common/extension.h @@ -114,11 +114,17 @@ class Instance { virtual void HandleBinaryMessage(const char* msg, size_t size) = 0; virtual void HandleSyncBinaryMessage(const char* msg, size_t size) = 0; + virtual void SetWebWorker(bool worker) { + is_web_worker_ = worker; + } XW_Instance xw_instance() const { return xw_instance_; } + protected: + bool is_web_worker_ = false; + private: friend class Extension; diff --git a/src/utils/utils_api.js b/src/utils/utils_api.js index 7d184af3..f5809506 100644 --- a/src/utils/utils_api.js +++ b/src/utils/utils_api.js @@ -1734,6 +1734,9 @@ Utils.prototype.exportModuleIfFeatureSupported = exportModuleIfFeatureSupported; Utils.prototype.ArrayBufferParser = ArrayBufferParser; var native_ = new NativeManager(extension); +if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) { + native_.callSync('UtilsSetWorkerScope', {}); +} exports.utils = new Utils(); diff --git a/src/utils/utils_instance.cc b/src/utils/utils_instance.cc index e90f8b2a..65edc0d4 100644 --- a/src/utils/utils_instance.cc +++ b/src/utils/utils_instance.cc @@ -31,6 +31,7 @@ UtilsInstance::UtilsInstance() { REGISTER_METHOD(UtilsToLongLong); REGISTER_METHOD(UtilsToUnsignedLongLong); REGISTER_METHOD(UtilsCheckProfile); + REGISTER_METHOD(UtilsSetWorkerScope); #undef REGISTER_METHOD } @@ -129,5 +130,13 @@ void UtilsInstance::UtilsCheckProfile(const picojson::value& args, picojson::obj ReportSuccess(picojson::value(profile), out); } +void UtilsInstance::UtilsSetWorkerScope(const picojson::value& args, picojson::object& out) { + ScopeLogger(); + + SetWebWorker(true); + + ReportSuccess(picojson::value(true), out); +} + } // namespace utils } // namespace extension diff --git a/src/utils/utils_instance.h b/src/utils/utils_instance.h index 5708a922..71f013df 100644 --- a/src/utils/utils_instance.h +++ b/src/utils/utils_instance.h @@ -18,7 +18,9 @@ class UtilsInstance : public common::ParsedInstance { virtual ~UtilsInstance() { // At this point, frame of the page is destroyed or reloaded, so all the jobs have to be // removed. - common::TaskQueue::GetInstance().DeleteJobs(); + if (!is_webworker_) { + common::TaskQueue::GetInstance().DeleteJobs(); + } } private: @@ -30,6 +32,7 @@ class UtilsInstance : public common::ParsedInstance { void UtilsToLongLong(const picojson::value& args, picojson::object& out); void UtilsToUnsignedLongLong(const picojson::value& args, picojson::object& out); void UtilsCheckProfile(const picojson::value& args, picojson::object& out); + void UtilsSetWorkerScope(const picojson::value& args, picojson::object& out); }; } // namespace utils } // namespace extension