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

Side by Side Diff: chrome/browser/chromeos/arc/tracing/arc_tracing_bridge.cc

Issue 2699833003: arc: enable Android tracing from chrome://tracing in dev mode (Closed)
Patch Set: Fix according to comments Created 3 years, 9 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/tracing/arc_tracing_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 // The space at the end of the string is intentional as the separator between
20 // the prefix and the real categories.
21 constexpr char kCategoryPrefix[] = TRACE_DISABLED_BY_DEFAULT("android ");
22
23 } // namespace
24
25 ArcTracingBridge::ArcTracingBridge(ArcBridgeService* bridge_service)
26 : ArcService(bridge_service), weak_ptr_factory_(this) {
27 arc_bridge_service()->tracing()->AddObserver(this);
28 chromeos::ArcTracingAgent::GetInstance()->SetDelegate(this);
29 }
30
31 ArcTracingBridge::~ArcTracingBridge() {
32 chromeos::ArcTracingAgent::GetInstance()->SetDelegate(nullptr);
33 arc_bridge_service()->tracing()->RemoveObserver(this);
34 }
35
36 void ArcTracingBridge::OnInstanceReady() {
37 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
38 mojom::TracingInstance* tracing_instance = ARC_GET_INSTANCE_FOR_METHOD(
39 arc_bridge_service()->tracing(), QueryAvailableCategories);
40 if (!tracing_instance)
41 return;
42 tracing_instance->QueryAvailableCategories(base::Bind(
43 &ArcTracingBridge::OnCategoriesReady, weak_ptr_factory_.GetWeakPtr()));
44 }
45
46 void ArcTracingBridge::OnCategoriesReady(
47 const std::vector<std::string>& categories) {
48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
49
50 // There is no API in TraceLog to remove a category from the UI. As an
51 // alternative, the old category that is no longer in |categories_| will be
52 // ignored when calling |StartTracing|.
53 categories_.clear();
54 for (const auto& category : categories) {
55 categories_.push_back(Category{category, kCategoryPrefix + category});
dcheng 2017/03/10 22:09:24 Nit: Omit Category (that way it's clear this isn't
Earl Ou 2017/03/13 02:00:13 Done.
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 ArcTracingBridge::StartTracing(
63 const base::trace_event::TraceConfig& trace_config,
64 const StartTracingCallback& callback) {
65 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
66
67 mojom::TracingInstance* tracing_instance = ARC_GET_INSTANCE_FOR_METHOD(
68 arc_bridge_service()->tracing(), StartTracing);
69 if (!tracing_instance) {
70 // Use PostTask as the convention of TracingAgent. 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 tracing_instance->StartTracing(selected_categories, callback);
84 }
85
86 void ArcTracingBridge::StopTracing(const StopTracingCallback& callback) {
87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
88
89 mojom::TracingInstance* tracing_instance =
90 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->tracing(), StopTracing);
91 if (!tracing_instance) {
92 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
93 base::Bind(callback, false));
94 return;
95 }
96 tracing_instance->StopTracing(callback);
97 }
98
99 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698