chromium/components/performance_manager/owned_objects.h

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

#ifndef COMPONENTS_PERFORMANCE_MANAGER_OWNED_OBJECTS_H_
#define COMPONENTS_PERFORMANCE_MANAGER_OWNED_OBJECTS_H_

#include <memory>

#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/containers/flat_set.h"
#include "base/containers/unique_ptr_adapters.h"

namespace performance_manager {

namespace internal {

// Builds the callback type from the ObjectType and CallbackArgType.
template <typename ObjectType, typename CallbackArgType>
struct CallbackType {};

// Specialization for void CallbackArgType.
CallbackType<ObjectType, void>;

}  // namespace internal

// Helper class defining storage for a collection of "owned" objects. These
// are objects whose ownership has explicitly been passed to the container.
// The objects can be taken back from the container, or will be torn down
// with the container. Note that the owner of this container should
// explicitly call ReleaseObjects prior to the object being torn down; the
// container expects to be empty at destruction.
// TODO: Once C++17 is available, use "auto" here and simply accept the 2
// member function pointers, deducing all other type info.
template <typename OwnedType,
          typename CallbackArgType,
          typename internal::CallbackType<OwnedType, CallbackArgType>::Type
              OnPassedMemberFunction,
          typename internal::CallbackType<OwnedType, CallbackArgType>::Type
              OnTakenMemberFunction>
class OwnedObjects {};

}  // namespace performance_manager

#endif  // COMPONENTS_PERFORMANCE_MANAGER_OWNED_OBJECTS_H_