diff --git a/BUILD.gn b/BUILD.gn index f8c7cf9..badcb19 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -130,6 +130,7 @@ if (defined(ohos_lite)) { defines = [] public_configs = [ ":ace_napi_config" ] public_deps = [ "//third_party/libuv:uv" ] + deps = [] include_dirs = [ "//foundation/ace/napi", @@ -159,12 +160,16 @@ if (defined(ohos_lite)) { "hiviewdfx_hilog_native:libhilog", ] defines += [ "ENABLE_HITRACE" ] + if (product_name != "ohos-sdk") { + deps += [ "$ace_root/frameworks/core:ace_container_scope" ] + defines += [ "ENABLE_CONTAINER_SCOPE" ] + } } else { external_deps = [ "hilog:libhilog" ] } } - deps = [ + deps += [ "//third_party/libuv:uv", "//utils/native/base:utilsecurec", ] diff --git a/native_engine/native_async_work.cpp b/native_engine/native_async_work.cpp index 2fded24..8e4e319 100644 --- a/native_engine/native_async_work.cpp +++ b/native_engine/native_async_work.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -18,11 +18,18 @@ #ifdef ENABLE_HITRACE #include "hitrace/trace.h" #endif +#ifdef ENABLE_CONTAINER_SCOPE +#include "core/common/container_scope.h" +#endif #include "napi/native_api.h" #include "native_engine.h" #include "utils/log.h" +#ifdef ENABLE_CONTAINER_SCOPE +using OHOS::Ace::ContainerScope; +#endif + NativeAsyncWork::NativeAsyncWork(NativeEngine* engine, NativeAsyncExecuteCallback execute, NativeAsyncCompleteCallback complete, @@ -33,6 +40,9 @@ NativeAsyncWork::NativeAsyncWork(NativeEngine* engine, #ifdef ENABLE_HITRACE traceId_ = std::make_unique(OHOS::HiviewDFX::HiTrace::GetId()); #endif +#ifdef ENABLE_CONTAINER_SCOPE + containerScopeId_ = ContainerScope::CurrentId(); +#endif } NativeAsyncWork::~NativeAsyncWork() = default; @@ -125,6 +135,10 @@ void NativeAsyncWork::AsyncWorkCallback(uv_work_t* req) } auto that = reinterpret_cast(req->data); + +#ifdef ENABLE_CONTAINER_SCOPE + ContainerScope containerScope(that->containerScopeId_); +#endif #ifdef ENABLE_HITRACE if (that->traceId_ && that->traceId_->IsValid()) { OHOS::HiviewDFX::HiTrace::SetId(*(that->traceId_.get())); @@ -172,6 +186,9 @@ void NativeAsyncWork::AsyncAfterWorkCallback(uv_work_t* req, int status) default: nstatus = napi_generic_failure; } +#ifdef ENABLE_CONTAINER_SCOPE + ContainerScope containerScope(that->containerScopeId_); +#endif #ifdef ENABLE_HITRACE if (that->traceId_ && that->traceId_->IsValid()) { OHOS::HiviewDFX::HiTrace::SetId(*(that->traceId_.get())); diff --git a/native_engine/native_async_work.h b/native_engine/native_async_work.h index 884e147..3b0323e 100644 --- a/native_engine/native_async_work.h +++ b/native_engine/native_async_work.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -85,6 +85,9 @@ private: #ifdef ENABLE_HITRACE std::unique_ptr traceId_; #endif +#ifdef ENABLE_CONTAINER_SCOPE + int32_t containerScopeId_; +#endif }; #endif /* FOUNDATION_ACE_NAPI_NATIVE_ENGINE_NATIVE_ASYNC_WORK_H */