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

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, 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 "base/bind.h"
8 #include "base/logging.h"
9 #include "components/arc/arc_bridge_service.h"
10 #include "components/arc/arc_service_manager.h"
11 #include "content/public/browser/browser_thread.h"
12
13 namespace arc {
14
15 namespace {
16
17 // The prefix of the categories to be shown on the trace selection UI.
18 constexpr char kCategoryPrefix[] = TRACE_DISABLED_BY_DEFAULT("android ");
19
20 } // namespace
21
22 ArcTraceBridge::ArcTraceBridge(ArcBridgeService* bridge_service)
23 : ArcService(bridge_service), weak_ptr_factory_(this) {
24 arc_bridge_service()->trace()->AddObserver(this);
25 chromeos::ArcTraceAgent::GetInstance()->SetDelegate(this);
26 }
27
28 ArcTraceBridge::~ArcTraceBridge() {
29 arc_bridge_service()->trace()->RemoveObserver(this);
Yusuke Sato 2017/01/17 22:17:20 swap L29 and L30 to do the removal in the reversed
Earl Ou 2017/01/18 09:13:21 Done.
30 chromeos::ArcTraceAgent::GetInstance()->SetDelegate(nullptr);
31 }
32
33 void ArcTraceBridge::OnInstanceReady() {
34 QueryAvailableCategories();
35 }
36
37 void ArcTraceBridge::QueryAvailableCategories() {
38 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
39 auto* trace_instance = ARC_GET_INSTANCE_FOR_METHOD(
40 arc_bridge_service()->trace(), QueryAvailableCategories);
41 if (!trace_instance)
42 return;
43 trace_instance->QueryAvailableCategories(base::Bind(
44 &ArcTraceBridge::OnCategoriesReady, weak_ptr_factory_.GetWeakPtr()));
45 }
46
47 void ArcTraceBridge::OnCategoriesReady(
48 const std::vector<std::string>& categories) {
49 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
50
51 categories_.clear();
52 for (const auto& category : categories) {
53 categories_.push_back(
54 Category{category, std::string(kCategoryPrefix) + category});
55 // Show the category name in the selection UI.
56 base::trace_event::TraceLog::GetCategoryGroupEnabled(
57 categories_.back().full_name.c_str());
58 }
59 }
60
61 void ArcTraceBridge::StartTracing(
62 const base::trace_event::TraceConfig& trace_config,
63 const base::Callback<void(bool)>& callback) {
64 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
65
66 auto* trace_instance =
67 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->trace(), StartTracing);
68 if (!trace_instance)
69 return;
Yusuke Sato 2017/01/17 22:17:20 Shouldn't we run the |callback| with false in this
Earl Ou 2017/01/18 09:13:21 Done.
70
71 std::vector<std::string> selected_categories;
72 for (const auto& category : categories_) {
73 if (trace_config.IsCategoryGroupEnabled(category.full_name.c_str()))
74 selected_categories.push_back(category.name);
75 }
76
77 trace_instance->StartTracing(selected_categories, callback);
78 }
79
80 void ArcTraceBridge::StopTracing(
81 const base::Callback<void(const std::string&)>& callback) {
82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
83 auto* trace_instance =
84 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->trace(), StopTracing);
85 if (!trace_instance)
86 return;
Yusuke Sato 2017/01/17 22:17:20 same
Earl Ou 2017/01/18 09:13:20 Done.
87
88 trace_instance->StopTracing(callback);
89 }
90
91 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698