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