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

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 nit 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 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 "base/bind.h"
8 #include "base/logging.h"
9 #include "base/threading/thread_task_runner_handle.h"
10 #include "components/arc/arc_bridge_service.h"
11 #include "components/arc/arc_service_manager.h"
12 #include "content/public/browser/browser_thread.h"
13
14 namespace arc {
15
16 namespace {
17
18 // The prefix of the categories to be shown on the trace selection UI.
19 constexpr char kCategoryPrefix[] = TRACE_DISABLED_BY_DEFAULT("android ");
20
21 } // namespace
22
23 ArcTraceBridge::ArcTraceBridge(ArcBridgeService* bridge_service)
24 : ArcService(bridge_service), weak_ptr_factory_(this) {
25 arc_bridge_service()->trace()->AddObserver(this);
26 chromeos::ArcTraceAgent::GetInstance()->SetDelegate(this);
27 }
28
29 ArcTraceBridge::~ArcTraceBridge() {
30 chromeos::ArcTraceAgent::GetInstance()->SetDelegate(nullptr);
31 arc_bridge_service()->trace()->RemoveObserver(this);
32 }
33
34 void ArcTraceBridge::OnInstanceReady() {
35 QueryAvailableCategories();
36 }
37
38 void ArcTraceBridge::QueryAvailableCategories() {
39 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
40 auto* trace_instance = ARC_GET_INSTANCE_FOR_METHOD(
41 arc_bridge_service()->trace(), QueryAvailableCategories);
42 if (!trace_instance)
43 return;
44 trace_instance->QueryAvailableCategories(base::Bind(
45 &ArcTraceBridge::OnCategoriesReady, weak_ptr_factory_.GetWeakPtr()));
46 }
47
48 void ArcTraceBridge::OnCategoriesReady(
49 const std::vector<std::string>& categories) {
50 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
51
52 categories_.clear();
53 for (const auto& category : categories) {
54 categories_.push_back(
55 Category{category, std::string(kCategoryPrefix) + category});
56 // Show the category name in the selection UI.
57 base::trace_event::TraceLog::GetCategoryGroupEnabled(
58 categories_.back().full_name.c_str());
59 }
60 }
61
62 void ArcTraceBridge::StartTracing(
63 const base::trace_event::TraceConfig& trace_config,
64 const StartTracingCallback& callback) {
65 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
66
67 auto* trace_instance =
68 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->trace(), StartTracing);
69 if (!trace_instance) {
70 // Use PostTask as the convention of TraceAgent. The caller expects
71 // callback to be called after this function returns.
72 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
73 base::Bind(callback, false));
74 return;
75 }
76
77 std::vector<std::string> selected_categories;
78 for (const auto& category : categories_) {
79 if (trace_config.IsCategoryGroupEnabled(category.full_name.c_str()))
80 selected_categories.push_back(category.name);
81 }
82
83 trace_instance->StartTracing(selected_categories, callback);
84 }
85
86 void ArcTraceBridge::StopTracing(const StopTracingCallback& callback) {
87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
88 auto* trace_instance =
89 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->trace(), StopTracing);
90 if (!trace_instance) {
91 callback.Run("");
Yusuke Sato 2017/01/19 23:06:18 So PostTask is not needed here right? Can you docu
Earl Ou 2017/01/25 03:50:59 Done.
92 return;
93 }
94
95 trace_instance->StopTracing(callback);
96 }
97
98 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698