• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 APP_DOMAIN_VERIFY_DEFERRED_LINK_MGR_H
17 #define APP_DOMAIN_VERIFY_DEFERRED_LINK_MGR_H
18 #include <string>
19 #include <mutex>
20 #include <set>
21 #include "datetime_ex.h"
22 #include "uri.h"
23 #include "event_handler.h"
24 #include "event_runner.h"
25 #include "app_domain_verify_hilog.h"
26 #include "ability_filter.h"
27 
28 namespace OHOS::AppDomainVerify {
29 
30 struct DeferredLinkInfo {
31     std::string domain;
32     std::string url;
33     int64_t timeStamp;
34 };
35 /**
36  * DeferredLinkMgr
37  * @descrition
38  * The mgr keeps limited links which are generated when the link is clicked but app is not installed.
39  * After app installed, app can get the link which click to open it, and app can continue the browsing.
40  */
41 class DeferredLinkMgr {
42 public:
43     DeferredLinkMgr();
44     /**
45      * PutDeferredLink
46      * @descrition put deferred link info
47      * @param info the link.
48      */
49     void PutDeferredLink(const DeferredLinkInfo& info);
50 
51     /**
52      * GetDeferredLink
53      * @descrition get deferred link within domains and bundleName
54      * @param bundleName the bundleName to filter link info.
55      * @param domains the domains to filter link info.
56      * @return url the deferred url to open.
57      */
58     std::string GetDeferredLink(const std::string& bundleName, const std::vector<std::string>& domains);
59 
60     /**
61      * RemoveDeferredLink
62      * @descrition remove link stored.
63      * @param info the deferred link info to remove.
64      */
65     void RemoveDeferredLink(const DeferredLinkInfo& info);
66 
67     ~DeferredLinkMgr();
68 
69 private:
70     void PostAgeCacheTask();
71     void AgeCacheProcess();
72     void CheckStartTimerUnlocked();
73     void CheckFullUnlocked();
74     void CheckRemoveExistedUnlocked(const DeferredLinkInfo& info);
75     /**
76      * cache list
77      * @descrition list contains deferred link info, newly in front, older in back.
78      */
79     std::list<DeferredLinkInfo> caches_;
80     std::mutex cachesMutex_;
81     std::shared_ptr<AppExecFwk::EventHandler> ageHandler_;
82     std::shared_ptr<AppExecFwk::EventRunner> ageRunner_;
83 };
84 }
85 #endif  // APP_DOMAIN_VERIFY_DEFERRED_LINK_MGR_H
86