LCOV - code coverage report
Current view: top level - desktop/source/deployment/registry/inc - dp_backend.h (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 7 85.7 %
Date: 2012-08-25 Functions: 4 5 80.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef INCLUDED_DP_REGISTRY_H
      30                 :            : #define INCLUDED_DP_REGISTRY_H
      31                 :            : 
      32                 :            : #include "dp_misc.h"
      33                 :            : #include "dp_resource.h"
      34                 :            : #include "dp_interact.h"
      35                 :            : #include "rtl/ref.hxx"
      36                 :            : #include "cppuhelper/weakref.hxx"
      37                 :            : #include "cppuhelper/implbase1.hxx"
      38                 :            : #include "cppuhelper/compbase1.hxx"
      39                 :            : #include "cppuhelper/compbase2.hxx"
      40                 :            : #include "tools/inetmime.hxx"
      41                 :            : #include "com/sun/star/lang/XEventListener.hpp"
      42                 :            : #include "com/sun/star/deployment/XPackageRegistry.hpp"
      43                 :            : #include "com/sun/star/deployment/XPackageManager.hpp"
      44                 :            : #include "com/sun/star/deployment/InvalidRemovedParameterException.hpp"
      45                 :            : #include <memory>
      46                 :            : #include <boost/unordered_map.hpp>
      47                 :            : #include <list>
      48                 :            : #include "dp_registry.hrc"
      49                 :            : 
      50                 :            : namespace dp_registry
      51                 :            : {
      52                 :            : namespace backend
      53                 :            : {
      54                 :            : 
      55                 :            : namespace css = ::com::sun::star;
      56                 :            : 
      57                 :            : class PackageRegistryBackend;
      58                 :            : 
      59                 :            : #define BACKEND_SERVICE_NAME "com.sun.star.deployment.PackageRegistryBackend"
      60                 :            : 
      61                 :            : typedef ::cppu::WeakComponentImplHelper1<
      62                 :            :     css::deployment::XPackage > t_PackageBase;
      63                 :            : 
      64                 :            : //==============================================================================
      65                 :            : class Package : protected ::dp_misc::MutexHolder, public t_PackageBase
      66                 :            : {
      67                 :            :     PackageRegistryBackend * getMyBackend() const;
      68                 :            :     void processPackage_impl(
      69                 :            :         bool registerPackage,
      70                 :            :         bool startup,
      71                 :            :         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
      72                 :            :         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
      73                 :            : 
      74                 :            : protected:
      75                 :            :     ::rtl::Reference<PackageRegistryBackend> m_myBackend;
      76                 :            :     const ::rtl::OUString m_url;
      77                 :            :     ::rtl::OUString m_name;
      78                 :            :     ::rtl::OUString m_displayName;
      79                 :            :     const css::uno::Reference<css::deployment::XPackageTypeInfo> m_xPackageType;
      80                 :            :     const bool m_bRemoved;
      81                 :            :     //Only set if m_bRemoved = true;
      82                 :            :     const ::rtl::OUString m_identifier;
      83                 :            : 
      84                 :            :     void check() const;
      85                 :            :     void fireModified();
      86                 :            :     virtual void SAL_CALL disposing();
      87                 :            : 
      88                 :            :     void checkAborted(
      89                 :            :         ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel );
      90                 :            : 
      91                 :            :     // @@@ to be implemented by specific backend:
      92                 :            :     virtual css::beans::Optional< css::beans::Ambiguous<sal_Bool> >
      93                 :            :     isRegistered_(
      94                 :            :         ::osl::ResettableMutexGuard & guard,
      95                 :            :         ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel,
      96                 :            :         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
      97                 :            :         = 0;
      98                 :            :     virtual void processPackage_(
      99                 :            :         ::osl::ResettableMutexGuard & guard,
     100                 :            :         bool registerPackage,
     101                 :            :         bool startup,
     102                 :            :         ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel,
     103                 :            :         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
     104                 :            :         = 0;
     105                 :            : 
     106                 :            :     virtual ~Package();
     107                 :            :     Package( ::rtl::Reference<PackageRegistryBackend> const & myBackend,
     108                 :            :              ::rtl::OUString const & url,
     109                 :            :              ::rtl::OUString const & name,
     110                 :            :              ::rtl::OUString const & displayName,
     111                 :            :              css::uno::Reference<css::deployment::XPackageTypeInfo> const &
     112                 :            :              xPackageType,
     113                 :            :              bool bRemoved,
     114                 :            :              ::rtl::OUString const & identifier);
     115                 :            : 
     116                 :            : public:
     117                 :            : 
     118                 :            :     class TypeInfo :
     119                 :            :         public ::cppu::WeakImplHelper1<css::deployment::XPackageTypeInfo>
     120                 :            :     {
     121                 :            :         const ::rtl::OUString m_mediaType;
     122                 :            :         const ::rtl::OUString m_fileFilter;
     123                 :            :         const ::rtl::OUString m_shortDescr;
     124                 :            :         const sal_uInt16 m_smallIcon;
     125                 :            :     public:
     126                 :            :         virtual ~TypeInfo();
     127                 :       5700 :         TypeInfo( ::rtl::OUString const & mediaType,
     128                 :            :                   ::rtl::OUString const & fileFilter,
     129                 :            :                   ::rtl::OUString const & shortDescr,
     130                 :            :                   sal_uInt16 smallIcon)
     131                 :            :             : m_mediaType(mediaType), m_fileFilter(fileFilter),
     132                 :            :               m_shortDescr(shortDescr),
     133                 :       5700 :               m_smallIcon(smallIcon)
     134                 :       5700 :             {}
     135                 :            :         // XPackageTypeInfo
     136                 :            :         virtual ::rtl::OUString SAL_CALL getMediaType()
     137                 :            :             throw (css::uno::RuntimeException);
     138                 :            :         virtual ::rtl::OUString SAL_CALL getDescription()
     139                 :            :             throw (css::deployment::ExtensionRemovedException,
     140                 :            :                    css::uno::RuntimeException);
     141                 :            :         virtual ::rtl::OUString SAL_CALL getShortDescription()
     142                 :            :             throw (css::deployment::ExtensionRemovedException,
     143                 :            :                    css::uno::RuntimeException);
     144                 :            :         virtual ::rtl::OUString SAL_CALL getFileFilter()
     145                 :            :             throw (css::uno::RuntimeException);
     146                 :            :         virtual css::uno::Any SAL_CALL getIcon( sal_Bool highContrast,
     147                 :            :                                                 sal_Bool smallIcon )
     148                 :            :             throw (css::uno::RuntimeException);
     149                 :            :     };
     150                 :            : 
     151                 :            :     // XComponent
     152                 :            :     virtual void SAL_CALL dispose() throw (css::uno::RuntimeException);
     153                 :            :     virtual void SAL_CALL addEventListener(
     154                 :            :         css::uno::Reference<css::lang::XEventListener> const & xListener )
     155                 :            :         throw (css::uno::RuntimeException);
     156                 :            :     virtual void SAL_CALL removeEventListener(
     157                 :            :         css::uno::Reference<css::lang::XEventListener> const & xListener )
     158                 :            :         throw (css::uno::RuntimeException);
     159                 :            : 
     160                 :            :     // XModifyBroadcaster
     161                 :            :     virtual void SAL_CALL addModifyListener(
     162                 :            :         css::uno::Reference<css::util::XModifyListener> const & xListener )
     163                 :            :         throw (css::uno::RuntimeException);
     164                 :            :     virtual void SAL_CALL removeModifyListener(
     165                 :            :         css::uno::Reference<css::util::XModifyListener> const & xListener )
     166                 :            :         throw (css::uno::RuntimeException);
     167                 :            : 
     168                 :            :     // XPackage
     169                 :            :     virtual css::uno::Reference<css::task::XAbortChannel> SAL_CALL
     170                 :            :     createAbortChannel() throw (css::uno::RuntimeException);
     171                 :            :     virtual css::beans::Optional< css::beans::Ambiguous<sal_Bool> >
     172                 :            :     SAL_CALL isRegistered(
     173                 :            :         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
     174                 :            :         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
     175                 :            :         throw (css::deployment::DeploymentException,
     176                 :            :                css::ucb::CommandFailedException,
     177                 :            :                css::ucb::CommandAbortedException,
     178                 :            :                css::uno::RuntimeException);
     179                 :            : 
     180                 :            :     virtual ::sal_Int32 SAL_CALL checkPrerequisites(
     181                 :            :         const css::uno::Reference< css::task::XAbortChannel >& xAbortChannel,
     182                 :            :         const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv,
     183                 :            :         sal_Bool noLicenseChecking)
     184                 :            :         throw (css::deployment::DeploymentException,
     185                 :            :                css::deployment::ExtensionRemovedException,
     186                 :            :                css::ucb::CommandFailedException,
     187                 :            :                css::ucb::CommandAbortedException,
     188                 :            :                css::uno::RuntimeException);
     189                 :            : 
     190                 :            :     virtual ::sal_Bool SAL_CALL checkDependencies(
     191                 :            :         const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv )
     192                 :            :         throw (css::deployment::DeploymentException,
     193                 :            :                css::deployment::ExtensionRemovedException,
     194                 :            :                css::ucb::CommandFailedException,
     195                 :            :                css::uno::RuntimeException);
     196                 :            : 
     197                 :            :     virtual void SAL_CALL registerPackage(
     198                 :            :         sal_Bool startup,
     199                 :            :         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
     200                 :            :         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
     201                 :            :         throw (css::deployment::DeploymentException,
     202                 :            :                css::deployment::ExtensionRemovedException,
     203                 :            :                css::ucb::CommandFailedException,
     204                 :            :                css::ucb::CommandAbortedException,
     205                 :            :                css::lang::IllegalArgumentException, css::uno::RuntimeException);
     206                 :            :     virtual void SAL_CALL revokePackage(
     207                 :            :         sal_Bool startup,
     208                 :            :         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
     209                 :            :         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
     210                 :            :         throw (css::deployment::DeploymentException,
     211                 :            :                css::ucb::CommandFailedException,
     212                 :            :                css::ucb::CommandAbortedException,
     213                 :            :                css::lang::IllegalArgumentException,
     214                 :            :                css::uno::RuntimeException);
     215                 :            :     virtual sal_Bool SAL_CALL isBundle()
     216                 :            :         throw (css::uno::RuntimeException);
     217                 :            :     virtual css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
     218                 :            :     SAL_CALL getBundle(
     219                 :            :         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
     220                 :            :         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
     221                 :            :         throw (css::deployment::DeploymentException,
     222                 :            :                css::ucb::CommandFailedException,
     223                 :            :                css::ucb::CommandAbortedException,
     224                 :            :                css::lang::IllegalArgumentException,
     225                 :            :                css::uno::RuntimeException);
     226                 :            :     virtual ::rtl::OUString SAL_CALL getName()
     227                 :            :         throw (css::uno::RuntimeException);
     228                 :            :     virtual css::beans::Optional< ::rtl::OUString > SAL_CALL getIdentifier()
     229                 :            :         throw (css::uno::RuntimeException);
     230                 :            :     virtual ::rtl::OUString SAL_CALL getVersion()
     231                 :            :         throw (css::deployment::ExtensionRemovedException,
     232                 :            :                css::uno::RuntimeException);
     233                 :            :     virtual ::rtl::OUString SAL_CALL getURL()
     234                 :            :         throw (css::uno::RuntimeException);
     235                 :            :     virtual ::rtl::OUString SAL_CALL getDisplayName()
     236                 :            :         throw (css::deployment::ExtensionRemovedException,
     237                 :            :                css::uno::RuntimeException);
     238                 :            :     virtual ::rtl::OUString SAL_CALL getDescription()
     239                 :            :         throw (css::deployment::ExtensionRemovedException,
     240                 :            :                css::uno::RuntimeException);
     241                 :            :     virtual ::rtl::OUString SAL_CALL getLicenseText()
     242                 :            :         throw (css::deployment::ExtensionRemovedException,
     243                 :            :                css::uno::RuntimeException);
     244                 :            :     virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL
     245                 :            :     getUpdateInformationURLs()
     246                 :            :         throw (css::deployment::ExtensionRemovedException,
     247                 :            :                css::uno::RuntimeException);
     248                 :            :     virtual css::beans::StringPair SAL_CALL getPublisherInfo()
     249                 :            :         throw (css::deployment::ExtensionRemovedException,
     250                 :            :                css::uno::RuntimeException);
     251                 :            :     virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL
     252                 :            :     getIcon( sal_Bool bHighContrast )
     253                 :            :         throw (css::deployment::ExtensionRemovedException,
     254                 :            :                css::uno::RuntimeException);
     255                 :            :     virtual css::uno::Reference<css::deployment::XPackageTypeInfo> SAL_CALL
     256                 :            :     getPackageType() throw (css::uno::RuntimeException);
     257                 :            :     virtual void SAL_CALL exportTo(
     258                 :            :         ::rtl::OUString const & destFolderURL,
     259                 :            :         ::rtl::OUString const & newTitle,
     260                 :            :         sal_Int32 nameClashAction,
     261                 :            :         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
     262                 :            :         throw (css::deployment::ExtensionRemovedException,
     263                 :            :                css::ucb::CommandFailedException,
     264                 :            :                css::ucb::CommandAbortedException, css::uno::RuntimeException);
     265                 :            :     virtual ::rtl::OUString SAL_CALL getRepositoryName()
     266                 :            :         throw (css::uno::RuntimeException);
     267                 :            :     virtual css::beans::Optional< ::rtl::OUString > SAL_CALL getRegistrationDataURL()
     268                 :            :         throw (css::deployment::ExtensionRemovedException,
     269                 :            :                css::uno::RuntimeException);
     270                 :            :     virtual sal_Bool SAL_CALL isRemoved()
     271                 :            :         throw (css::uno::RuntimeException);
     272                 :            : 
     273                 :            : };
     274                 :            : 
     275                 :            : typedef ::cppu::WeakComponentImplHelper2<
     276                 :            :     css::lang::XEventListener,
     277                 :            :     css::deployment::XPackageRegistry > t_BackendBase;
     278                 :            : 
     279                 :            : //==============================================================================
     280                 :            : class PackageRegistryBackend
     281                 :            :     : protected ::dp_misc::MutexHolder, public t_BackendBase
     282                 :            : {
     283                 :            :     //The map held originally WeakReferences. The map entries are removed in the disposing
     284                 :            :     //function, which is called when the XPackages are destructed or they are
     285                 :            :     //explicitly disposed. The latter happens, for example, when a extension is
     286                 :            :     //removed (see dp_manager.cxx). However, because of how the help systems work, now
     287                 :            :     // XPackageManager::getDeployedPackages is called often. This results in a lot
     288                 :            :     //of bindPackage calls which are costly. Therefore we keep hard references in
     289                 :            :     //the map now.
     290                 :            :     typedef ::boost::unordered_map<
     291                 :            :         ::rtl::OUString, css::uno::Reference<css::deployment::XPackage>,
     292                 :            :         ::rtl::OUStringHash > t_string2ref;
     293                 :            :     t_string2ref m_bound;
     294                 :            : 
     295                 :            : protected:
     296                 :            :     ::rtl::OUString m_cachePath;
     297                 :            :     css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
     298                 :            : 
     299                 :            :     ::rtl::OUString m_context;
     300                 :            :     // currently only for library containers:
     301                 :            :     enum {
     302                 :            :         CONTEXT_UNKNOWN,
     303                 :            :         CONTEXT_USER, CONTEXT_SHARED,CONTEXT_BUNDLED, CONTEXT_TMP,
     304                 :            :         CONTEXT_DOCUMENT
     305                 :            :     } m_eContext;
     306                 :            :     bool m_readOnly;
     307                 :            : 
     308                 :            :     struct StrCannotDetectMediaType : public ::dp_misc::StaticResourceString<
     309                 :            :         StrCannotDetectMediaType, RID_STR_CANNOT_DETECT_MEDIA_TYPE> {};
     310                 :            :     struct StrUnsupportedMediaType : public ::dp_misc::StaticResourceString<
     311                 :            :         StrUnsupportedMediaType, RID_STR_UNSUPPORTED_MEDIA_TYPE> {};
     312                 :            : 
     313                 :            :     // @@@ to be implemented by specific backend:
     314                 :            :     virtual css::uno::Reference<css::deployment::XPackage> bindPackage_(
     315                 :            :         ::rtl::OUString const & url, ::rtl::OUString const & mediaType,
     316                 :            :         sal_Bool bRemoved, ::rtl::OUString const & identifier,
     317                 :            :         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
     318                 :            :         = 0;
     319                 :            : 
     320                 :            :     void check();
     321                 :            :     virtual void SAL_CALL disposing();
     322                 :            : 
     323                 :            :     virtual ~PackageRegistryBackend();
     324                 :            :     PackageRegistryBackend(
     325                 :            :         css::uno::Sequence<css::uno::Any> const & args,
     326                 :            :         css::uno::Reference<css::uno::XComponentContext> const & xContext );
     327                 :            : 
     328                 :            :     /* creates a folder with a unique name.
     329                 :            :        If url is empty then it is created in the the backend folder, otherwise
     330                 :            :        at a location relative to that folder specified by url.
     331                 :            :     */
     332                 :            :     ::rtl::OUString createFolder(
     333                 :            :         ::rtl::OUString const & relUrl,
     334                 :            :         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
     335                 :            :     /* deletes folders and files.
     336                 :            : 
     337                 :            :        All folder all files which end with ".tmp" or ".tmp_" and which are
     338                 :            :        not used are deleted.
     339                 :            :      */
     340                 :            :     void deleteUnusedFolders(
     341                 :            :         ::rtl::OUString const & relUrl,
     342                 :            :         ::std::list< ::rtl::OUString> const & usedFolders);
     343                 :            :     /* deletes one folder with a "temporary" name and the corresponding
     344                 :            :        tmp file, which was used to derive the folder name.
     345                 :            :     */
     346                 :            :     static void deleteTempFolder(
     347                 :            :         ::rtl::OUString const & folderUrl);
     348                 :            : 
     349                 :            :     ::rtl::OUString getSharedRegistrationDataURL(
     350                 :            :         css::uno::Reference<css::deployment::XPackage> const & extension,
     351                 :            :         css::uno::Reference<css::deployment::XPackage> const & item);
     352                 :            : 
     353                 :            :     /* The backends must implement this function, which is called
     354                 :            :        from XPackageRegistry::packageRemoved (also implemented here).
     355                 :            :        This ensure that the backends clean up their registration data
     356                 :            :        when an extension was removed.
     357                 :            :     */
     358                 :            : //    virtual void deleteDbEntry( ::rtl::OUString const & url) = 0;
     359                 :            : 
     360                 :            : 
     361                 :            : 
     362                 :            : public:
     363                 :            :     struct StrRegisteringPackage : public ::dp_misc::StaticResourceString<
     364                 :            :         StrRegisteringPackage, RID_STR_REGISTERING_PACKAGE> {};
     365                 :            :     struct StrRevokingPackage : public ::dp_misc::StaticResourceString<
     366                 :            :         StrRevokingPackage, RID_STR_REVOKING_PACKAGE> {};
     367                 :            : 
     368                 :            :     inline css::uno::Reference<css::uno::XComponentContext> const &
     369                 :       3714 :     getComponentContext() const { return m_xComponentContext; }
     370                 :            : 
     371                 :       9158 :     inline ::rtl::OUString const & getCachePath() const { return m_cachePath; }
     372                 :       8778 :     inline bool transientMode() const { return m_cachePath.isEmpty(); }
     373                 :            : 
     374                 :          0 :     inline ::rtl::OUString getContext() const {return m_context; }
     375                 :            : 
     376                 :            :     // XEventListener
     377                 :            :     virtual void SAL_CALL disposing( css::lang::EventObject const & evt )
     378                 :            :         throw (css::uno::RuntimeException);
     379                 :            : 
     380                 :            :     // XPackageRegistry
     381                 :            :     virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL bindPackage(
     382                 :            :         ::rtl::OUString const & url, ::rtl::OUString const & mediaType,
     383                 :            :         sal_Bool bRemoved, ::rtl::OUString const & identifier,
     384                 :            :         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
     385                 :            :         throw (css::deployment::DeploymentException,
     386                 :            :                css::deployment::InvalidRemovedParameterException,
     387                 :            :                css::ucb::CommandFailedException,
     388                 :            :                css::lang::IllegalArgumentException, css::uno::RuntimeException);
     389                 :            : 
     390                 :            : //     virtual void SAL_CALL packageRemoved(
     391                 :            : //         ::rtl::OUString const & url, ::rtl::OUString const & mediaType)
     392                 :            : //         throw (css::deployment::DeploymentException,
     393                 :            : //                css::uno::RuntimeException);
     394                 :            : 
     395                 :            : };
     396                 :            : 
     397                 :            : }
     398                 :            : }
     399                 :            : 
     400                 :            : #endif
     401                 :            : 
     402                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10