summaryrefslogtreecommitdiff
path: root/chromium/ui/compositor/throughput_tracker.cc
blob: 50e379fdc3fb582437dfbde3ee968198ea2aabc2 (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
57
58
59
60
61
62
63
64
65
// Copyright 2020 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 "ui/compositor/throughput_tracker.h"

#include <utility>

#include "base/callback.h"
#include "base/check.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) {
  // Start after |host_| destruction is likely an error.
  DCHECK(host_);
  DCHECK(!started_);

  started_ = true;
  host_->StartThroughputTracker(id_, std::move(callback));
}

void ThroughputTracker::Stop() {
  DCHECK(started_);

  started_ = false;
  if (host_)
    host_->StopThroughtputTracker(id_);
}

void ThroughputTracker::Cancel() {
  DCHECK(started_);

  started_ = false;
  if (host_)
    host_->CancelThroughtputTracker(id_);
}

}  // namespace ui