1 /* 2 * Copyright (c) 2022 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 TOKEN_MODIFY_NOTIFIER_H 17 #define TOKEN_MODIFY_NOTIFIER_H 18 19 #include <atomic> 20 #include <set> 21 #include <vector> 22 23 #include "access_token.h" 24 #include "nocopyable.h" 25 #include "rwlock.h" 26 #ifndef RESOURCESCHEDULE_FFRT_ENABLE 27 #include "thread_pool.h" 28 #endif 29 30 namespace OHOS { 31 namespace Security { 32 namespace AccessToken { 33 class TokenModifyNotifier final { 34 public: 35 static TokenModifyNotifier& GetInstance(); 36 ~TokenModifyNotifier(); 37 void AddHapTokenObservation(AccessTokenID tokenID); 38 void NotifyTokenDelete(AccessTokenID tokenID); 39 void NotifyTokenModify(AccessTokenID tokenID); 40 void NotifyTokenChangedIfNeed(); 41 void NotifyTokenSyncTask(); 42 43 #ifdef RESOURCESCHEDULE_FFRT_ENABLE 44 int32_t GetCurTaskNum(); 45 void AddCurTaskNum(); 46 void ReduceCurTaskNum(); 47 #endif 48 49 private: 50 TokenModifyNotifier(); 51 DISALLOW_COPY_AND_MOVE(TokenModifyNotifier); 52 53 bool hasInited_; 54 OHOS::Utils::RWLock initLock_; 55 OHOS::Utils::RWLock Notifylock_; 56 #ifdef RESOURCESCHEDULE_FFRT_ENABLE 57 std::atomic_int32_t curTaskNum_; 58 #else 59 OHOS::ThreadPool notifyTokenWorker_; 60 #endif 61 std::set<AccessTokenID> observationSet_; 62 std::vector<AccessTokenID> deleteTokenList_; 63 std::vector<AccessTokenID> modifiedTokenList_; 64 }; 65 } // namespace AccessToken 66 } // namespace Security 67 } // namespace OHOS 68 #endif // TOKEN_MODIFY_NOTIFIER_H 69