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 #ifndef INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_REGISTRY_INC_DP_BACKEND_H
21 #define INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_REGISTRY_INC_DP_BACKEND_H
22 
23 #include <dp_misc.h>
24 #include <dp_resource.h>
25 #include <dp_shared.hxx>
26 #include <dp_interact.h>
27 #include <rtl/ref.hxx>
28 #include <cppuhelper/weakref.hxx>
29 #include <cppuhelper/implbase.hxx>
30 #include <cppuhelper/compbase.hxx>
31 #include <com/sun/star/lang/XEventListener.hpp>
32 #include <com/sun/star/deployment/XPackageRegistry.hpp>
33 #include <com/sun/star/deployment/XPackageManager.hpp>
34 #include <com/sun/star/deployment/InvalidRemovedParameterException.hpp>
35 #include <unordered_map>
36 #include <strings.hrc>
37 
38 namespace dp_registry
39 {
40 namespace backend
41 {
42 
43 class PackageRegistryBackend;
44 
45 #define BACKEND_SERVICE_NAME "com.sun.star.deployment.PackageRegistryBackend"
46 
47 typedef ::cppu::WeakComponentImplHelper<
48  css::deployment::XPackage > t_PackageBase;
49 
50 
51 class Package : protected ::dp_misc::MutexHolder, public t_PackageBase
52 {
55  bool registerPackage,
56  bool startup,
57  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
58  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
59 
60 protected:
62  const OUString m_url;
63  OUString m_name;
64  OUString m_displayName;
65  const css::uno::Reference<css::deployment::XPackageTypeInfo> m_xPackageType;
66  const bool m_bRemoved;
67  //Only set if m_bRemoved = true;
68  const OUString m_identifier;
69 
70  void check() const;
71  void fireModified();
72  virtual void SAL_CALL disposing() override;
73 
74  void checkAborted(
75  ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel );
76 
77  // @@@ to be implemented by specific backend:
78  virtual css::beans::Optional< css::beans::Ambiguous<sal_Bool> >
80  ::osl::ResettableMutexGuard & guard,
81  ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel,
82  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
83  = 0;
84  virtual void processPackage_(
85  ::osl::ResettableMutexGuard & guard,
86  bool registerPackage,
87  bool startup,
88  ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel,
89  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
90  = 0;
91 
92  virtual ~Package() override;
94  OUString const & url,
95  OUString const & name,
96  OUString const & displayName,
97  css::uno::Reference<css::deployment::XPackageTypeInfo> const &
98  xPackageType,
99  bool bRemoved,
100  OUString const & identifier);
101 
102 public:
103 
104  class TypeInfo :
105  public ::cppu::WeakImplHelper<css::deployment::XPackageTypeInfo>
106  {
107  const OUString m_mediaType;
108  const OUString m_fileFilter;
109  const OUString m_shortDescr;
110  public:
111  virtual ~TypeInfo() override;
112  TypeInfo( OUString const & mediaType,
113  OUString const & fileFilter,
114  OUString const & shortDescr )
115  : m_mediaType(mediaType), m_fileFilter(fileFilter),
116  m_shortDescr(shortDescr)
117  {}
118  // XPackageTypeInfo
119  virtual OUString SAL_CALL getMediaType() override;
120  virtual OUString SAL_CALL getDescription() override;
121  virtual OUString SAL_CALL getShortDescription() override;
122  virtual OUString SAL_CALL getFileFilter() override;
123  virtual css::uno::Any SAL_CALL getIcon( sal_Bool highContrast,
124  sal_Bool smallIcon ) override;
125  };
126 
127  // XComponent
128  virtual void SAL_CALL dispose() override;
129  virtual void SAL_CALL addEventListener(
130  css::uno::Reference<css::lang::XEventListener> const & xListener ) override;
131  virtual void SAL_CALL removeEventListener(
132  css::uno::Reference<css::lang::XEventListener> const & xListener ) override;
133 
134  // XModifyBroadcaster
135  virtual void SAL_CALL addModifyListener(
136  css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
137  virtual void SAL_CALL removeModifyListener(
138  css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
139 
140  // XPackage
141  virtual css::uno::Reference<css::task::XAbortChannel> SAL_CALL
142  createAbortChannel() override;
143  virtual css::beans::Optional< css::beans::Ambiguous<sal_Bool> >
144  SAL_CALL isRegistered(
145  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
146  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
147 
148  virtual ::sal_Int32 SAL_CALL checkPrerequisites(
149  const css::uno::Reference< css::task::XAbortChannel >& xAbortChannel,
150  const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv,
151  sal_Bool noLicenseChecking) override;
152 
153  virtual ::sal_Bool SAL_CALL checkDependencies(
154  const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv ) override;
155 
156  virtual void SAL_CALL registerPackage(
157  sal_Bool startup,
158  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
159  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
160  virtual void SAL_CALL revokePackage(
161  sal_Bool startup,
162  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
163  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
164  virtual sal_Bool SAL_CALL isBundle() override;
165  virtual css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
166  SAL_CALL getBundle(
167  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
168  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
169  virtual OUString SAL_CALL getName() override;
170  virtual css::beans::Optional< OUString > SAL_CALL getIdentifier() override;
171  virtual OUString SAL_CALL getVersion() override;
172  virtual OUString SAL_CALL getURL() override;
173  virtual OUString SAL_CALL getDisplayName() override;
174  virtual OUString SAL_CALL getDescription() override;
175  virtual OUString SAL_CALL getLicenseText() override;
176  virtual css::uno::Sequence< OUString > SAL_CALL
177  getUpdateInformationURLs() override;
178  virtual css::beans::StringPair SAL_CALL getPublisherInfo() override;
179  virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL
180  getIcon( sal_Bool bHighContrast ) override;
181  virtual css::uno::Reference<css::deployment::XPackageTypeInfo> SAL_CALL
182  getPackageType() override;
183  virtual void SAL_CALL exportTo(
184  OUString const & destFolderURL,
185  OUString const & newTitle,
186  sal_Int32 nameClashAction,
187  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
188  virtual OUString SAL_CALL getRepositoryName() override;
189  virtual css::beans::Optional< OUString > SAL_CALL getRegistrationDataURL() override;
190  virtual sal_Bool SAL_CALL isRemoved() override;
191 
192 };
193 
194 typedef ::cppu::WeakComponentImplHelper<
195  css::lang::XEventListener,
196  css::deployment::XPackageRegistry > t_BackendBase;
197 
198 
200  : protected ::dp_misc::MutexHolder, public t_BackendBase
201 {
202  //The map held originally WeakReferences. The map entries are removed in the disposing
203  //function, which is called when the XPackages are destructed or they are
204  //explicitly disposed. The latter happens, for example, when an extension is
205  //removed (see dp_manager.cxx). However, because of how the help systems work, now
206  // XPackageManager::getDeployedPackages is called often. This results in a lot
207  //of bindPackage calls which are costly. Therefore we keep hard references in
208  //the map now.
209  typedef std::unordered_map<
210  OUString, css::uno::Reference<css::deployment::XPackage> > t_string2ref;
211  t_string2ref m_bound;
212 
213 protected:
214  OUString m_cachePath;
215  css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
216 
217  OUString m_context;
218  // currently only for library containers:
219  enum class Context {
221  } m_eContext;
222 
223  static OUString StrCannotDetectMediaType() { return DpResId(RID_STR_CANNOT_DETECT_MEDIA_TYPE); }
224  static OUString StrUnsupportedMediaType() { return DpResId(RID_STR_UNSUPPORTED_MEDIA_TYPE); }
225 
226  // @@@ to be implemented by specific backend:
227  virtual css::uno::Reference<css::deployment::XPackage> bindPackage_(
228  OUString const & url, OUString const & mediaType,
229  bool bRemoved, OUString const & identifier,
230  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
231  = 0;
232 
233  void check();
234  virtual void SAL_CALL disposing() override;
235 
236  virtual ~PackageRegistryBackend() override;
238  css::uno::Sequence<css::uno::Any> const & args,
239  css::uno::Reference<css::uno::XComponentContext> const & xContext );
240 
241  /* creates a folder with a unique name.
242  If url is empty then it is created in the backend folder, otherwise
243  at a location relative to that folder specified by url.
244  */
245  OUString createFolder(
246  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
247  /* deletes folders and files.
248 
249  All folder all files which end with ".tmp" or ".tmp_" and which are
250  not used are deleted.
251  */
252  void deleteUnusedFolders(
253  std::vector< OUString> const & usedFolders);
254  /* deletes one folder with a "temporary" name and the corresponding
255  tmp file, which was used to derive the folder name.
256  */
257  static void deleteTempFolder(
258  OUString const & folderUrl);
259 
260 public:
261  static OUString StrRegisteringPackage() { return DpResId(RID_STR_REGISTERING_PACKAGE); }
262  static OUString StrRevokingPackage() { return DpResId(RID_STR_REVOKING_PACKAGE); }
263 
264  css::uno::Reference<css::uno::XComponentContext> const &
266 
267  OUString const & getCachePath() const { return m_cachePath; }
268  bool transientMode() const { return m_cachePath.isEmpty(); }
269 
270  const OUString& getContext() const {return m_context; }
271 
272  // XEventListener
273  virtual void SAL_CALL disposing( css::lang::EventObject const & evt ) override;
274 
275  // XPackageRegistry
276  virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL bindPackage(
277  OUString const & url, OUString const & mediaType,
278  sal_Bool bRemoved, OUString const & identifier,
279  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
280 
281 // virtual void SAL_CALL packageRemoved(
282 // OUString const & url, OUString const & mediaType)
283 // throw (css::deployment::DeploymentException,
284 // css::uno::RuntimeException);
285 
286 };
287 
288 }
289 }
290 
291 #endif
292 
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:140
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:607
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
virtual OUString SAL_CALL getFileFilter() override
Definition: dp_backend.cxx:759
void checkAborted(::rtl::Reference< ::dp_misc::AbortChannel > const &abortChannel)
Definition: dp_backend.cxx:395
PackageRegistryBackend * getMyBackend() const
Definition: dp_backend.cxx:703
std::unordered_map< OUString, css::uno::Reference< css::deployment::XPackage > > t_string2ref
Definition: dp_backend.h:210
virtual void SAL_CALL disposing() override
Definition: dp_backend.cxx:118
enum dp_registry::backend::PackageRegistryBackend::Context m_eContext
const OUString m_identifier
Definition: dp_backend.h:68
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:439
virtual void SAL_CALL removeEventListener(css::uno::Reference< css::lang::XEventListener > const &xListener) override
Definition: dp_backend.cxx:369
virtual void SAL_CALL addEventListener(css::uno::Reference< css::lang::XEventListener > const &xListener) override
Definition: dp_backend.cxx:360
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:419
virtual css::uno::Sequence< OUString > SAL_CALL getUpdateInformationURLs() override
Definition: dp_backend.cxx:499
virtual OUString SAL_CALL getRepositoryName() override
Definition: dp_backend.cxx:718
::cppu::WeakComponentImplHelper< css::lang::XEventListener, css::deployment::XPackageRegistry > t_BackendBase
Definition: dp_backend.h:196
Package(::rtl::Reference< PackageRegistryBackend > const &myBackend, OUString const &url, OUString const &name, OUString const &displayName, css::uno::Reference< css::deployment::XPackageTypeInfo > const &xPackageType, bool bRemoved, OUString const &identifier)
void deleteUnusedFolders(std::vector< OUString > const &usedFolders)
Definition: dp_backend.cxx:251
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:683
virtual OUString SAL_CALL getDescription() override
Definition: dp_backend.cxx:748
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
virtual void SAL_CALL dispose() override
Definition: dp_backend.cxx:352
virtual sal_Bool SAL_CALL isRemoved() override
Definition: dp_backend.cxx:731
OUString createFolder(css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
Definition: dp_backend.cxx:212
TypeInfo(OUString const &mediaType, OUString const &fileFilter, OUString const &shortDescr)
Definition: dp_backend.h:112
virtual OUString SAL_CALL getMediaType() override
Definition: dp_backend.cxx:742
::cppu::WeakComponentImplHelper< css::deployment::XPackage > t_PackageBase
Definition: dp_backend.h:48
virtual OUString SAL_CALL getName() override
Definition: dp_backend.cxx:447
const css::uno::Reference< css::deployment::XPackageTypeInfo > m_xPackageType
Definition: dp_backend.h:65
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
virtual sal_Bool SAL_CALL isBundle() override
Definition: dp_backend.cxx:413
OUString const & getCachePath() const
Definition: dp_backend.h:267
PackageRegistryBackend(css::uno::Sequence< css::uno::Any > const &args, css::uno::Reference< css::uno::XComponentContext > const &xContext)
Definition: dp_backend.cxx:78
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:531
unsigned char sal_Bool
css::uno::Reference< css::uno::XComponentContext > m_xComponentContext
Definition: dp_backend.h:215
virtual OUString SAL_CALL getShortDescription() override
Definition: dp_backend.cxx:754
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:694
virtual css::uno::Any SAL_CALL getIcon(sal_Bool highContrast, sal_Bool smallIcon) override
Definition: dp_backend.cxx:764
virtual void SAL_CALL removeModifyListener(css::uno::Reference< css::util::XModifyListener > const &xListener) override
Definition: dp_backend.cxx:387
virtual css::uno::Reference< css::task::XAbortChannel > SAL_CALL createAbortChannel() override
Definition: dp_backend.cxx:406
virtual css::beans::Optional< OUString > SAL_CALL getRegistrationDataURL() override
Definition: dp_backend.cxx:724
static uno::Reference< css::uno::XComponentContext > xContext
Definition: init.cxx:1858
virtual ::sal_Bool SAL_CALL checkDependencies(const css::uno::Reference< css::ucb::XCommandEnvironment > &xCmdEnv) override
Definition: dp_backend.cxx:430
virtual OUString SAL_CALL getVersion() override
Definition: dp_backend.cxx:461
virtual css::beans::StringPair SAL_CALL getPublisherInfo() override
Definition: dp_backend.cxx:507
static void deleteTempFolder(OUString const &folderUrl)
Definition: dp_backend.cxx:230
virtual void SAL_CALL addModifyListener(css::uno::Reference< css::util::XModifyListener > const &xListener) override
Definition: dp_backend.cxx:379
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:576
css::uno::Reference< css::uno::XComponentContext > const & getComponentContext() const
Definition: dp_backend.h:265
const OUString & getContext() const
Definition: dp_backend.h:270
virtual OUString SAL_CALL getLicenseText() override
Definition: dp_backend.cxx:491
virtual OUString SAL_CALL getURL() override
Definition: dp_backend.cxx:469
virtual void SAL_CALL disposing() override
Definition: dp_backend.cxx:333
OUString DpResId(const char *pId)
Definition: dp_shared.hxx:38
virtual OUString SAL_CALL getDisplayName() override
Definition: dp_backend.cxx:475
virtual ~Package() override
Definition: dp_backend.cxx:298
::rtl::Reference< PackageRegistryBackend > m_myBackend
Definition: dp_backend.h:61
virtual css::uno::Reference< css::deployment::XPackageTypeInfo > SAL_CALL getPackageType() override
Definition: dp_backend.cxx:526
virtual css::beans::Optional< OUString > SAL_CALL getIdentifier() override
Definition: dp_backend.cxx:452
virtual OUString SAL_CALL getDescription() override
Definition: dp_backend.cxx:483
virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL getIcon(sal_Bool bHighContrast) override
Definition: dp_backend.cxx:516