LCOV - code coverage report
Current view: top level - desktop/source/deployment/registry/inc - dp_backend.h (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 6 7 85.7 %
Date: 2015-06-13 12:38:46 Functions: 4 5 80.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11