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

Side by Side Diff: chrome/browser/metrics/perf/perf_output.cc

Issue 2081153002: No dbus::FileDescriptor in DebugDaemonClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. PipeReader::StartIO returns ScopedFD Created 4 years, 4 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
« no previous file with comments | « chrome/browser/metrics/perf/perf_output.h ('k') | chromeos/dbus/debug_daemon_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/metrics/perf/perf_output.h" 5 #include "chrome/browser/metrics/perf/perf_output.h"
6 6
7 #include <memory>
8
9 #include "base/bind.h" 7 #include "base/bind.h"
10 #include "base/location.h"
11 #include "base/task_runner_util.h"
12 #include "chromeos/dbus/dbus_thread_manager.h" 8 #include "chromeos/dbus/dbus_thread_manager.h"
13 #include "chromeos/dbus/debug_daemon_client.h" 9 #include "chromeos/dbus/debug_daemon_client.h"
14 10
15 namespace {
16
17 // Create a dbus::FileDescriptor from a base::File.
18 dbus::ScopedFileDescriptor CreateFileDescriptor(base::File pipe_write_end) {
19 dbus::ScopedFileDescriptor file_descriptor(new dbus::FileDescriptor);
20 file_descriptor->PutValue(pipe_write_end.TakePlatformFile());
21 file_descriptor->CheckValidity();
22 return file_descriptor;
23 }
24
25 } // namespace
26
27 PerfOutputCall::PerfOutputCall( 11 PerfOutputCall::PerfOutputCall(
28 scoped_refptr<base::TaskRunner> blocking_task_runner, 12 scoped_refptr<base::TaskRunner> blocking_task_runner,
29 base::TimeDelta duration, 13 base::TimeDelta duration,
30 const std::vector<std::string>& perf_args, 14 const std::vector<std::string>& perf_args,
31 const DoneCallback& callback) 15 const DoneCallback& callback)
32 : blocking_task_runner_(blocking_task_runner), 16 : blocking_task_runner_(blocking_task_runner),
33 duration_(duration), 17 duration_(duration),
34 perf_args_(perf_args), 18 perf_args_(perf_args),
35 done_callback_(callback), 19 done_callback_(callback),
36 weak_factory_(this) { 20 weak_factory_(this) {
37 DCHECK(thread_checker_.CalledOnValidThread()); 21 DCHECK(thread_checker_.CalledOnValidThread());
38 22
39 perf_data_pipe_reader_.reset(new chromeos::PipeReaderForString( 23 perf_data_pipe_reader_.reset(new chromeos::PipeReaderForString(
40 blocking_task_runner_, 24 blocking_task_runner_,
41 base::Bind(&PerfOutputCall::OnIOComplete, weak_factory_.GetWeakPtr()))); 25 base::Bind(&PerfOutputCall::OnIOComplete, weak_factory_.GetWeakPtr())));
42 26
43 base::File pipe_write_end = perf_data_pipe_reader_->StartIO(); 27 base::ScopedFD pipe_write_end = perf_data_pipe_reader_->StartIO();
Ilya Sherman 2016/08/23 19:40:38 FWIW, the only reason that I know what "FD" means
hashimoto 2016/08/24 15:59:10 It was unfortunate that ScopedFD was introduced wi
44 base::PostTaskAndReplyWithResult( 28
Ilya Sherman 2016/08/23 19:40:38 Optional nit: I'd omit this newline.
hashimoto 2016/08/24 15:59:10 Done.
45 blocking_task_runner_.get(), FROM_HERE, 29 chromeos::DebugDaemonClient* client =
46 base::Bind(&CreateFileDescriptor, base::Passed(&pipe_write_end)), 30 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
47 base::Bind(&PerfOutputCall::OnFileDescriptorCreated, 31
Ilya Sherman 2016/08/23 19:40:38 Ditto
hashimoto 2016/08/24 15:59:10 Done.
48 weak_factory_.GetWeakPtr())); 32 client->GetPerfOutput(duration_, perf_args_, pipe_write_end.get(),
33 base::Bind(&PerfOutputCall::OnGetPerfOutputError,
34 weak_factory_.GetWeakPtr()));
49 } 35 }
50 36
51 PerfOutputCall::~PerfOutputCall() {} 37 PerfOutputCall::~PerfOutputCall() {}
52 38
53 void PerfOutputCall::OnFileDescriptorCreated(
54 dbus::ScopedFileDescriptor file_descriptor) {
55 DCHECK(thread_checker_.CalledOnValidThread());
56 DCHECK(file_descriptor);
57
58 chromeos::DebugDaemonClient* client =
59 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
60
61 client->GetPerfOutput(duration_, perf_args_, std::move(file_descriptor),
62 base::Bind(&PerfOutputCall::OnGetPerfOutputError,
63 weak_factory_.GetWeakPtr()));
64 }
65
66 void PerfOutputCall::OnIOComplete() { 39 void PerfOutputCall::OnIOComplete() {
67 DCHECK(thread_checker_.CalledOnValidThread()); 40 DCHECK(thread_checker_.CalledOnValidThread());
68 41
69 std::string stdout_data; 42 std::string stdout_data;
70 perf_data_pipe_reader_->GetData(&stdout_data); 43 perf_data_pipe_reader_->GetData(&stdout_data);
71 44
72 done_callback_.Run(stdout_data); 45 done_callback_.Run(stdout_data);
73 // The callback may delete us, so it's hammertime: Can't touch |this|. 46 // The callback may delete us, so it's hammertime: Can't touch |this|.
74 } 47 }
75 48
76 void PerfOutputCall::OnGetPerfOutputError(const std::string& error_name, 49 void PerfOutputCall::OnGetPerfOutputError(const std::string& error_name,
77 const std::string& error_message) { 50 const std::string& error_message) {
78 DCHECK(thread_checker_.CalledOnValidThread()); 51 DCHECK(thread_checker_.CalledOnValidThread());
79 52
80 // Signal pipe reader to shut down. This will cause 53 // Signal pipe reader to shut down. This will cause
81 // OnIOComplete to be called, probably with an empty string. 54 // OnIOComplete to be called, probably with an empty string.
82 perf_data_pipe_reader_->OnDataReady(-1); 55 perf_data_pipe_reader_->OnDataReady(-1);
83 } 56 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/perf/perf_output.h ('k') | chromeos/dbus/debug_daemon_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698