/src/libreoffice/desktop/source/deployment/manager/dp_manager.h
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include "dp_activepackages.hxx" |
23 | | #include <cppuhelper/basemutex.hxx> |
24 | | #include <cppuhelper/compbase.hxx> |
25 | | #include <cppuhelper/implbase.hxx> |
26 | | #include <ucbhelper/content.hxx> |
27 | | #include <com/sun/star/deployment/XPackageRegistry.hpp> |
28 | | #include <com/sun/star/deployment/XPackageManager.hpp> |
29 | | #include <memory> |
30 | | #include <mutex> |
31 | | #include <string_view> |
32 | | #include <utility> |
33 | | |
34 | | namespace dp_manager { |
35 | | |
36 | | typedef ::cppu::WeakComponentImplHelper< |
37 | | css::deployment::XPackageManager > t_pm_helper; |
38 | | |
39 | | |
40 | | class PackageManagerImpl final : private cppu::BaseMutex, public t_pm_helper |
41 | | { |
42 | | css::uno::Reference<css::uno::XComponentContext> m_xComponentContext; |
43 | | OUString m_context; |
44 | | OUString m_registrationData; |
45 | | OUString m_registrationData_expanded; |
46 | | OUString m_registryCache; |
47 | | bool m_readOnly; |
48 | | |
49 | | OUString m_activePackages; |
50 | | OUString m_activePackages_expanded; |
51 | | std::unique_ptr< ActivePackages > m_activePackagesDB; |
52 | | //This mutex is only used for synchronization in addPackage |
53 | | std::mutex m_addMutex; |
54 | | css::uno::Reference<css::ucb::XProgressHandler> m_xLogFile; |
55 | | inline void logIntern( css::uno::Any const & status ); |
56 | | void fireModified(); |
57 | | |
58 | | css::uno::Reference<css::deployment::XPackageRegistry> m_xRegistry; |
59 | | |
60 | | void initRegistryBackends(); |
61 | | void initActivationLayer( |
62 | | css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ); |
63 | | OUString detectMediaType( |
64 | | ::ucbhelper::Content const & ucbContent, bool throw_exc = true ); |
65 | | OUString insertToActivationLayer( |
66 | | css::uno::Sequence<css::beans::NamedValue> const & properties, |
67 | | OUString const & mediaType, |
68 | | ::ucbhelper::Content const & sourceContent, |
69 | | OUString const & title, ActivePackages::Data * dbData ); |
70 | | void insertToActivationLayerDB( |
71 | | OUString const & id, ActivePackages::Data const & dbData ); |
72 | | |
73 | | static void deletePackageFromCache( |
74 | | css::uno::Reference<css::deployment::XPackage> const & xPackage, |
75 | | OUString const & destFolder ); |
76 | | |
77 | | bool isInstalled( |
78 | | css::uno::Reference<css::deployment::XPackage> const & package); |
79 | | |
80 | | bool synchronizeRemovedExtensions( |
81 | | css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, |
82 | | css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv); |
83 | | |
84 | | bool synchronizeAddedExtensions( |
85 | | css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, |
86 | | css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv); |
87 | | |
88 | | class CmdEnvWrapperImpl |
89 | | : public ::cppu::WeakImplHelper< css::ucb::XCommandEnvironment, |
90 | | css::ucb::XProgressHandler > |
91 | | { |
92 | | css::uno::Reference<css::ucb::XProgressHandler> m_xLogFile; |
93 | | css::uno::Reference<css::ucb::XProgressHandler> m_xUserProgress; |
94 | | css::uno::Reference<css::task::XInteractionHandler> |
95 | | m_xUserInteractionHandler; |
96 | | |
97 | | public: |
98 | | virtual ~CmdEnvWrapperImpl() override; |
99 | | CmdEnvWrapperImpl( |
100 | | css::uno::Reference<css::ucb::XCommandEnvironment> |
101 | | const & xUserCmdEnv, |
102 | | css::uno::Reference<css::ucb::XProgressHandler> const & xLogFile ); |
103 | | |
104 | | // XCommandEnvironment |
105 | | virtual css::uno::Reference<css::task::XInteractionHandler> SAL_CALL |
106 | | getInteractionHandler() override; |
107 | | virtual css::uno::Reference<css::ucb::XProgressHandler> SAL_CALL |
108 | | getProgressHandler() override; |
109 | | |
110 | | // XProgressHandler |
111 | | virtual void SAL_CALL push( css::uno::Any const & Status ) override; |
112 | | virtual void SAL_CALL update( css::uno::Any const & Status ) override; |
113 | | virtual void SAL_CALL pop() override; |
114 | | }; |
115 | | |
116 | | inline void check(); |
117 | | virtual void SAL_CALL disposing() override; |
118 | | |
119 | | virtual ~PackageManagerImpl() override; |
120 | | PackageManagerImpl( |
121 | | css::uno::Reference<css::uno::XComponentContext> xComponentContext, OUString context ) |
122 | 0 | : t_pm_helper( m_aMutex ), |
123 | 0 | m_xComponentContext(std::move( xComponentContext )), |
124 | 0 | m_context(std::move( context )), |
125 | 0 | m_readOnly( true ) |
126 | 0 | {} |
127 | | |
128 | | public: |
129 | | static css::uno::Reference<css::deployment::XPackageManager> create( |
130 | | css::uno::Reference<css::uno::XComponentContext> |
131 | | const & xComponentContext, OUString const & context ); |
132 | | |
133 | | // XComponent |
134 | | virtual void SAL_CALL dispose() override; |
135 | | virtual void SAL_CALL addEventListener( |
136 | | css::uno::Reference<css::lang::XEventListener> const & xListener ) override; |
137 | | virtual void SAL_CALL removeEventListener( |
138 | | css::uno::Reference<css::lang::XEventListener> const & xListener ) override; |
139 | | |
140 | | // XModifyBroadcaster |
141 | | virtual void SAL_CALL addModifyListener( |
142 | | css::uno::Reference<css::util::XModifyListener> const & xListener ) override; |
143 | | virtual void SAL_CALL removeModifyListener( |
144 | | css::uno::Reference<css::util::XModifyListener> const & xListener ) override; |
145 | | |
146 | | // XPackageManager |
147 | | virtual OUString SAL_CALL getContext() override; |
148 | | virtual css::uno::Sequence< |
149 | | css::uno::Reference<css::deployment::XPackageTypeInfo> > SAL_CALL |
150 | | getSupportedPackageTypes() override; |
151 | | |
152 | | virtual css::uno::Reference<css::task::XAbortChannel> SAL_CALL |
153 | | createAbortChannel() override; |
154 | | |
155 | | virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL addPackage( |
156 | | OUString const & url, |
157 | | css::uno::Sequence<css::beans::NamedValue> const & properties, |
158 | | OUString const & mediaType, |
159 | | css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, |
160 | | css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override; |
161 | | |
162 | | virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL importExtension( |
163 | | css::uno::Reference<css::deployment::XPackage> const & extension, |
164 | | css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, |
165 | | css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override; |
166 | | |
167 | | virtual void SAL_CALL removePackage( |
168 | | OUString const & id, OUString const & fileName, |
169 | | css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, |
170 | | css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override; |
171 | | |
172 | | OUString getDeployPath( ActivePackages::Data const & data ); |
173 | | css::uno::Reference<css::deployment::XPackage> getDeployedPackage_( |
174 | | OUString const & id, OUString const & fileName, |
175 | | css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ); |
176 | | css::uno::Reference<css::deployment::XPackage> getDeployedPackage_( |
177 | | std::u16string_view id, ActivePackages::Data const & data, |
178 | | css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv, |
179 | | bool ignoreAlienPlatforms = false ); |
180 | | virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL |
181 | | getDeployedPackage( |
182 | | OUString const & id, OUString const & fileName, |
183 | | css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override; |
184 | | |
185 | | css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> > |
186 | | getDeployedPackages_( |
187 | | css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ); |
188 | | virtual css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> > |
189 | | SAL_CALL getDeployedPackages( |
190 | | css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, |
191 | | css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override; |
192 | | |
193 | | virtual void SAL_CALL reinstallDeployedPackages( |
194 | | sal_Bool force, |
195 | | css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, |
196 | | css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override; |
197 | | |
198 | | virtual ::sal_Bool SAL_CALL isReadOnly( ) override; |
199 | | |
200 | | virtual ::sal_Bool SAL_CALL synchronize( |
201 | | css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, |
202 | | css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override; |
203 | | |
204 | | virtual css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> > SAL_CALL |
205 | | getExtensionsWithUnacceptedLicenses( |
206 | | css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv) override; |
207 | | |
208 | | virtual sal_Int32 SAL_CALL checkPrerequisites( |
209 | | css::uno::Reference<css::deployment::XPackage> const & extension, |
210 | | css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, |
211 | | css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override; |
212 | | }; |
213 | | |
214 | | |
215 | | inline void PackageManagerImpl::check() |
216 | 0 | { |
217 | 0 | ::osl::MutexGuard guard( m_aMutex ); |
218 | 0 | if (rBHelper.bInDispose || rBHelper.bDisposed) |
219 | 0 | throw css::lang::DisposedException( |
220 | 0 | u"PackageManager instance has already been disposed!"_ustr, |
221 | 0 | static_cast< ::cppu::OWeakObject * >(this) ); |
222 | 0 | } |
223 | | |
224 | | |
225 | | inline void PackageManagerImpl::logIntern( css::uno::Any const & status ) |
226 | 0 | { |
227 | 0 | if (m_xLogFile.is()) |
228 | 0 | m_xLogFile->update( status ); |
229 | 0 | } |
230 | | |
231 | | } |
232 | | |
233 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |