Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: remoting/host/process_stats_sender.cc

Issue 2775983003: [Chromoting] Retrieve process resource usage (ProcessStats) and its tests (Closed)
Patch Set: Update the test case Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_agent.h"
12 #include "remoting/host/process_stats_util.h"
13
14 namespace remoting {
15
16 ProcessStatsSender::ProcessStatsSender(
17 protocol::ProcessStatsStub* host_stats_stub,
18 base::TimeDelta interval)
19 : host_stats_stub_(host_stats_stub), interval_(interval) {
20 DCHECK(thread_checker_.CalledOnValidThread());
21 DCHECK(host_stats_stub_);
22 DCHECK(!interval_.is_zero());
23
24 timer_.Start(FROM_HERE, interval_, this, &ProcessStatsSender::ReportUsage);
25 }
26
27 ProcessStatsSender::~ProcessStatsSender() {
28 DCHECK(thread_checker_.CalledOnValidThread());
29 timer_.Stop();
30 }
31
32 void ProcessStatsSender::AddProcessStatsAgent(
33 std::unique_ptr<ProcessStatsAgent> agent) {
34 DCHECK(thread_checker_.CalledOnValidThread());
35 agents_.push_back(std::move(agent));
36 }
37
38 void ProcessStatsSender::ReportUsage() {
39 DCHECK(thread_checker_.CalledOnValidThread());
40 if (agents_.empty()) {
Sergey Ulanov 2017/04/26 05:42:44 Maybe replace this with a check that usages is not
Hzj_jie 2017/04/26 20:47:19 If so, I would also update the comment in header f
joedow 2017/04/26 23:48:01 That seems like a dangerous assumption. Maybe you
Hzj_jie 2017/04/27 02:21:33 Emmm, looks like once the if-check has been change
joedow 2017/04/27 15:01:55 I don't think you need to fire the timer if no one
Hzj_jie 2017/04/27 18:28:49 As far as I can imagine, it's definitely wrong if
41 return;
42 }
43
44 std::vector<protocol::ProcessResourceUsage> usages;
45 for (const auto& agent : agents_) {
46 protocol::ProcessResourceUsage usage = agent->GetResourceUsage();
47 if (!IsEmptyProcessResourceUsage(usage)) {
48 usages.push_back(std::move(usage));
49 }
50 }
51
52 host_stats_stub_->OnProcessStats(AggregateProcessResourceUsage(usages));
53 }
54
55 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698