chart2: add some locking to chart::ChartType UNO service

On the libreoffice-4-3 branch, chart2_unoapi crashed with what looks
like a corrupted ChartType::m_aDataSeries triggering STL assertions.

Try to protect the mutable members with SolarMutex guards.

Change-Id: I3f2edd36b8ecf37ef60239415f70abfc8b59244d
(cherry picked from commit 6cad548ee21f19b816726a03995b9bc8905757f8)
Reviewed-on: https://gerrit.libreoffice.org/10085
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
diff --git a/chart2/source/model/template/ChartType.cxx b/chart2/source/model/template/ChartType.cxx
index 9fb275f..ea1f5ab 100644
--- a/chart2/source/model/template/ChartType.cxx
+++ b/chart2/source/model/template/ChartType.cxx
@@ -26,6 +26,7 @@
#include "CloneHelper.hxx"
#include "AxisIndexDefines.hxx"
#include "ContainerHelper.hxx"
#include <vcl/svapp.hxx>
#include <com/sun/star/chart2/AxisType.hpp>
#include <com/sun/star/beans/PropertyAttribute.hpp>

@@ -56,7 +57,11 @@ ChartType::ChartType( const ChartType & rOther ) :
    m_xContext( rOther.m_xContext ),
    m_bNotifyChanges( true )
{
    CloneHelper::CloneRefVector< Reference< chart2::XDataSeries > >( rOther.m_aDataSeries, m_aDataSeries );
    {
        SolarMutexGuard g; // access to rOther.m_aDataSeries
        CloneHelper::CloneRefVector<Reference<chart2::XDataSeries> >(
                rOther.m_aDataSeries, m_aDataSeries);
    }
    ModifyListenerHelper::addListenerToAllElements( m_aDataSeries, m_xModifyEventForwarder );
}

@@ -150,6 +155,8 @@ void SAL_CALL ChartType::addDataSeries( const Reference< chart2::XDataSeries >& 
    throw (lang::IllegalArgumentException,
           uno::RuntimeException, std::exception)
{
    SolarMutexGuard g;

    impl_addDataSeriesWithoutNotification( xDataSeries );
    fireModifyEvent();
}
@@ -161,6 +168,8 @@ void SAL_CALL ChartType::removeDataSeries( const Reference< chart2::XDataSeries 
    if( !xDataSeries.is())
        throw container::NoSuchElementException();

    SolarMutexGuard g;

    tDataSeriesContainerType::iterator aIt(
            ::std::find( m_aDataSeries.begin(), m_aDataSeries.end(), xDataSeries ) );

@@ -177,6 +186,8 @@ void SAL_CALL ChartType::removeDataSeries( const Reference< chart2::XDataSeries 
Sequence< Reference< chart2::XDataSeries > > SAL_CALL ChartType::getDataSeries()
    throw (uno::RuntimeException, std::exception)
{
    SolarMutexGuard g;

    return ContainerHelper::ContainerToSequence( m_aDataSeries );
}

@@ -184,6 +195,8 @@ void SAL_CALL ChartType::setDataSeries( const Sequence< Reference< chart2::XData
    throw (lang::IllegalArgumentException,
           uno::RuntimeException, std::exception)
{
    SolarMutexGuard g;

    m_bNotifyChanges = false;
    try
    {
@@ -309,7 +322,14 @@ void ChartType::firePropertyChangeEvent()

void ChartType::fireModifyEvent()
{
    if( m_bNotifyChanges )
    bool bNotifyChanges;

    {
        SolarMutexGuard g;
        bNotifyChanges = m_bNotifyChanges;
    }

    if (bNotifyChanges)
        m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
}

diff --git a/chart2/source/model/template/ChartType.hxx b/chart2/source/model/template/ChartType.hxx
index 82eb8033..a4c8473 100644
--- a/chart2/source/model/template/ChartType.hxx
+++ b/chart2/source/model/template/ChartType.hxx
@@ -140,7 +140,8 @@ protected:
     DECLARE_XTYPEPROVIDER()

protected:
    ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xModifyEventForwarder;
    ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >
        const m_xModifyEventForwarder;

private:
    void impl_addDataSeriesWithoutNotification(
@@ -149,13 +150,15 @@ private:

private:
    ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
        m_xContext;
        const m_xContext;

    typedef
        ::std::vector< ::com::sun::star::uno::Reference<
            ::com::sun::star::chart2::XDataSeries > >
        tDataSeriesContainerType;

    // --- mutable members: the following members need mutex guard ---

    tDataSeriesContainerType  m_aDataSeries;

    bool  m_bNotifyChanges;