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 DLP_VISIT_RECORD_FILE_MANAGER_H
17 #define DLP_VISIT_RECORD_FILE_MANAGER_H
18 
19 #include <mutex>
20 #include <map>
21 
22 #include "file_operator.h"
23 #include "nlohmann/json.hpp"
24 #include "visited_dlp_file_info.h"
25 #include "visit_record_json_manager.h"
26 
27 namespace OHOS {
28 namespace Security {
29 namespace DlpPermission {
30 using Json = nlohmann::json;
31 
32 class VisitRecordFileManager {
33 public:
34     VisitRecordFileManager();
35     virtual ~VisitRecordFileManager();
36     static VisitRecordFileManager& GetInstance();
37 
38     int32_t AddVisitRecord(const std::string& bundleName, const int32_t& userId, const std::string& docUri);
39     int32_t GetVisitRecordList(const std::string& bundleName, const int32_t& userId,
40         std::vector<VisitedDLPFileInfo>& infoVec);
41 
42 private:
43     bool Init();
44     int32_t UpdateFile(const int32_t& jsonRes);
45     bool hasInit_ = false;
46     std::shared_ptr<FileOperator> fileOperator_;
47     std::recursive_mutex mutex_;
48     std::shared_ptr<VisitRecordJsonManager> visitRecordJsonManager_;
49 };
50 } // namespace DlpPermission
51 } // namespace Security
52 } // namespace OHOS
53 #endif // DLP_VISIT_RECORD_FILE_MANAGER_H
54