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

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

Powered by Google App Engine
This is Rietveld 408576698