• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_CLOUD_SYNC_SERVICE_CYCLE_TASK_RUNNER_H
17 #define OHOS_CLOUD_SYNC_SERVICE_CYCLE_TASK_RUNNER_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <vector>
22 #include <chrono>
23 #include <ctime>
24 #include "cloud_pref_impl.h"
25 #include "cycle_task.h"
26 
27 namespace OHOS {
28 namespace FileManagement {
29 namespace CloudSync {
30 class CycleTaskRunner {
31 public:
32     enum IntervalTime {
33         ONE_DAY = 24 * 60 * 60,
34         TWO_DAY = ONE_DAY * 2,
35         THREE_DAY = ONE_DAY * 3,
36         ONE_WEEK = ONE_DAY * 7,
37     };
38 
39     static const std::string FILE_PATH;
40     static const int32_t DEFAULT_VALUE;
41     static const int32_t DEFAULT_USER_ID;
42     CycleTaskRunner(std::shared_ptr<DataSyncManager> dataSyncManager);
43     void StartTask(std::string &reason);
44 
SetPref(const std::string & key,bool val)45     void SetPref(const std::string &key, bool val)
46     {
47         cloudPrefImpl_->SetBool(key, val);
48     }
49 
50 private:
51     int32_t userId_{0};
52     std::time_t setUpTime_{0};
53     std::unique_ptr<CloudPrefImpl> cloudPrefImpl_;
54     std::shared_ptr<DataSyncManager> dataSyncManager_;
55     std::vector<std::shared_ptr<CycleTask>> cycleTasks_ {};
56 
57     void InitTasks();
58     void GetLastRunTime(std::string taskName, std::time_t &time);
59     void SetLastRunTime(std::string taskName, std::time_t time);
60 };
61 
62 } // namespace CloudSync
63 } // namespace FileManagement
64 } // namespace OHOS
65 #endif // OHOS_CLOUD_SYNC_SERVICE_CYCLE_TASK_RUNNER_H