• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 DOWNLOAD_DATA_ABILITY_H
17 #define DOWNLOAD_DATA_ABILITY_H
18 
19 #include "ability.h"
20 #include "ability_loader.h"
21 #include "want.h"
22 
23 #include "download_database.h"
24 
25 namespace OHOS::AppExecFwk {
26 class DownloadDataAbility : public Ability {
27 public:
28     DownloadDataAbility();
29     ~DownloadDataAbility();
30     virtual int Insert(const Uri &uri, const NativeRdb::ValuesBucket &value) override;
31     virtual int BatchInsert(const Uri &uri, const std::vector<NativeRdb::ValuesBucket> &values) override;
32     virtual void OnStart(const Want &want) override;
33     virtual int Update(const Uri &uri, const NativeRdb::ValuesBucket &value,
34         const NativeRdb::DataAbilityPredicates &predicates) override;
35     virtual int Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates) override;
36     virtual std::shared_ptr<NativeRdb::AbsSharedResultSet> Query(const Uri &uri,
37         const std::vector<std::string> &columns, const NativeRdb::DataAbilityPredicates &predicates) override;
38     virtual void Dump(const std::string &extra) override;
39 
40 private:
41     int UriParse(Uri &uri);
42     int InsertExecute(const Uri &uri, const NativeRdb::ValuesBucket &value);
43     void DataBaseNotifyChange(int code, Uri uri);
44     bool IsBeginTransactionOK(int code, std::mutex &mutex);
45     bool IsCommitOk(int code, std::mutex &mutex);
46 
47 private:
48     static std::shared_ptr<OHOS::Request::Download::DownloadDataBase> database_;
49     static std::map<std::string, int> uriValueMap_;
50 };
51 } // namespace OHOS::AppExecFwk
52 
53 #endif // DOWNLOAD_DATA_ABILITY_H