Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/host/process_stats_sender.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/location.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "remoting/host/process_stats_util.h" | |
| 12 | |
| 13 namespace remoting { | |
| 14 | |
| 15 ProcessStatsSender::ProcessStatsSender( | |
| 16 protocol::ProcessStatsStub* host_stats_stub, | |
| 17 base::TimeDelta interval) | |
| 18 : host_stats_stub_(host_stats_stub), interval_(interval) { | |
| 19 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 20 DCHECK(host_stats_stub_); | |
| 21 DCHECK(!interval_.is_zero()); | |
| 22 | |
| 23 timer_.Start(FROM_HERE, interval_, this, &ProcessStatsSender::ReportUsage); | |
| 24 } | |
| 25 | |
| 26 ProcessStatsSender::~ProcessStatsSender() { | |
| 27 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
:)
| |
| 28 timer_.Stop(); | |
| 29 } | |
| 30 | |
| 31 void ProcessStatsSender::AddProcessStatsAgent( | |
| 32 std::unique_ptr<ProcessStatsAgent> agent) { | |
| 33 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 34 agents_.push_back(std::move(agent)); | |
| 35 } | |
| 36 | |
| 37 void ProcessStatsSender::ReportUsage() { | |
| 38 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 39 if (agents_.empty()) { | |
| 40 return; | |
| 41 } | |
| 42 | |
| 43 std::vector<protocol::ProcessResourceUsage> usages; | |
| 44 for (const auto& agent : agents_) { | |
| 45 protocol::ProcessResourceUsage usage = agent->GetResourceUsage(); | |
| 46 if (!IsEmptyProcessResourceUsage(usage)) { | |
| 47 usages.push_back(std::move(usage)); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 host_stats_stub_->OnProcessStats(AggregateProcessResourceUsage(usages)); | |
| 52 } | |
| 53 | |
| 54 } // namespace remoting | |
| OLD | NEW |