#ifndef MEDIA_CAPABILITIES_PENDING_OPERATIONS_H_
#define MEDIA_CAPABILITIES_PENDING_OPERATIONS_H_
#include "base/cancelable_callback.h"
#include "base/containers/flat_map.h"
#include "base/memory/weak_ptr.h"
#include "base/sequence_checker.h"
#include "base/time/time.h"
#include "media/base/media_export.h"
namespace media {
class MEDIA_EXPORT PendingOperations {
public:
using Id = int;
class PendingOperation {
public:
PendingOperation(
std::string uma_str,
std::unique_ptr<base::CancelableOnceClosure> timeout_closure);
virtual ~PendingOperation();
PendingOperation(const PendingOperation&) = delete;
PendingOperation& operator=(const PendingOperation&) = delete;
void UmaHistogramOpTime(base::TimeDelta duration);
void OnTimeout();
private:
friend class VideoDecodeStatsDBImplTest;
friend class WebrtcVideoStatsDBImplTest;
const std::string uma_str_;
std::unique_ptr<base::CancelableOnceClosure> timeout_closure_;
const base::TimeTicks start_ticks_;
};
explicit PendingOperations(std::string uma_prefix);
~PendingOperations();
Id Start(std::string_view uma_str);
void Complete(Id op_id);
void OnTimeout(Id id);
const base::flat_map<Id, std::unique_ptr<PendingOperation>>&
get_pending_ops_for_test() const {
return pending_ops_;
}
private:
const std::string uma_prefix_;
Id next_op_id_ = 0;
base::flat_map<Id, std::unique_ptr<PendingOperation>> pending_ops_;
SEQUENCE_CHECKER(sequence_checker_);
base::WeakPtrFactory<PendingOperations> weak_ptr_factory_{this};
};
}
#endif