summaryrefslogtreecommitdiffstats
path: root/mailnews/addrbook/src/nsAbDirFactoryService.cpp
blob: 4ddf8e63581975a5fd1e59f1462a8b760f6668f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsComponentManagerUtils.h"
#include "nsServiceManagerUtils.h"
#include "nsIIOService.h"
#include "nsNetCID.h"
#include "nsMemory.h"
#include "nsStringGlue.h"
#include "plstr.h"

#include "nsAbBaseCID.h"
#include "nsAbDirFactoryService.h"
#include "nsIAbDirFactory.h"
#include "mozilla/Services.h"

NS_IMPL_ISUPPORTS(nsAbDirFactoryService, nsIAbDirFactoryService)

nsAbDirFactoryService::nsAbDirFactoryService()
{
}

nsAbDirFactoryService::~nsAbDirFactoryService()
{
}

/* nsIAbDirFactory getDirFactory (in string uri); */
NS_IMETHODIMP
nsAbDirFactoryService::GetDirFactory(const nsACString &aURI,
                                     nsIAbDirFactory** aDirFactory)
{
  NS_ENSURE_ARG_POINTER(aDirFactory);

  nsresult rv;

  // Obtain the network IO service
  nsCOMPtr<nsIIOService> nsService =
    mozilla::services::GetIOService();
  NS_ENSURE_TRUE(nsService, NS_ERROR_UNEXPECTED);
    
  // Extract the scheme
  nsAutoCString scheme;
  rv = nsService->ExtractScheme(aURI, scheme);
  NS_ENSURE_SUCCESS(rv, rv);

  // Try to find a factory using the component manager.
  nsAutoCString contractID;
  contractID.AssignLiteral(NS_AB_DIRECTORY_FACTORY_CONTRACTID_PREFIX);
  contractID.Append(scheme);

  return CallCreateInstance(contractID.get(), aDirFactory);
}