#include "ui/compositor/throughput_tracker.h"
#include <utility>
#include "base/check.h"
#include "base/functional/callback.h"
namespace ui {
ThroughputTracker::ThroughputTracker(TrackerId id,
base::WeakPtr<ThroughputTrackerHost> host)
: id_(id), host_(std::move(host)) {
DCHECK(host_);
}
ThroughputTracker::ThroughputTracker(ThroughputTracker&& other) {
*this = std::move(other);
}
ThroughputTracker& ThroughputTracker::operator=(ThroughputTracker&& other) {
id_ = other.id_;
host_ = std::move(other.host_);
started_ = other.started_;
other.id_ = kInvalidId;
other.host_.reset();
other.started_ = false;
return *this;
}
ThroughputTracker::~ThroughputTracker() {
if (started_)
Cancel();
}
void ThroughputTracker::Start(ThroughputTrackerHost::ReportCallback callback) {
DCHECK(host_);
DCHECK(!started_);
started_ = true;
host_->StartThroughputTracker(id_, std::move(callback));
}
bool ThroughputTracker::Stop() {
DCHECK(started_);
started_ = false;
if (host_)
return host_->StopThroughtputTracker(id_);
return false;
}
void ThroughputTracker::Cancel() {
if (!started_)
return;
started_ = false;
if (host_)
host_->CancelThroughtputTracker(id_);
}
}