summaryrefslogtreecommitdiffstats
path: root/chrome/common/classfactory.cc
blob: ba32c15b0e08a88eb3fe75882e1ace58eaa914f8 (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
55
56
//
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "classfactory.h"


GenericClassFactory::GenericClassFactory() :
  reference_count_(1)
{
  InterlockedIncrement(&object_count_);
}


GenericClassFactory::~GenericClassFactory() {
  InterlockedDecrement(&object_count_);
}


LONG GenericClassFactory::object_count_ = 0;


STDMETHODIMP GenericClassFactory::QueryInterface(REFIID riid,
                                                 LPVOID* ppobject) {
  *ppobject = NULL;

  if (IsEqualIID(riid, IID_IUnknown) ||
      IsEqualIID(riid, IID_IClassFactory))
    *ppobject = static_cast<IClassFactory*>(this);
  else
    return E_NOINTERFACE;

  this->AddRef();
  return S_OK;
}


STDMETHODIMP_(ULONG) GenericClassFactory::AddRef() {
  return InterlockedIncrement(&reference_count_);
}


STDMETHODIMP_(ULONG) GenericClassFactory::Release() {
  if(0 == InterlockedDecrement(&reference_count_)) {
    delete this;
    return 0;
  }
  return reference_count_;
}


STDMETHODIMP GenericClassFactory::LockServer(BOOL) {
  return E_NOTIMPL;
}