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 #ifndef DISTRIBUTEDDATAMGR_ACCOUNT_DELEGATE_NORMAL_IMPL_H
16 #define DISTRIBUTEDDATAMGR_ACCOUNT_DELEGATE_NORMAL_IMPL_H
17 
18 #include "account_delegate_impl.h"
19 #include "common_event_manager.h"
20 #include "common_event_subscriber.h"
21 #include "common_event_support.h"
22 #include "executor_pool.h"
23 #include "log_print.h"
24 
25 namespace OHOS {
26 namespace DistributedKv {
27 class AccountDelegateNormalImpl final : public AccountDelegateImpl {
28 public:
29     std::string GetCurrentAccountId() const override;
30     int32_t GetUserByToken(uint32_t tokenId) const override;
31     bool QueryUsers(std::vector<int> &users) override;
32     bool QueryForegroundUsers(std::vector<int> &users) override;
33     bool IsLoginAccount() override;
34     bool IsVerified(int userId) override;
35     void SubscribeAccountEvent() override;
36     void UnsubscribeAccountEvent() override;
37     void BindExecutor(std::shared_ptr<ExecutorPool> executors) override;
38     std::string GetUnencryptedAccountId(int32_t userId = 0) const override;
39     bool QueryForegroundUserId(int &foregroundUserId) override;
40     static bool Init();
41 
42 private:
43     ~AccountDelegateNormalImpl();
44     std::string Sha256AccountId(const std::string &plainText) const;
45     ExecutorPool::Task GetTask(uint32_t retry);
46     void UpdateUserStatus(const AccountEventInfo& account);
47     static constexpr int MAX_RETRY_TIME = 300;
48     static constexpr int RETRY_WAIT_TIME_S = 1;
49     std::shared_ptr<EventSubscriber> eventSubscriber_ {};
50     std::shared_ptr<ExecutorPool> executors_;
51     ConcurrentMap<int32_t, bool> userStatus_ {};
52 };
53 }  // namespace DistributedKv
54 }  // namespace OHOS
55 #endif // DISTRIBUTEDDATAMGR_ACCOUNT_DELEGATE_NORMAL_IMPL_H