LibreOffice Module ucb (master)  1
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  * 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 #include <memory>
21 #include "DAVSessionFactory.hxx"
22 #include "SerfSession.hxx"
23 #include "SerfUri.hxx"
24 
25 using namespace http_dav_ucp;
26 using namespace com::sun::star;
27 
29 {
30 }
31 
33  const OUString & inUri,
34  const uno::Reference< uno::XComponentContext > & rxContext )
35 {
36  osl::MutexGuard aGuard( m_aMutex );
37 
38  if ( !m_xProxyDecider.get() )
39  m_xProxyDecider.reset( new ucbhelper::InternetProxyDecider( rxContext ) );
40 
41  Map::iterator aIt = std::find_if(m_aMap.begin(), m_aMap.end(),
42  [&inUri](const Map::value_type& rEntry) { return rEntry.second->CanUse( inUri ); });
43 
44  if ( aIt == m_aMap.end() )
45  {
46  SerfUri aURI( inUri );
47 
48  std::unique_ptr< DAVSession > xElement(
49  new SerfSession( this, inUri, *m_xProxyDecider.get() ) );
50 
51  aIt = m_aMap.emplace( inUri, xElement.get() ).first;
52  aIt->second->m_aContainerIt = aIt;
53  xElement.release();
54  return aIt->second;
55  }
56  else if ( osl_atomic_increment( &aIt->second->m_nRefCount ) > 1 )
57  {
58  rtl::Reference< DAVSession > xElement( aIt->second );
59  osl_atomic_decrement( &aIt->second->m_nRefCount );
60  return xElement;
61  }
62  else
63  {
64  osl_atomic_decrement( &aIt->second->m_nRefCount );
65  aIt->second->m_aContainerIt = m_aMap.end();
66 
67  // If URL scheme is different from http or https we definitely
68  // have to use a proxy and therefore can optimize the getProxy
69  // call a little:
70  SerfUri aURI( inUri );
71 
72  aIt->second = new SerfSession( this, inUri, *m_xProxyDecider.get() );
73  aIt->second->m_aContainerIt = aIt;
74  return aIt->second;
75  }
76 }
77 
79 {
80  assert( pElement );
81  osl::MutexGuard aGuard( m_aMutex );
82  if ( pElement->m_aContainerIt != m_aMap.end() )
83  m_aMap.erase( pElement->m_aContainerIt );
84 }
85 
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::osl::Mutex m_aMutex
void releaseElement(DAVSession *pElement)
DAVSessionFactory::Map::iterator m_aContainerIt
Definition: DAVSession.hxx:194
rtl::Reference< DAVSession > createDAVSession(const OUString &inUri, const css::uno::Reference< css::uno::XComponentContext > &rxContext)