1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_RECORDER_EXPOSURE_PROCESSOR_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_RECORDER_EXPOSURE_PROCESSOR_H 18 19 #include <string> 20 21 #include "base/memory/ace_type.h" 22 #include "core/common/recorder/event_config.h" 23 24 namespace OHOS::Ace::Recorder { 25 constexpr char ORIGIN_PARAM[] = "$origin"; 26 constexpr char EXPOSURE_CONFIG_PARAM[] = "$exposureCfg"; 27 constexpr char EXPOSURE_CONFIG_RATIO[] = "ratio"; 28 constexpr char EXPOSURE_CONFIG_DURATION[] = "duration"; 29 30 class ExposureProcessor : public AceType { 31 DECLARE_ACE_TYPE(ExposureProcessor, AceType); 32 33 public: 34 ExposureProcessor(const std::string& pageUrl, const std::string& inspectorId); 35 ExposureProcessor(const std::string& pageUrl, const std::string& inspectorId, double ratio, int duration); 36 explicit ExposureProcessor(const RefPtr<ExposureProcessor>& processor); 37 ~ExposureProcessor() = default; 38 39 bool IsNeedRecord() const; 40 41 double GetRatio() const; 42 43 void OnVisibleChange(bool isVisible, const std::string& param = ""); 44 SetContainerId(int32_t id)45 void SetContainerId(int32_t id) 46 { 47 containerId_ = id; 48 } 49 GetContainerId()50 int32_t GetContainerId() const 51 { 52 return containerId_; 53 } 54 SetListenState(bool state)55 void SetListenState(bool state) 56 { 57 isListening_ = state; 58 } 59 isListening()60 bool isListening() const 61 { 62 return isListening_; 63 } 64 65 private: 66 ExposureCfg cfg_ = { "", 0.0, 0 }; 67 int64_t startTime_ = -1; 68 69 int32_t containerId_ = -1; 70 71 std::string pageUrl_; 72 std::string navDstName_; 73 74 bool isListening_ = false; 75 76 ACE_DISALLOW_COPY_AND_MOVE(ExposureProcessor); 77 }; 78 } // namespace OHOS::Ace::Recorder 79 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_RECORDER_EXPOSURE_PROCESSOR_H 80