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

Side by Side Diff: chrome/browser/chromeos/arc/trace/arc_trace_bridge.cc

Issue 2699833003: arc: enable Android tracing from chrome://tracing in dev mode (Closed)
Patch Set: Fix according to the 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/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 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
36 auto* trace_instance = ARC_GET_INSTANCE_FOR_METHOD(
37 arc_bridge_service()->trace(), QueryAvailableCategories);
38 if (!trace_instance)
39 return;
40 trace_instance->QueryAvailableCategories(base::Bind(
41 &ArcTraceBridge::OnCategoriesReady, weak_ptr_factory_.GetWeakPtr()));
42 }
43
44 void ArcTraceBridge::OnCategoriesReady(
45 const std::vector<std::string>& categories) {
46 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
47
48 // There is no API in TraceLog to remove a category from the UI. As an
49 // alternative, the old category that is no longer in |categories_| will be
50 // ignored when calling |StartTracing|.
51 categories_.clear();
52 for (const auto& category : categories) {
53 categories_.push_back(Category{category, kCategoryPrefix + category});
54 // Show the category name in the selection UI.
55 base::trace_event::TraceLog::GetCategoryGroupEnabled(
56 categories_.back().full_name.c_str());
57 }
58 }
59
60 void ArcTraceBridge::StartTracing(
61 const base::trace_event::TraceConfig& trace_config,
62 const StartTracingCallback& callback) {
63 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
64
65 auto* trace_instance =
66 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->trace(), StartTracing);
67 if (!trace_instance) {
68 // Use PostTask as the convention of TraceAgent. The caller expects
69 // callback to be called after this function returns.
70 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
71 base::Bind(callback, false));
72 return;
73 }
74
75 std::vector<std::string> selected_categories;
76 for (const auto& category : categories_) {
77 if (trace_config.IsCategoryGroupEnabled(category.full_name.c_str()))
78 selected_categories.push_back(category.name);
79 }
80
81 trace_instance->StartTracing(selected_categories, callback);
82 }
83
84 void ArcTraceBridge::StopTracing(const StopTracingCallback& callback) {
85 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
86
87 auto* trace_instance =
88 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->trace(), StopTracing);
89 if (!trace_instance) {
90 callback.Run(false);
Daniel Erat 2017/03/07 15:53:21 same comment as in later file: this callback shoul
Earl Ou 2017/03/08 05:03:04 Done.
91 return;
92 }
93 trace_instance->StopTracing(callback);
94 }
95
96 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698