• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 "base/utils/utils.h"
17 #include "core/common/storage/storage_proxy.h"
18 
19 namespace OHOS::Ace {
20 
GetInstance()21 StorageProxy* StorageProxy::GetInstance()
22 {
23     static StorageProxy instance;
24     return &instance;
25 }
26 
SetDelegate(std::unique_ptr<StorageInterface> && delegate)27 void StorageProxy::SetDelegate(std::unique_ptr<StorageInterface>&& delegate)
28 {
29     delegate_ = std::move(delegate);
30 }
31 
SetDistributedDelegate(std::unique_ptr<StorageInterface> && delegate)32 void StorageProxy::SetDistributedDelegate(std::unique_ptr<StorageInterface>&& delegate)
33 {
34     distributedDelegate_ = std::move(delegate);
35 }
36 
GetStorage(int areaMode) const37 RefPtr<Storage> StorageProxy::GetStorage(int areaMode) const
38 {
39     CHECK_NULL_RETURN(delegate_, nullptr);
40     return delegate_->GetStorage(areaMode);
41 }
42 
GetStorage(const std::string & sessionId,std::function<void (const std::string &)> && notifier,const RefPtr<TaskExecutor> & taskExecutor) const43 RefPtr<Storage> StorageProxy::GetStorage(const std::string& sessionId,
44     std::function<void(const std::string&)>&& notifier, const RefPtr<TaskExecutor>& taskExecutor) const
45 {
46     CHECK_NULL_RETURN(distributedDelegate_, nullptr);
47     return distributedDelegate_->GetStorage(sessionId, std::move(notifier), taskExecutor);
48 }
49 
50 } // namespace OHOS::Ace
51