chromium/extensions/browser/api/declarative/deduping_factory.h

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_DEDUPING_FACTORY_H__
#define EXTENSIONS_BROWSER_API_DECLARATIVE_DEDUPING_FACTORY_H__

#include <stddef.h>

#include <list>
#include <string>

#include "base/check.h"
#include "base/compiler_specific.h"
#include "base/containers/contains.h"
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/memory/ref_counted.h"

namespace extensions {

// Factory class that stores a cache of the last |N| created objects of each
// kind. These objects need to be immutable, refcounted objects that are derived
// from BaseClassT. The objects do not need to be RefCountedThreadSafe. If a new
// instance of an object is created that is identical to a pre-existing object,
// it is discarded and the pre-existing object is recycled.
//
// BaseClassT needs to provide a comparison operations. Like the following:
//
// class BaseClassT {
//   virtual bool Equals(const BaseClassT* other) const;
// };
//
// The unit test shows an example.
template <typename BaseClassT, typename ValueT>
class DedupingFactory {};

template <typename BaseClassT, typename ValueT>
DedupingFactory<BaseClassT, ValueT>::DedupingFactory(
    size_t max_number_prototypes)
    :{}

template <typename BaseClassT, typename ValueT>
DedupingFactory<BaseClassT, ValueT>::~DedupingFactory() {}

template <typename BaseClassT, typename ValueT>
void DedupingFactory<BaseClassT, ValueT>::RegisterFactoryMethod(
    const std::string& instance_type,
    typename DedupingFactory<BaseClassT, ValueT>::Parameterized parameterized,
    FactoryMethod factory_method) {}

template <typename BaseClassT, typename ValueT>
scoped_refptr<const BaseClassT>
DedupingFactory<BaseClassT, ValueT>::Instantiate(
    const std::string& instance_type,
    ValueT value,
    std::string* error,
    bool* bad_message) {}

template <typename BaseClassT, typename ValueT>
void DedupingFactory<BaseClassT, ValueT>::ClearPrototypes() {}

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_API_DECLARATIVE_DEDUPING_FACTORY_H__