LibreOffice Module ucb (master)  1
neon/DAVSessionFactory.cxx
Go to the documentation of this file.
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 #include <memory>
30 #include "DAVSessionFactory.hxx"
31 #include "NeonSession.hxx"
32 #include "NeonUri.hxx"
33 #include <osl/diagnose.h>
34 
35 using namespace webdav_ucp;
36 using namespace com::sun::star;
37 
39 {
40 }
41 
43  const OUString & inUri,
44  const uno::Sequence< beans::NamedValue >& rFlags,
45  const uno::Reference< uno::XComponentContext > & rxContext )
46 {
47  osl::MutexGuard aGuard( m_aMutex );
48 
49  m_xContext = rxContext;
50 
51  if (!m_xProxyDecider)
52  m_xProxyDecider.reset( new ucbhelper::InternetProxyDecider( rxContext ) );
53 
54  Map::iterator aIt = std::find_if(m_aMap.begin(), m_aMap.end(),
55  [&inUri, &rFlags](const Map::value_type& rEntry) { return rEntry.second->CanUse( inUri, rFlags ); });
56 
57  if ( aIt == m_aMap.end() )
58  {
59  NeonUri aURI( inUri );
60 
61  std::unique_ptr<DAVSession> xElement(
62  new NeonSession(this, inUri, rFlags, *m_xProxyDecider));
63 
64  aIt = m_aMap.emplace( inUri, xElement.get() ).first;
65  aIt->second->m_aContainerIt = aIt;
66  xElement.release();
67  return aIt->second;
68  }
69  else if ( osl_atomic_increment( &aIt->second->m_nRefCount ) > 1 )
70  {
71  rtl::Reference< DAVSession > xElement( aIt->second );
72  osl_atomic_decrement( &aIt->second->m_nRefCount );
73  return xElement;
74  }
75  else
76  {
77  osl_atomic_decrement( &aIt->second->m_nRefCount );
78  aIt->second->m_aContainerIt = m_aMap.end();
79 
80  // If URL scheme is different from http or https we definitely
81  // have to use a proxy and therefore can optimize the getProxy
82  // call a little:
83  NeonUri aURI( inUri );
84 
85  aIt->second = new NeonSession(this, inUri, rFlags, *m_xProxyDecider);
86  aIt->second->m_aContainerIt = aIt;
87  return aIt->second;
88  }
89 }
90 
92 {
93  OSL_ASSERT( pElement );
94  osl::MutexGuard aGuard( m_aMutex );
95  if ( pElement->m_aContainerIt != m_aMap.end() )
96  m_aMap.erase( pElement->m_aContainerIt );
97 }
98 
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::osl::Mutex m_aMutex
void releaseElement(DAVSession const *pElement)
DAVSessionFactory::Map::iterator m_aContainerIt
rtl::Reference< DAVSession > createDAVSession(const OUString &inUri, const ::uno::Sequence< css::beans::NamedValue > &rFlags, const ::uno::Reference< ::uno::XComponentContext > &rxContext)
const uno::Reference< uno::XComponentContext > m_xContext