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_ROSEN_WINDOW_SCENE_EXTENSION_SESSION_MANAGER_H 17 #define OHOS_ROSEN_WINDOW_SCENE_EXTENSION_SESSION_MANAGER_H 18 19 #include "common/include/task_scheduler.h" 20 #include "interfaces/include/ws_common.h" 21 #include "wm_single_instance.h" 22 23 namespace OHOS::AAFwk { 24 class SessionInfo; 25 } // namespace OHOS::AAFwk 26 27 namespace OHOS::Rosen { 28 class ExtensionSession; 29 class ExtensionSessionManager { 30 WM_DECLARE_SINGLE_INSTANCE_BASE(ExtensionSessionManager) 31 public: 32 /** 33 * @brief create extension session 34 * 35 * @param sessionInfo sessionInfo, identify extension session instance 36 * @return sptr<ExtensionSession> return session if create extension session success;Otherwise, return nullptr 37 */ 38 sptr<ExtensionSession> RequestExtensionSession(const SessionInfo& sessionInfo); 39 /** 40 * @brief active extension session 41 * 42 * @param extensionSession the extension session need to be activated 43 * @return WSError 44 */ 45 WSError RequestExtensionSessionActivation(const sptr<ExtensionSession>& extensionSession, uint32_t hostWindowId, 46 const std::function<void(WSError)>&& resultCallback); 47 /** 48 * @brief background extension session 49 * 50 * @param extensionSession the extension session need to be go background 51 * @return WSError 52 */ 53 WSError RequestExtensionSessionBackground( 54 const sptr<ExtensionSession>& extensionSession, const std::function<void(WSError)>&& resultCallback); 55 /** 56 * @brief destroy extension session 57 * 58 * @param extensionSession the extension session need to be destroyed 59 * @return WSError 60 */ 61 WSError RequestExtensionSessionDestruction( 62 const sptr<ExtensionSession>& extensionSession, const std::function<void(WSError)>&& resultCallback); 63 /** 64 * @brief destroy extension session done 65 * 66 * @param extensionSession the extension session need to be destroyed 67 * @return WSError 68 */ 69 WSError RequestExtensionSessionDestructionDone(const sptr<ExtensionSession>& extensionSession); 70 71 private: 72 ExtensionSessionManager(); 73 ~ExtensionSessionManager() = default; 74 75 sptr<AAFwk::SessionInfo> SetAbilitySessionInfo(const sptr<ExtensionSession>& extensionSession); 76 77 std::shared_ptr<TaskScheduler> taskScheduler_; 78 std::map<int32_t, sptr<ExtensionSession>> extensionSessionMap_; 79 }; 80 } // namespace OHOS::Rosen 81 82 #endif // OHOS_ROSEN_WINDOW_SCENE_EXTENSION_SESSION_MANAGER_H 83