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

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 according to comments Created 3 years, 11 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 "chrome/browser/chromeos/arc/trace/arc_trace_bridge.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/logging.h"
11 #include "components/arc/arc_bridge_service.h"
12 #include "components/arc/arc_service_manager.h"
13 #include "content/public/browser/browser_thread.h"
14
15 namespace arc {
16
17 namespace {
18
19 // This class is owned by ArcServiceManager so that it is safe to use this raw
20 // pointer as the singleton reference.
21 ArcTraceBridge* g_arc_trace_bridge = nullptr;
Yusuke Sato 2017/01/04 23:55:47 same, please remove if possible.
Earl Ou 2017/01/16 14:05:39 Done.
22
23 // The prefix of the categories to be shown on the trace selection UI.
24 constexpr char kCategoryPrefix[] = TRACE_DISABLED_BY_DEFAULT("android ");
25
26 void OnTraceStart(bool success) {
27 if (!success)
28 LOG(ERROR) << "Failed to start tracing in the container.";
29 }
30
31 void OnTraceStop(bool success) {
32 if (!success)
33 LOG(ERROR) << "Failed to stop tracing in the container.";
34 }
35
36 } // namespace
37
38 ArcTraceBridge* ArcTraceBridge::Get() {
39 return g_arc_trace_bridge;
40 }
41
42 ArcTraceBridge::ArcTraceBridge(ArcBridgeService* bridge_service)
43 : ArcService(bridge_service), weak_ptr_factory_(this) {
44 arc_bridge_service()->trace()->AddObserver(this);
45 DCHECK(!g_arc_trace_bridge);
46 g_arc_trace_bridge = this;
47 }
48
49 ArcTraceBridge::~ArcTraceBridge() {
50 arc_bridge_service()->trace()->RemoveObserver(this);
51 g_arc_trace_bridge = nullptr;
52 }
53
54 void ArcTraceBridge::OnInstanceReady() {
55 QueryAvailableCategories();
56 }
57
58 void ArcTraceBridge::QueryAvailableCategories() {
59 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
60 auto* trace_instance = arc_bridge_service()->trace()->GetInstanceForMethod(
Yusuke Sato 2017/01/04 23:55:47 The API for getting an instance has been changed.
Earl Ou 2017/01/16 14:05:39 Done.
61 "QueryAvailableCategories");
62 if (!trace_instance)
63 return;
64 trace_instance->QueryAvailableCategories(base::Bind(
65 &ArcTraceBridge::OnCategoriesReady, weak_ptr_factory_.GetWeakPtr()));
66 }
67
68 void ArcTraceBridge::OnCategoriesReady(
69 const std::vector<std::string>& categories) {
70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
71
72 categories_.clear();
73 for (const auto& category : categories) {
74 categories_.push_back(
75 Category{category, std::string(kCategoryPrefix) + category});
76 // Show the category name in the selection UI.
77 base::trace_event::TraceLog::GetCategoryGroupEnabled(
78 categories_.back().full_name.c_str());
79 }
80 }
81
82 void ArcTraceBridge::StartTracing(
83 const base::trace_event::TraceConfig& trace_config) {
84 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
85
86 auto* trace_instance =
87 arc_bridge_service()->trace()->GetInstanceForMethod("StartTracing");
88 if (!trace_instance)
89 return;
90
91 std::vector<std::string> selected_categories;
92 for (const auto& category : categories_) {
93 if (trace_config.IsCategoryGroupEnabled(category.full_name.c_str()))
94 selected_categories.push_back(category.name);
95 }
96
97 trace_instance->StartTracing(selected_categories, base::Bind(&OnTraceStart));
98 }
99
100 void ArcTraceBridge::StopTracing() {
101 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
102 auto* trace_instance =
103 arc_bridge_service()->trace()->GetInstanceForMethod("StopTracing");
104 if (!trace_instance)
105 return;
106 trace_instance->StopTracing(base::Bind(&OnTraceStop));
107 }
108
109 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698