LibreOffice Module desktop (master)  1
dp_manager.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_MANAGER_DP_MANAGER_H
21 #define INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_MANAGER_DP_MANAGER_H
22 
23 #include <dp_misc.h>
24 #include <dp_interact.h>
25 #include "dp_activepackages.hxx"
26 #include <rtl/ref.hxx>
27 #include <cppuhelper/compbase.hxx>
28 #include <cppuhelper/implbase.hxx>
29 #include <ucbhelper/content.hxx>
30 #include <com/sun/star/deployment/XPackageRegistry.hpp>
31 #include <com/sun/star/deployment/XPackageManager.hpp>
32 #include <memory>
33 
34 
35 namespace dp_manager {
36 
37 typedef ::cppu::WeakComponentImplHelper<
38  css::deployment::XPackageManager > t_pm_helper;
39 
40 
41 class PackageManagerImpl final : private ::dp_misc::MutexHolder, public t_pm_helper
42 {
43  css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
44  OUString m_context;
47  OUString m_registryCache;
48  bool m_readOnly;
49 
50  OUString m_activePackages;
52  std::unique_ptr< ActivePackages > m_activePackagesDB;
53  //This mutex is only used for synchronization in addPackage
54  ::osl::Mutex m_addMutex;
55  css::uno::Reference<css::ucb::XProgressHandler> m_xLogFile;
56  inline void logIntern( css::uno::Any const & status );
57  void fireModified();
58 
59  css::uno::Reference<css::deployment::XPackageRegistry> m_xRegistry;
60 
61  void initRegistryBackends();
63  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
64  OUString detectMediaType(
65  ::ucbhelper::Content const & ucbContent, bool throw_exc = true );
66  OUString insertToActivationLayer(
67  css::uno::Sequence<css::beans::NamedValue> const & properties,
68  OUString const & mediaType,
69  ::ucbhelper::Content const & sourceContent,
70  OUString const & title, ActivePackages::Data * dbData );
72  OUString const & id, ActivePackages::Data const & dbData );
73 
74  static void deletePackageFromCache(
75  css::uno::Reference<css::deployment::XPackage> const & xPackage,
76  OUString const & destFolder );
77 
78  bool isInstalled(
79  css::uno::Reference<css::deployment::XPackage> const & package);
80 
82  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
83  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
84 
86  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
87  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
88 
90  : public ::cppu::WeakImplHelper< css::ucb::XCommandEnvironment,
91  css::ucb::XProgressHandler >
92  {
93  css::uno::Reference<css::ucb::XProgressHandler> m_xLogFile;
94  css::uno::Reference<css::ucb::XProgressHandler> m_xUserProgress;
95  css::uno::Reference<css::task::XInteractionHandler>
97 
98  public:
99  virtual ~CmdEnvWrapperImpl() override;
101  css::uno::Reference<css::ucb::XCommandEnvironment>
102  const & xUserCmdEnv,
103  css::uno::Reference<css::ucb::XProgressHandler> const & xLogFile );
104 
105  // XCommandEnvironment
106  virtual css::uno::Reference<css::task::XInteractionHandler> SAL_CALL
107  getInteractionHandler() override;
108  virtual css::uno::Reference<css::ucb::XProgressHandler> SAL_CALL
109  getProgressHandler() override;
110 
111  // XProgressHandler
112  virtual void SAL_CALL push( css::uno::Any const & Status ) override;
113  virtual void SAL_CALL update( css::uno::Any const & Status ) override;
114  virtual void SAL_CALL pop() override;
115  };
116 
117  inline void check();
118  virtual void SAL_CALL disposing() override;
119 
120  virtual ~PackageManagerImpl() override;
122  css::uno::Reference<css::uno::XComponentContext>
123  const & xComponentContext, OUString const & context )
124  : t_pm_helper( getMutex() ),
125  m_xComponentContext( xComponentContext ),
126  m_context( context ),
127  m_readOnly( true )
128  {}
129 
130 public:
131  static css::uno::Reference<css::deployment::XPackageManager> create(
132  css::uno::Reference<css::uno::XComponentContext>
133  const & xComponentContext, OUString const & context );
134 
135  // XComponent
136  virtual void SAL_CALL dispose() override;
137  virtual void SAL_CALL addEventListener(
138  css::uno::Reference<css::lang::XEventListener> const & xListener ) override;
139  virtual void SAL_CALL removeEventListener(
140  css::uno::Reference<css::lang::XEventListener> const & xListener ) override;
141 
142  // XModifyBroadcaster
143  virtual void SAL_CALL addModifyListener(
144  css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
145  virtual void SAL_CALL removeModifyListener(
146  css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
147 
148  // XPackageManager
149  virtual OUString SAL_CALL getContext() override;
150  virtual css::uno::Sequence<
151  css::uno::Reference<css::deployment::XPackageTypeInfo> > SAL_CALL
152  getSupportedPackageTypes() override;
153 
154  virtual css::uno::Reference<css::task::XAbortChannel> SAL_CALL
155  createAbortChannel() override;
156 
157  virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL addPackage(
158  OUString const & url,
159  css::uno::Sequence<css::beans::NamedValue> const & properties,
160  OUString const & mediaType,
161  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
162  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
163 
164  virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL importExtension(
165  css::uno::Reference<css::deployment::XPackage> const & extension,
166  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
167  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
168 
169  virtual void SAL_CALL removePackage(
170  OUString const & id, OUString const & fileName,
171  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
172  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
173 
174  OUString getDeployPath( ActivePackages::Data const & data );
175  css::uno::Reference<css::deployment::XPackage> getDeployedPackage_(
176  OUString const & id, OUString const & fileName,
177  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
178  css::uno::Reference<css::deployment::XPackage> getDeployedPackage_(
179  OUString const & id, ActivePackages::Data const & data,
180  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv,
181  bool ignoreAlienPlatforms = false );
182  virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL
184  OUString const & id, OUString const & fileName,
185  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
186 
187  css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
189  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
190  virtual css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
191  SAL_CALL getDeployedPackages(
192  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
193  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
194 
195  virtual void SAL_CALL reinstallDeployedPackages(
196  sal_Bool force,
197  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
198  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
199 
200  virtual ::sal_Bool SAL_CALL isReadOnly( ) override;
201 
202  virtual ::sal_Bool SAL_CALL synchronize(
203  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
204  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
205 
206  virtual css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> > SAL_CALL
208  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv) override;
209 
210  virtual sal_Int32 SAL_CALL checkPrerequisites(
211  css::uno::Reference<css::deployment::XPackage> const & extension,
212  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
213  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
214  };
215 
216 
218 {
219  ::osl::MutexGuard guard( getMutex() );
220  if (rBHelper.bInDispose || rBHelper.bDisposed)
221  throw css::lang::DisposedException(
222  "PackageManager instance has already been disposed!",
223  static_cast< ::cppu::OWeakObject * >(this) );
224 }
225 
226 
227 inline void PackageManagerImpl::logIntern( css::uno::Any const & status )
228 {
229  if (m_xLogFile.is())
230  m_xLogFile->update( status );
231 }
232 
233 }
234 
235 #endif
236 
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::osl::Mutex & getMutex() const
Definition: dp_misc.h:45
virtual void SAL_CALL dispose() override
Definition: dp_manager.cxx:508
virtual void SAL_CALL reinstallDeployedPackages(sal_Bool force, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual css::uno::Reference< css::task::XAbortChannel > SAL_CALL createAbortChannel() override
Definition: dp_manager.cxx:550
css::uno::Reference< css::deployment::XPackageRegistry > m_xRegistry
Definition: dp_manager.h:59
virtual sal_Int32 SAL_CALL checkPrerequisites(css::uno::Reference< css::deployment::XPackage > const &extension, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual ~PackageManagerImpl() override
Definition: dp_manager.cxx:463
void logIntern(css::uno::Any const &status)
Definition: dp_manager.h:227
virtual ::sal_Bool SAL_CALL synchronize(css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual void SAL_CALL removeEventListener(css::uno::Reference< css::lang::XEventListener > const &xListener) override
Definition: dp_manager.cxx:525
OUString detectMediaType(::ucbhelper::Content const &ucbContent, bool throw_exc=true)
Definition: dp_manager.cxx:574
virtual void SAL_CALL removePackage(OUString const &id, OUString const &fileName, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_manager.cxx:870
static void deletePackageFromCache(css::uno::Reference< css::deployment::XPackage > const &xPackage, OUString const &destFolder)
Definition: dp_manager.cxx:853
void insertToActivationLayerDB(OUString const &id, ActivePackages::Data const &dbData)
Definition: dp_manager.cxx:679
virtual css::uno::Sequence< css::uno::Reference< css::deployment::XPackage > > SAL_CALL getDeployedPackages(css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual ::sal_Bool SAL_CALL isReadOnly() override
std::unique_ptr< ActivePackages > m_activePackagesDB
Definition: dp_manager.h:52
css::uno::Reference< css::task::XInteractionHandler > m_xUserInteractionHandler
Definition: dp_manager.h:96
virtual void SAL_CALL push(css::uno::Any const &Status) override
bool isInstalled(css::uno::Reference< css::deployment::XPackage > const &package)
Definition: dp_manager.cxx:691
css::uno::Reference< css::uno::XComponentContext > m_xComponentContext
Definition: dp_manager.h:43
virtual css::uno::Reference< css::task::XInteractionHandler > SAL_CALL getInteractionHandler() override
unsigned char sal_Bool
virtual void SAL_CALL addEventListener(css::uno::Reference< css::lang::XEventListener > const &xListener) override
Definition: dp_manager.cxx:516
virtual css::uno::Reference< css::ucb::XProgressHandler > SAL_CALL getProgressHandler() override
css::uno::Reference< css::deployment::XPackage > getDeployedPackage_(OUString const &id, OUString const &fileName, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
css::uno::Reference< css::ucb::XProgressHandler > m_xLogFile
Definition: dp_manager.h:93
CmdEnvWrapperImpl(css::uno::Reference< css::ucb::XCommandEnvironment > const &xUserCmdEnv, css::uno::Reference< css::ucb::XProgressHandler > const &xLogFile)
css::uno::Reference< css::ucb::XProgressHandler > m_xUserProgress
Definition: dp_manager.h:94
::cppu::WeakComponentImplHelper< css::deployment::XPackageManager > t_pm_helper
Definition: dp_manager.h:38
virtual css::uno::Reference< css::deployment::XPackage > SAL_CALL importExtension(css::uno::Reference< css::deployment::XPackage > const &extension, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_manager.cxx:706
virtual css::uno::Reference< css::deployment::XPackage > SAL_CALL addPackage(OUString const &url, css::uno::Sequence< css::beans::NamedValue > const &properties, OUString const &mediaType, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_manager.cxx:718
virtual void SAL_CALL addModifyListener(css::uno::Reference< css::util::XModifyListener > const &xListener) override
Definition: dp_manager.cxx:558
static css::uno::Reference< css::deployment::XPackageManager > create(css::uno::Reference< css::uno::XComponentContext > const &xComponentContext, OUString const &context)
Definition: dp_manager.cxx:350
bool synchronizeAddedExtensions(css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
virtual OUString SAL_CALL getContext() override
Definition: dp_manager.cxx:535
virtual css::uno::Sequence< css::uno::Reference< css::deployment::XPackageTypeInfo > > SAL_CALL getSupportedPackageTypes() override
Definition: dp_manager.cxx:543
OUString getDeployPath(ActivePackages::Data const &data)
Definition: dp_manager.cxx:954
PackageManagerImpl(css::uno::Reference< css::uno::XComponentContext > const &xComponentContext, OUString const &context)
Definition: dp_manager.h:121
virtual void SAL_CALL removeModifyListener(css::uno::Reference< css::util::XModifyListener > const &xListener) override
Definition: dp_manager.cxx:566
bool synchronizeRemovedExtensions(css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
OUString insertToActivationLayer(css::uno::Sequence< css::beans::NamedValue > const &properties, OUString const &mediaType,::ucbhelper::Content const &sourceContent, OUString const &title, ActivePackages::Data *dbData)
Definition: dp_manager.cxx:612
virtual void SAL_CALL update(css::uno::Any const &Status) override
void initActivationLayer(css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
Definition: dp_manager.cxx:122
virtual css::uno::Sequence< css::uno::Reference< css::deployment::XPackage > > SAL_CALL getExtensionsWithUnacceptedLicenses(css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
css::uno::Reference< css::ucb::XProgressHandler > m_xLogFile
Definition: dp_manager.h:55
virtual css::uno::Reference< css::deployment::XPackage > SAL_CALL getDeployedPackage(OUString const &id, OUString const &fileName, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
css::uno::Sequence< css::uno::Reference< css::deployment::XPackage > > getDeployedPackages_(css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
virtual void SAL_CALL disposing() override
Definition: dp_manager.cxx:480