LibreOffice Module desktop (master) 1
dp_backend.h
Go to the documentation of this file.
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_shared.hxx>
23#include <dp_interact.h>
24#include <rtl/ref.hxx>
28#include <com/sun/star/lang/XEventListener.hpp>
29#include <com/sun/star/lang/XServiceInfo.hpp>
30#include <com/sun/star/deployment/XPackageRegistry.hpp>
31#include <com/sun/star/uno/XComponentContext.hpp>
32#include <unordered_map>
33#include <strings.hrc>
34#include <utility>
35
37{
38
39class PackageRegistryBackend;
40
41inline constexpr OUStringLiteral BACKEND_SERVICE_NAME = u"com.sun.star.deployment.PackageRegistryBackend";
42
43typedef ::cppu::WeakComponentImplHelper<
44 css::deployment::XPackage > t_PackageBase;
45
46
47class Package : protected cppu::BaseMutex, public t_PackageBase
48{
51 bool registerPackage,
52 bool startup,
53 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
54 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
55
56protected:
58 const OUString m_url;
59 OUString m_name;
60 OUString m_displayName;
61 const css::uno::Reference<css::deployment::XPackageTypeInfo> m_xPackageType;
62 const bool m_bRemoved;
63 //Only set if m_bRemoved = true;
64 const OUString m_identifier;
65
66 void check() const;
67 void fireModified();
68 virtual void SAL_CALL disposing() override;
69
70 void checkAborted(
72
73 // @@@ to be implemented by specific backend:
74 virtual css::beans::Optional< css::beans::Ambiguous<sal_Bool> >
76 ::osl::ResettableMutexGuard & guard,
78 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
79 = 0;
80 virtual void processPackage_(
81 ::osl::ResettableMutexGuard & guard,
82 bool registerPackage,
83 bool startup,
85 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
86 = 0;
87
88 virtual ~Package() override;
90 OUString url,
91 OUString name,
92 OUString displayName,
93 css::uno::Reference<css::deployment::XPackageTypeInfo> const & xPackageType,
94 bool bRemoved,
95 OUString identifier);
96
97public:
98
99 class TypeInfo :
100 public ::cppu::WeakImplHelper<css::deployment::XPackageTypeInfo>
101 {
102 const OUString m_mediaType;
103 const OUString m_fileFilter;
104 const OUString m_shortDescr;
105 public:
106 virtual ~TypeInfo() override;
107 TypeInfo( OUString mediaType,
108 OUString fileFilter,
109 OUString shortDescr )
110 : m_mediaType(std::move(mediaType)), m_fileFilter(std::move(fileFilter)),
111 m_shortDescr(std::move(shortDescr))
112 {}
113 // XPackageTypeInfo
114 virtual OUString SAL_CALL getMediaType() override;
115 virtual OUString SAL_CALL getDescription() override;
116 virtual OUString SAL_CALL getShortDescription() override;
117 virtual OUString SAL_CALL getFileFilter() override;
118 virtual css::uno::Any SAL_CALL getIcon( sal_Bool highContrast,
119 sal_Bool smallIcon ) override;
120 };
121
122 // XComponent
123 virtual void SAL_CALL dispose() override;
124 virtual void SAL_CALL addEventListener(
125 css::uno::Reference<css::lang::XEventListener> const & xListener ) override;
126 virtual void SAL_CALL removeEventListener(
127 css::uno::Reference<css::lang::XEventListener> const & xListener ) override;
128
129 // XModifyBroadcaster
130 virtual void SAL_CALL addModifyListener(
131 css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
132 virtual void SAL_CALL removeModifyListener(
133 css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
134
135 // XPackage
136 virtual css::uno::Reference<css::task::XAbortChannel> SAL_CALL
137 createAbortChannel() override;
138 virtual css::beans::Optional< css::beans::Ambiguous<sal_Bool> >
139 SAL_CALL isRegistered(
140 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
141 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
142
143 virtual ::sal_Int32 SAL_CALL checkPrerequisites(
144 const css::uno::Reference< css::task::XAbortChannel >& xAbortChannel,
145 const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv,
146 sal_Bool noLicenseChecking) override;
147
148 virtual ::sal_Bool SAL_CALL checkDependencies(
149 const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv ) override;
150
151 virtual void SAL_CALL registerPackage(
152 sal_Bool startup,
153 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
154 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
155 virtual void SAL_CALL revokePackage(
156 sal_Bool startup,
157 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
158 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
159 virtual sal_Bool SAL_CALL isBundle() override;
160 virtual css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
161 SAL_CALL getBundle(
162 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
163 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
164 virtual OUString SAL_CALL getName() override;
165 virtual css::beans::Optional< OUString > SAL_CALL getIdentifier() override;
166 virtual OUString SAL_CALL getVersion() override;
167 virtual OUString SAL_CALL getURL() override;
168 virtual OUString SAL_CALL getDisplayName() override;
169 virtual OUString SAL_CALL getDescription() override;
170 virtual OUString SAL_CALL getLicenseText() override;
171 virtual css::uno::Sequence< OUString > SAL_CALL
172 getUpdateInformationURLs() override;
173 virtual css::beans::StringPair SAL_CALL getPublisherInfo() override;
174 virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL
175 getIcon( sal_Bool bHighContrast ) override;
176 virtual css::uno::Reference<css::deployment::XPackageTypeInfo> SAL_CALL
177 getPackageType() override;
178 virtual void SAL_CALL exportTo(
179 OUString const & destFolderURL,
180 OUString const & newTitle,
181 sal_Int32 nameClashAction,
182 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
183 virtual OUString SAL_CALL getRepositoryName() override;
184 virtual css::beans::Optional< OUString > SAL_CALL getRegistrationDataURL() override;
185 virtual sal_Bool SAL_CALL isRemoved() override;
186
187};
188
189typedef ::cppu::WeakComponentImplHelper<
190 css::lang::XEventListener,
191 css::deployment::XPackageRegistry,
192 css::lang::XServiceInfo > t_BackendBase;
193
194
196 : protected cppu::BaseMutex, public t_BackendBase
197{
198 //The map held originally WeakReferences. The map entries are removed in the disposing
199 //function, which is called when the XPackages are destructed or they are
200 //explicitly disposed. The latter happens, for example, when an extension is
201 //removed (see dp_manager.cxx). However, because of how the help systems work, now
202 // XPackageManager::getDeployedPackages is called often. This results in a lot
203 //of bindPackage calls which are costly. Therefore we keep hard references in
204 //the map now.
205 typedef std::unordered_map<
206 OUString, css::uno::Reference<css::deployment::XPackage> > t_string2ref;
208
209protected:
210 OUString m_cachePath;
211 css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
212
213 OUString m_context;
214 // currently only for library containers:
215 enum class Context {
216 Unknown, User, Shared, Bundled, Tmp, Document
218
219 static OUString StrCannotDetectMediaType() { return DpResId(RID_STR_CANNOT_DETECT_MEDIA_TYPE); }
220 static OUString StrUnsupportedMediaType() { return DpResId(RID_STR_UNSUPPORTED_MEDIA_TYPE); }
221
222 // @@@ to be implemented by specific backend:
223 virtual css::uno::Reference<css::deployment::XPackage> bindPackage_(
224 OUString const & url, OUString const & mediaType,
225 bool bRemoved, OUString const & identifier,
226 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
227 = 0;
228
229 void check();
230 virtual void SAL_CALL disposing() override;
231
232 virtual ~PackageRegistryBackend() override;
234 css::uno::Sequence<css::uno::Any> const & args,
235 css::uno::Reference<css::uno::XComponentContext> const & xContext );
236
237 /* creates a folder with a unique name.
238 If url is empty then it is created in the backend folder, otherwise
239 at a location relative to that folder specified by url.
240 */
241 OUString createFolder(
242 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
243 /* deletes folders and files.
244
245 All folder all files which end with ".tmp" or ".tmp_" and which are
246 not used are deleted.
247 */
249 std::vector< OUString> const & usedFolders);
250 /* deletes one folder with a "temporary" name and the corresponding
251 tmp file, which was used to derive the folder name.
252 */
253 static void deleteTempFolder(
254 OUString const & folderUrl);
255
256public:
257 static OUString StrRegisteringPackage() { return DpResId(RID_STR_REGISTERING_PACKAGE); }
258 static OUString StrRevokingPackage() { return DpResId(RID_STR_REVOKING_PACKAGE); }
259
260 css::uno::Reference<css::uno::XComponentContext> const &
262
263 OUString const & getCachePath() const { return m_cachePath; }
264 bool transientMode() const { return m_cachePath.isEmpty(); }
265
266 const OUString& getContext() const {return m_context; }
267
268 // XEventListener
269 virtual void SAL_CALL disposing( css::lang::EventObject const & evt ) override;
270
271 // XPackageRegistry
272 virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL bindPackage(
273 OUString const & url, OUString const & mediaType,
274 sal_Bool bRemoved, OUString const & identifier,
275 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
276
277// virtual void SAL_CALL packageRemoved(
278// OUString const & url, OUString const & mediaType)
279// throw (css::deployment::DeploymentException,
280// css::uno::RuntimeException);
281
282};
283
284}
285
286
287/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOUser User
virtual css::uno::Reference< css::deployment::XPackage > SAL_CALL bindPackage(OUString const &url, OUString const &mediaType, sal_Bool bRemoved, OUString const &identifier, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_backend.cxx:138
OUString createFolder(css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
Definition: dp_backend.cxx:210
std::unordered_map< OUString, css::uno::Reference< css::deployment::XPackage > > t_string2ref
Definition: dp_backend.h:206
css::uno::Reference< css::uno::XComponentContext > const & getComponentContext() const
Definition: dp_backend.h:261
virtual void SAL_CALL disposing() override
Definition: dp_backend.cxx:116
static void deleteTempFolder(OUString const &folderUrl)
Definition: dp_backend.cxx:226
virtual css::uno::Reference< css::deployment::XPackage > bindPackage_(OUString const &url, OUString const &mediaType, bool bRemoved, OUString const &identifier, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)=0
void deleteUnusedFolders(std::vector< OUString > const &usedFolders)
Definition: dp_backend.cxx:247
enum dp_registry::backend::PackageRegistryBackend::Context m_eContext
PackageRegistryBackend(css::uno::Sequence< css::uno::Any > const &args, css::uno::Reference< css::uno::XComponentContext > const &xContext)
Definition: dp_backend.cxx:76
virtual void SAL_CALL disposing(css::lang::EventObject const &evt) override
css::uno::Reference< css::uno::XComponentContext > m_xComponentContext
Definition: dp_backend.h:211
virtual OUString SAL_CALL getDescription() override
Definition: dp_backend.cxx:746
virtual css::uno::Any SAL_CALL getIcon(sal_Bool highContrast, sal_Bool smallIcon) override
Definition: dp_backend.cxx:762
virtual OUString SAL_CALL getShortDescription() override
Definition: dp_backend.cxx:752
virtual OUString SAL_CALL getMediaType() override
Definition: dp_backend.cxx:740
TypeInfo(OUString mediaType, OUString fileFilter, OUString shortDescr)
Definition: dp_backend.h:107
virtual OUString SAL_CALL getFileFilter() override
Definition: dp_backend.cxx:757
virtual OUString SAL_CALL getLicenseText() override
Definition: dp_backend.cxx:487
virtual OUString SAL_CALL getName() override
Definition: dp_backend.cxx:443
virtual void SAL_CALL removeEventListener(css::uno::Reference< css::lang::XEventListener > const &xListener) override
Definition: dp_backend.cxx:365
virtual void processPackage_(::osl::ResettableMutexGuard &guard, bool registerPackage, bool startup, ::rtl::Reference< ::dp_misc::AbortChannel > const &abortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)=0
void checkAborted(::rtl::Reference< ::dp_misc::AbortChannel > const &abortChannel)
Definition: dp_backend.cxx:391
const css::uno::Reference< css::deployment::XPackageTypeInfo > m_xPackageType
Definition: dp_backend.h:61
virtual void SAL_CALL addModifyListener(css::uno::Reference< css::util::XModifyListener > const &xListener) override
Definition: dp_backend.cxx:375
virtual void SAL_CALL exportTo(OUString const &destFolderURL, OUString const &newTitle, sal_Int32 nameClashAction, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_backend.cxx:527
virtual OUString SAL_CALL getURL() override
Definition: dp_backend.cxx:465
virtual OUString SAL_CALL getDescription() override
Definition: dp_backend.cxx:479
virtual OUString SAL_CALL getRepositoryName() override
Definition: dp_backend.cxx:716
virtual void SAL_CALL removeModifyListener(css::uno::Reference< css::util::XModifyListener > const &xListener) override
Definition: dp_backend.cxx:383
virtual ::sal_Bool SAL_CALL checkDependencies(const css::uno::Reference< css::ucb::XCommandEnvironment > &xCmdEnv) override
Definition: dp_backend.cxx:426
virtual sal_Bool SAL_CALL isBundle() override
Definition: dp_backend.cxx:409
PackageRegistryBackend * getMyBackend() const
Definition: dp_backend.cxx:701
::rtl::Reference< PackageRegistryBackend > m_myBackend
Definition: dp_backend.h:57
virtual ~Package() override
Definition: dp_backend.cxx:294
virtual void SAL_CALL dispose() override
Definition: dp_backend.cxx:348
virtual void SAL_CALL registerPackage(sal_Bool startup, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_backend.cxx:681
virtual OUString SAL_CALL getDisplayName() override
Definition: dp_backend.cxx:471
virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL getIcon(sal_Bool bHighContrast) override
Definition: dp_backend.cxx:512
virtual css::beans::Optional< OUString > SAL_CALL getRegistrationDataURL() override
Definition: dp_backend.cxx:722
virtual css::beans::Optional< OUString > SAL_CALL getIdentifier() override
Definition: dp_backend.cxx:448
virtual void SAL_CALL addEventListener(css::uno::Reference< css::lang::XEventListener > const &xListener) override
Definition: dp_backend.cxx:356
virtual css::beans::StringPair SAL_CALL getPublisherInfo() override
Definition: dp_backend.cxx:503
Package(::rtl::Reference< PackageRegistryBackend > myBackend, OUString url, OUString name, OUString displayName, css::uno::Reference< css::deployment::XPackageTypeInfo > const &xPackageType, bool bRemoved, OUString identifier)
Definition: dp_backend.cxx:299
virtual OUString SAL_CALL getVersion() override
Definition: dp_backend.cxx:457
virtual css::beans::Optional< css::beans::Ambiguous< sal_Bool > > isRegistered_(::osl::ResettableMutexGuard &guard, ::rtl::Reference< ::dp_misc::AbortChannel > const &abortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)=0
const OUString m_identifier
Definition: dp_backend.h:64
virtual css::uno::Sequence< css::uno::Reference< css::deployment::XPackage > > SAL_CALL getBundle(css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_backend.cxx:435
virtual void SAL_CALL disposing() override
Definition: dp_backend.cxx:329
void processPackage_impl(bool registerPackage, bool startup, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
Definition: dp_backend.cxx:603
virtual css::beans::Optional< css::beans::Ambiguous< sal_Bool > > SAL_CALL isRegistered(css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_backend.cxx:572
virtual css::uno::Reference< css::deployment::XPackageTypeInfo > SAL_CALL getPackageType() override
Definition: dp_backend.cxx:522
virtual css::uno::Sequence< OUString > SAL_CALL getUpdateInformationURLs() override
Definition: dp_backend.cxx:495
virtual ::sal_Int32 SAL_CALL checkPrerequisites(const css::uno::Reference< css::task::XAbortChannel > &xAbortChannel, const css::uno::Reference< css::ucb::XCommandEnvironment > &xCmdEnv, sal_Bool noLicenseChecking) override
Definition: dp_backend.cxx:415
virtual css::uno::Reference< css::task::XAbortChannel > SAL_CALL createAbortChannel() override
Definition: dp_backend.cxx:402
virtual void SAL_CALL revokePackage(sal_Bool startup, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_backend.cxx:692
virtual sal_Bool SAL_CALL isRemoved() override
Definition: dp_backend.cxx:729
OUString DpResId(TranslateId aId)
Definition: dp_misc.cxx:555
float u
static uno::Reference< css::uno::XComponentContext > xContext
Definition: init.cxx:2642
constexpr OUStringLiteral BACKEND_SERVICE_NAME
Definition: dp_backend.h:41
::cppu::WeakComponentImplHelper< css::deployment::XPackage > t_PackageBase
Definition: dp_backend.h:44
::cppu::WeakComponentImplHelper< css::lang::XEventListener, css::deployment::XPackageRegistry, css::lang::XServiceInfo > t_BackendBase
Definition: dp_backend.h:192
Unknown
unsigned char sal_Bool