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

Side by Side Diff: components/arc/trace/arc_trace_bridge.cc

Issue 2400163003: arc: enable Android tracing in verified-boot mode (Closed)
Patch Set: arc: enable Android framework tracing in chrome://tracing Created 4 years, 2 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 2016 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 "components/arc/trace/arc_trace_bridge.h"
6
7 #include <string>
8 #include <utility>
9
10 #include "base/logging.h"
11 #include "base/trace_event/trace_event.h"
12 #include "components/arc/arc_bridge_service.h"
13
14 namespace arc {
15
16 namespace {
17 // This class is owned by ArcServiceManager so that it is safe to use this raw
18 // pointer as the singleton reference.
19 ArcTraceBridge* g_arc_trace_bridge = nullptr;
20
21 // The prefix of the categories to be shown on the trace selection UI.
22 constexpr char kCategoryPrefix[] = TRACE_DISABLED_BY_DEFAULT("android ");
23
24 } // namcespace
25
26 ArcTraceBridge* ArcTraceBridge::Get() {
27 DCHECK(g_arc_trace_bridge);
28 return g_arc_trace_bridge;
29 }
30
31 ArcTraceBridge::ArcTraceBridge(ArcBridgeService* bridge_service)
32 : ArcService(bridge_service), binding_(this), weak_ptr_factory_(this) {
33 arc_bridge_service()->trace()->AddObserver(this);
34 g_arc_trace_bridge = this;
35 }
36
37 ArcTraceBridge::~ArcTraceBridge() {
38 arc_bridge_service()->trace()->RemoveObserver(this);
39 g_arc_trace_bridge = nullptr;
40 }
41
42 void ArcTraceBridge::OnInstanceReady() {
43 QueryAvailableCategories();
44 }
45
46 void ArcTraceBridge::QueryAvailableCategories() {
47 auto* trace_instance = arc_bridge_service()->trace()->GetInstanceForMethod(
48 "QueryAvailableCategories");
49 if (!trace_instance)
50 return;
51 trace_instance->QueryAvailableCategories(base::Bind(
52 &ArcTraceBridge::OnCategoriesReady, weak_ptr_factory_.GetWeakPtr()));
53 }
54
55 void ArcTraceBridge::OnCategoriesReady(mojo::Array<mojo::String> categories) {
56 DCHECK(thread_checker_.CalledOnValidThread());
57
58 for (const auto& category : categories) {
59 categories_.push_back(std::pair<std::string, std::string>(
60 category, std::string(kCategoryPrefix) + std::string(category)));
61 // Shows the category name in the selection UI.
62 base::trace_event::TraceLog::GetCategoryGroupEnabled(
63 categories_.back().second.c_str());
64 }
65 }
66
67 void ArcTraceBridge::StartTracing(
68 const base::trace_event::TraceConfig& trace_config) {
69 DCHECK(thread_checker_.CalledOnValidThread());
70
71 auto* trace_instance =
72 arc_bridge_service()->trace()->GetInstanceForMethod("StartTracing");
73 if (!trace_instance)
74 return;
75
76 mojo::Array<mojo::String> selected_categories;
77 for (const auto& category : categories_) {
78 if (trace_config.IsCategoryGroupEnabled(category.second.c_str())) {
79 selected_categories.push_back(category.first);
80 }
81 }
82
83 trace_instance->StartTracing(std::move(selected_categories),
84 base::Bind(&ArcTraceBridge::OnTraceStart,
85 weak_ptr_factory_.GetWeakPtr()));
86 }
87
88 void ArcTraceBridge::StopTracing() {
89 auto* trace_instance =
90 arc_bridge_service()->trace()->GetInstanceForMethod("StopTracing");
91 if (!trace_instance)
92 return;
93 trace_instance->StopTracing(
94 base::Bind(&ArcTraceBridge::OnTraceStop, weak_ptr_factory_.GetWeakPtr()));
95 }
96
97 void ArcTraceBridge::OnTraceStart(bool success) {
98 if (!success) {
Luis Héctor Chávez 2016/10/11 13:13:03 nit: elide braces if both the condition and the bl
shunhsingou 2016/10/12 04:24:26 Done.
99 LOG(ERROR) << "Failed to start tracing in the container.";
100 }
101 }
102
103 void ArcTraceBridge::OnTraceStop(bool success) {
104 if (!success) {
105 LOG(ERROR) << "Failed to stop tracing in the container.";
106 }
107 }
108
109 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698