• 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 #include "cloud_download_uri_manager.h"
17 #include "utils_log.h"
18 
19 namespace OHOS::FileManagement::CloudSync {
20 
GetInstance()21 CloudDownloadUriManager& CloudDownloadUriManager::GetInstance()
22 {
23     static CloudDownloadUriManager mgr;
24     return mgr;
25 }
26 
SetRegisteredFlag()27 void CloudDownloadUriManager::SetRegisteredFlag()
28 {
29     LOGI("download_file : SetRegisteredFlag");
30     registered_ = true;
31 }
32 
UnsetRegisteredFlag()33 void CloudDownloadUriManager::UnsetRegisteredFlag()
34 {
35     LOGI("download_file : UnsetRegisteredFlag");
36     registered_ = false;
37 }
38 
AddPathToUri(const std::string & path,const std::string & uri)39 void CloudDownloadUriManager::AddPathToUri(const std::string& path, const std::string& uri)
40 {
41     if (registered_) {
42         LOGI("download_file : add path [ %{public}s ] -> uri [ %{public}s ]", path.c_str(), uri.c_str());
43         pathMap_[path] = uri;
44         return;
45     }
46     LOGI("download_file : unregistered_ can't add path [ %{public}s ] -> uri [ %{public}s ]",
47         path.c_str(), uri.c_str());
48 }
49 
RemoveUri(const std::string & path)50 void CloudDownloadUriManager::RemoveUri(const std::string& path)
51 {
52     if (pathMap_.find(path) != pathMap_.end()) {
53         LOGI("download_file : remove path [ %{public}s ] success", path.c_str());
54         pathMap_.erase(path);
55     }
56 }
57 
GetUri(const std::string & path)58 std::string CloudDownloadUriManager::GetUri(const std::string& path)
59 {
60     if (pathMap_.find(path) != pathMap_.end()) {
61         LOGI("download_file : get path [ %{public}s ] success", path.c_str());
62         return pathMap_[path];
63     }
64 
65     LOGE("download_file : get path [ %{public}s ] fail", path.c_str());
66     return "";
67 }
68 
69 } // namespace OHOS::FileManagement::CloudSync
70