Chromium Code Reviews| Index: remoting/host/process_stats_sender.cc |
| diff --git a/remoting/host/process_stats_sender.cc b/remoting/host/process_stats_sender.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3db8b8e0fba055f813efba955ad00f1938312060 |
| --- /dev/null |
| +++ b/remoting/host/process_stats_sender.cc |
| @@ -0,0 +1,54 @@ |
| +// Copyright 2017 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 "remoting/host/process_stats_sender.h" |
| + |
| +#include <utility> |
| + |
| +#include "base/location.h" |
| +#include "base/logging.h" |
| +#include "remoting/host/process_stats_util.h" |
| + |
| +namespace remoting { |
| + |
| +ProcessStatsSender::ProcessStatsSender( |
| + protocol::ProcessStatsStub* host_stats_stub, |
| + base::TimeDelta interval) |
| + : host_stats_stub_(host_stats_stub), interval_(interval) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + DCHECK(host_stats_stub_); |
| + DCHECK(!interval_.is_zero()); |
| + |
| + timer_.Start(FROM_HERE, interval_, this, &ProcessStatsSender::ReportUsage); |
| +} |
| + |
| +ProcessStatsSender::~ProcessStatsSender() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
|
joedow
2017/04/24 17:16:08
nit: You don't need this DCHECK as thread_checker_
Hzj_jie
2017/04/25 00:17:53
https://cs.chromium.org/chromium/src/base/threadin
joedow
2017/04/25 15:57:27
The ThreadChecker class contains a 'SequenceToken'
Hzj_jie
2017/04/25 22:19:19
SequenceToken has no destructor. Have I misunderst
Sergey Ulanov
2017/04/26 05:42:44
I think you are right. I thought myself that Threa
joedow
2017/04/26 16:07:57
I was looking at ScopedSequenceToken :( I did a q
Hzj_jie
2017/04/26 20:47:19
:)
|
| + timer_.Stop(); |
| +} |
| + |
| +void ProcessStatsSender::AddProcessStatsAgent( |
| + std::unique_ptr<ProcessStatsAgent> agent) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + agents_.push_back(std::move(agent)); |
| +} |
| + |
| +void ProcessStatsSender::ReportUsage() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + if (agents_.empty()) { |
| + return; |
| + } |
| + |
| + std::vector<protocol::ProcessResourceUsage> usages; |
| + for (const auto& agent : agents_) { |
| + protocol::ProcessResourceUsage usage = agent->GetResourceUsage(); |
| + if (!IsEmptyProcessResourceUsage(usage)) { |
| + usages.push_back(std::move(usage)); |
| + } |
| + } |
| + |
| + host_stats_stub_->OnProcessStats(AggregateProcessResourceUsage(usages)); |
| +} |
| + |
| +} // namespace remoting |