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

Side by Side Diff: chrome/browser/chromeos/arc/trace/arc_trace_bridge.cc

Issue 2400163003: arc: enable Android tracing in verified-boot mode (Closed)
Patch Set: Fix some nits Created 3 years, 10 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 "chrome/browser/chromeos/arc/trace/arc_trace_bridge.h"
6
7 #include <sys/socket.h>
8 #include <sys/types.h>
9
10 #include <utility>
11
12 #include "base/bind.h"
13 #include "base/logging.h"
14 #include "base/threading/thread_task_runner_handle.h"
15 #include "components/arc/arc_bridge_service.h"
16 #include "components/arc/arc_service_manager.h"
17 #include "content/public/browser/browser_thread.h"
18
19 #include "mojo/edk/embedder/embedder.h"
20 #include "mojo/edk/embedder/scoped_platform_handle.h"
21 #include "mojo/public/cpp/system/platform_handle.h"
22
23 namespace arc {
24
25 namespace {
26
27 // The prefix of the categories to be shown on the trace selection UI.
28 constexpr char kCategoryPrefix[] = TRACE_DISABLED_BY_DEFAULT("android ");
29
30 } // namespace
31
32 ArcTraceBridge::ArcTraceBridge(ArcBridgeService* bridge_service)
33 : ArcService(bridge_service), weak_ptr_factory_(this) {
34 arc_bridge_service()->trace()->AddObserver(this);
35 chromeos::ArcTraceAgent::GetInstance()->SetDelegate(this);
36 }
37
38 ArcTraceBridge::~ArcTraceBridge() {
39 chromeos::ArcTraceAgent::GetInstance()->SetDelegate(nullptr);
40 arc_bridge_service()->trace()->RemoveObserver(this);
41 }
42
43 void ArcTraceBridge::OnInstanceReady() {
Luis Héctor Chávez 2017/02/10 17:43:54 nit: DCHECK_CURRENTLY_ON(content::BrowserThread::U
Earl Ou 2017/03/22 11:38:25 Done.
44 int fds[2];
45 int ret = socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds);
46 DCHECK_EQ(0, ret);
Luis Héctor Chávez 2017/02/10 17:43:54 this will be messy on non-debug builds since you'l
Earl Ou 2017/03/22 11:38:26 Done in arc_tracing_agent.cc now.
47
48 auto* trace_instance =
49 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->trace(), SetHostSocket);
50 if (!trace_instance)
51 return;
52
53 mojo::ScopedHandle handle = mojo::WrapPlatformFile(fds[1]);
54 trace_instance->SetHostSocket(std::move(handle));
Luis Héctor Chávez 2017/02/10 17:43:54 nit: trace_instance->SetHostSocket(mojo::WrapPlatf
Earl Ou 2017/03/22 11:38:26 Done.
55 reader_.SetInputFD(base::ScopedFD(fds[0]));
56
57 QueryAvailableCategories();
58 }
59
60 void ArcTraceBridge::QueryAvailableCategories() {
61 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
62 auto* trace_instance = ARC_GET_INSTANCE_FOR_METHOD(
63 arc_bridge_service()->trace(), QueryAvailableCategories);
64 if (!trace_instance)
65 return;
66 trace_instance->QueryAvailableCategories(base::Bind(
67 &ArcTraceBridge::OnCategoriesReady, weak_ptr_factory_.GetWeakPtr()));
68 }
69
70 void ArcTraceBridge::OnCategoriesReady(
71 const std::vector<std::string>& categories) {
72 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
73
74 categories_.clear();
75 for (const auto& category : categories) {
76 categories_.push_back(
Luis Héctor Chávez 2017/02/10 17:43:54 nit: you can use emplace_back() here.
Earl Ou 2017/03/22 11:38:25 Done.
77 Category{category, std::string(kCategoryPrefix) + category});
78 // Show the category name in the selection UI.
79 base::trace_event::TraceLog::GetCategoryGroupEnabled(
80 categories_.back().full_name.c_str());
81 }
82 }
83
84 void ArcTraceBridge::StartTracing(
85 const base::trace_event::TraceConfig& trace_config,
86 const StartTracingCallback& callback) {
87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
88
89 auto* trace_instance =
90 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->trace(), StartTracing);
91 if (!trace_instance) {
92 // Use PostTask as the convention of TraceAgent. The caller expects
93 // callback to be called after this function returns.
94 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
95 base::Bind(callback, false));
96 return;
97 }
98
99 std::vector<std::string> selected_categories;
100 for (const auto& category : categories_) {
101 if (trace_config.IsCategoryGroupEnabled(category.full_name.c_str()))
102 selected_categories.push_back(category.name);
103 }
104
105 reader_.StartRecord();
106 trace_instance->StartTracing(selected_categories, callback);
107 }
108
109 void ArcTraceBridge::StopTracing(const StopTracingCallback& callback) {
110 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
111
112 auto* trace_instance =
113 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->trace(), StopTracing);
114 if (!trace_instance) {
115 reader_.StopRecord(callback);
116 return;
117 }
118 trace_instance->StopTracing(base::Bind(&ArcTraceBridge::OnStopTracing,
119 weak_ptr_factory_.GetWeakPtr(),
120 callback));
121 }
122
123 void ArcTraceBridge::OnStopTracing(const StopTracingCallback& callback,
124 bool success) {
125 if (!success) {
126 LOG(WARNING) << "Failed to stop tracing in ARC.";
Luis Héctor Chávez 2017/02/10 17:43:54 nit: LOG_IF(WARNING, !success) << "...";
Earl Ou 2017/03/22 11:38:25 Done.
127 }
128 reader_.StopRecord(callback);
129 }
130
131 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698