defer finding dialog parent until we need it
[LibreOffice.git] / ucb / source / ucp / webdav-curl / DAVSessionFactory.cxx
blob910e7f04b95959d4e12218367b71936a6d0136b1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <memory>
21 #include "DAVSessionFactory.hxx"
22 #include "CurlSession.hxx"
23 #include "CurlUri.hxx"
25 using namespace http_dav_ucp;
26 using namespace com::sun::star;
28 DAVSessionFactory::~DAVSessionFactory()
32 rtl::Reference< DAVSession > DAVSessionFactory::createDAVSession(
33 const OUString & inUri,
34 const uno::Sequence< beans::NamedValue >& rFlags,
35 const uno::Reference< uno::XComponentContext > & rxContext )
37 std::unique_lock aGuard( m_aMutex );
39 if (!m_xProxyDecider)
40 m_xProxyDecider.reset( new ucbhelper::InternetProxyDecider( rxContext ) );
42 Map::iterator aIt = std::find_if(m_aMap.begin(), m_aMap.end(),
43 [&inUri, &rFlags](const Map::value_type& rEntry) { return rEntry.second->CanUse( inUri, rFlags ); });
45 if ( aIt == m_aMap.end() )
47 rtl::Reference< CurlSession > xElement(
48 new CurlSession(rxContext, this, inUri, rFlags, *m_xProxyDecider) );
50 aIt = m_aMap.emplace( inUri, xElement.get() ).first;
52 aIt->second->m_aContainerIt = aIt;
53 return aIt->second;
55 else if ( osl_atomic_increment( &aIt->second->m_nRefCount ) > 1 )
57 rtl::Reference< DAVSession > xElement( aIt->second );
58 osl_atomic_decrement( &aIt->second->m_nRefCount );
59 return xElement;
61 else
63 osl_atomic_decrement( &aIt->second->m_nRefCount );
64 aIt->second->m_aContainerIt = m_aMap.end();
66 rtl::Reference< CurlSession > xNewStorage = new CurlSession(rxContext, this, inUri, rFlags, *m_xProxyDecider);
67 aIt->second = xNewStorage.get();
68 aIt->second->m_aContainerIt = aIt;
69 return xNewStorage;
73 void DAVSessionFactory::releaseElement( const DAVSession * pElement )
75 assert( pElement );
76 std::unique_lock aGuard( m_aMutex );
77 if ( pElement->m_aContainerIt != m_aMap.end() )
78 m_aMap.erase( pElement->m_aContainerIt );
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */