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 UDMF_URI_PERMISSION_MANAGER_H
17 #define UDMF_URI_PERMISSION_MANAGER_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "concurrent_map.h"
23 #include "error_code.h"
24 #include "executor_pool.h"
25 #include "uri.h"
26 
27 namespace OHOS {
28 namespace UDMF {
29 class UriPermissionManager {
30 public:
31     using Time = std::chrono::steady_clock::time_point;
32     static UriPermissionManager &GetInstance();
33     Status GrantUriPermission(const std::vector<Uri> &allUri, uint32_t tokenId, const std::string &queryKey);
34     void SetThreadPool(std::shared_ptr<ExecutorPool> executors);
35 
36 private:
UriPermissionManager()37     UriPermissionManager() {}
~UriPermissionManager()38     ~UriPermissionManager() {}
39     UriPermissionManager(const UriPermissionManager &mgr) = delete;
40     UriPermissionManager &operator=(const UriPermissionManager &mgr) = delete;
41 
42     void RevokeUriPermission();
43 
44     ConcurrentMap<std::pair<std::string, uint32_t>, Time> uriTimeout_;
45     static constexpr int64_t INTERVAL = 60;  // 60 min
46     ExecutorPool::TaskId taskId_ = ExecutorPool::INVALID_TASK_ID;
47     std::mutex taskMutex_;
48     std::shared_ptr<ExecutorPool> executorPool_;
49 };
50 } // namespace UDMF
51 } // namespace OHOS
52 #endif // UDMF_URI_PERMISSION_MANAGER_H