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 #pragma once
21 
22 #include <dp_misc.h>
23 #include "dp_activepackages.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 
31 
32 namespace dp_manager {
33 
34 typedef ::cppu::WeakComponentImplHelper<
35  css::deployment::XPackageManager > t_pm_helper;
36 
37 
38 class PackageManagerImpl final : private ::dp_misc::MutexHolder, public t_pm_helper
39 {
40  css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
41  OUString m_context;
44  OUString m_registryCache;
45  bool m_readOnly;
46 
47  OUString m_activePackages;
49  std::unique_ptr< ActivePackages > m_activePackagesDB;
50  //This mutex is only used for synchronization in addPackage
51  ::osl::Mutex m_addMutex;
52  css::uno::Reference<css::ucb::XProgressHandler> m_xLogFile;
53  inline void logIntern( css::uno::Any const & status );
54  void fireModified();
55 
56  css::uno::Reference<css::deployment::XPackageRegistry> m_xRegistry;
57 
58  void initRegistryBackends();
60  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
61  OUString detectMediaType(
62  ::ucbhelper::Content const & ucbContent, bool throw_exc = true );
63  OUString insertToActivationLayer(
64  css::uno::Sequence<css::beans::NamedValue> const & properties,
65  OUString const & mediaType,
66  ::ucbhelper::Content const & sourceContent,
67  OUString const & title, ActivePackages::Data * dbData );
69  OUString const & id, ActivePackages::Data const & dbData );
70 
71  static void deletePackageFromCache(
72  css::uno::Reference<css::deployment::XPackage> const & xPackage,
73  OUString const & destFolder );
74 
75  bool isInstalled(
76  css::uno::Reference<css::deployment::XPackage> const & package);
77 
79  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
80  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
81 
83  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
84  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
85 
87  : public ::cppu::WeakImplHelper< css::ucb::XCommandEnvironment,
88  css::ucb::XProgressHandler >
89  {
90  css::uno::Reference<css::ucb::XProgressHandler> m_xLogFile;
91  css::uno::Reference<css::ucb::XProgressHandler> m_xUserProgress;
92  css::uno::Reference<css::task::XInteractionHandler>
94 
95  public:
96  virtual ~CmdEnvWrapperImpl() override;
98  css::uno::Reference<css::ucb::XCommandEnvironment>
99  const & xUserCmdEnv,
100  css::uno::Reference<css::ucb::XProgressHandler> const & xLogFile );
101 
102  // XCommandEnvironment
103  virtual css::uno::Reference<css::task::XInteractionHandler> SAL_CALL
104  getInteractionHandler() override;
105  virtual css::uno::Reference<css::ucb::XProgressHandler> SAL_CALL
106  getProgressHandler() override;
107 
108  // XProgressHandler
109  virtual void SAL_CALL push( css::uno::Any const & Status ) override;
110  virtual void SAL_CALL update( css::uno::Any const & Status ) override;
111  virtual void SAL_CALL pop() override;
112  };
113 
114  inline void check();
115  virtual void SAL_CALL disposing() override;
116 
117  virtual ~PackageManagerImpl() override;
119  css::uno::Reference<css::uno::XComponentContext>
120  const & xComponentContext, OUString const & context )
121  : t_pm_helper( getMutex() ),
122  m_xComponentContext( xComponentContext ),
123  m_context( context ),
124  m_readOnly( true )
125  {}
126 
127 public:
128  static css::uno::Reference<css::deployment::XPackageManager> create(
129  css::uno::Reference<css::uno::XComponentContext>
130  const & xComponentContext, OUString const & context );
131 
132  // XComponent
133  virtual void SAL_CALL dispose() override;
134  virtual void SAL_CALL addEventListener(
135  css::uno::Reference<css::lang::XEventListener> const & xListener ) override;
136  virtual void SAL_CALL removeEventListener(
137  css::uno::Reference<css::lang::XEventListener> const & xListener ) override;
138 
139  // XModifyBroadcaster
140  virtual void SAL_CALL addModifyListener(
141  css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
142  virtual void SAL_CALL removeModifyListener(
143  css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
144 
145  // XPackageManager
146  virtual OUString SAL_CALL getContext() override;
147  virtual css::uno::Sequence<
148  css::uno::Reference<css::deployment::XPackageTypeInfo> > SAL_CALL
149  getSupportedPackageTypes() override;
150 
151  virtual css::uno::Reference<css::task::XAbortChannel> SAL_CALL
152  createAbortChannel() override;
153 
154  virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL addPackage(
155  OUString const & url,
156  css::uno::Sequence<css::beans::NamedValue> const & properties,
157  OUString const & mediaType,
158  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
159  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
160 
161  virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL importExtension(
162  css::uno::Reference<css::deployment::XPackage> const & extension,
163  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
164  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
165 
166  virtual void SAL_CALL removePackage(
167  OUString const & id, OUString const & fileName,
168  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
169  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
170 
171  OUString getDeployPath( ActivePackages::Data const & data );
172  css::uno::Reference<css::deployment::XPackage> getDeployedPackage_(
173  OUString const & id, OUString const & fileName,
174  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
175  css::uno::Reference<css::deployment::XPackage> getDeployedPackage_(
176  OUString const & id, ActivePackages::Data const & data,
177  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv,
178  bool ignoreAlienPlatforms = false );
179  virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL
181  OUString const & id, OUString const & fileName,
182  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
183 
184  css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
186  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
187  virtual css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
188  SAL_CALL getDeployedPackages(
189  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
190  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
191 
192  virtual void SAL_CALL reinstallDeployedPackages(
193  sal_Bool force,
194  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
195  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
196 
197  virtual ::sal_Bool SAL_CALL isReadOnly( ) override;
198 
199  virtual ::sal_Bool SAL_CALL synchronize(
200  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
201  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
202 
203  virtual css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> > SAL_CALL
205  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv) override;
206 
207  virtual sal_Int32 SAL_CALL checkPrerequisites(
208  css::uno::Reference<css::deployment::XPackage> const & extension,
209  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
210  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
211  };
212 
213 
215 {
216  ::osl::MutexGuard guard( getMutex() );
217  if (rBHelper.bInDispose || rBHelper.bDisposed)
218  throw css::lang::DisposedException(
219  "PackageManager instance has already been disposed!",
220  static_cast< ::cppu::OWeakObject * >(this) );
221 }
222 
223 
224 inline void PackageManagerImpl::logIntern( css::uno::Any const & status )
225 {
226  if (m_xLogFile.is())
227  m_xLogFile->update( status );
228 }
229 
230 }
231 
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::osl::Mutex & getMutex() const
Definition: dp_misc.h:39
virtual void SAL_CALL dispose() override
Definition: dp_manager.cxx:497
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:539
css::uno::Reference< css::deployment::XPackageRegistry > m_xRegistry
Definition: dp_manager.h:56
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:452
void logIntern(css::uno::Any const &status)
Definition: dp_manager.h:224
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:514
OUString detectMediaType(::ucbhelper::Content const &ucbContent, bool throw_exc=true)
Definition: dp_manager.cxx:563
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:859
static void deletePackageFromCache(css::uno::Reference< css::deployment::XPackage > const &xPackage, OUString const &destFolder)
Definition: dp_manager.cxx:842
void insertToActivationLayerDB(OUString const &id, ActivePackages::Data const &dbData)
Definition: dp_manager.cxx:668
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:49
css::uno::Reference< css::task::XInteractionHandler > m_xUserInteractionHandler
Definition: dp_manager.h:93
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:680
css::uno::Reference< css::uno::XComponentContext > m_xComponentContext
Definition: dp_manager.h:40
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:505
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:90
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:91
::cppu::WeakComponentImplHelper< css::deployment::XPackageManager > t_pm_helper
Definition: dp_manager.h:35
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:695
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:707
virtual void SAL_CALL addModifyListener(css::uno::Reference< css::util::XModifyListener > const &xListener) override
Definition: dp_manager.cxx:547
static css::uno::Reference< css::deployment::XPackageManager > create(css::uno::Reference< css::uno::XComponentContext > const &xComponentContext, OUString const &context)
Definition: dp_manager.cxx:339
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:524
virtual css::uno::Sequence< css::uno::Reference< css::deployment::XPackageTypeInfo > > SAL_CALL getSupportedPackageTypes() override
Definition: dp_manager.cxx:532
OUString getDeployPath(ActivePackages::Data const &data)
Definition: dp_manager.cxx:943
PackageManagerImpl(css::uno::Reference< css::uno::XComponentContext > const &xComponentContext, OUString const &context)
Definition: dp_manager.h:118
virtual void SAL_CALL removeModifyListener(css::uno::Reference< css::util::XModifyListener > const &xListener) override
Definition: dp_manager.cxx:555
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:601
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:111
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:52
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:469