OLD | NEW |
---|---|
(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 <utility> | |
8 | |
9 #include "base/logging.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 // This class is owned by ArcServiceManager so that it is safe to use this raw | |
19 // pointer as the singleton reference. | |
20 ArcTraceBridge* g_arc_trace_bridge = nullptr; | |
21 | |
22 // The prefix of the categories to be shown on the trace selection UI. | |
23 constexpr char kCategoryPrefix[] = TRACE_DISABLED_BY_DEFAULT("android "); | |
24 | |
25 } // namespace | |
26 | |
27 ArcTraceBridge* ArcTraceBridge::Get() { | |
28 return g_arc_trace_bridge; | |
29 } | |
30 | |
31 ArcTraceBridge::ArcTraceBridge(ArcBridgeService* bridge_service) | |
32 : ArcService(bridge_service), weak_ptr_factory_(this) { | |
33 arc_bridge_service()->trace()->AddObserver(this); | |
34 DCHECK(!g_arc_trace_bridge); | |
35 g_arc_trace_bridge = this; | |
36 } | |
37 | |
38 ArcTraceBridge::~ArcTraceBridge() { | |
39 arc_bridge_service()->trace()->RemoveObserver(this); | |
40 g_arc_trace_bridge = nullptr; | |
41 } | |
42 | |
43 void ArcTraceBridge::OnInstanceReady() { | |
44 QueryAvailableCategories(); | |
45 } | |
46 | |
47 void ArcTraceBridge::QueryAvailableCategories() { | |
48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
49 auto* trace_instance = arc_bridge_service()->trace()->GetInstanceForMethod( | |
50 "QueryAvailableCategories"); | |
51 if (!trace_instance) | |
52 return; | |
53 trace_instance->QueryAvailableCategories(base::Bind( | |
54 &ArcTraceBridge::OnCategoriesReady, weak_ptr_factory_.GetWeakPtr())); | |
55 } | |
56 | |
57 void ArcTraceBridge::OnCategoriesReady( | |
58 const std::vector<std::string>& categories) { | |
59 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
60 | |
61 categories_.clear(); | |
62 for (const auto& category : categories) { | |
63 categories_.push_back( | |
64 Category{category, std::string(kCategoryPrefix) + category}); | |
65 // Show the category name in the selection UI. | |
66 base::trace_event::TraceLog::GetCategoryGroupEnabled( | |
67 categories_.back().full_name.c_str()); | |
68 } | |
69 } | |
70 | |
71 void ArcTraceBridge::StartTracing( | |
72 const base::trace_event::TraceConfig& trace_config) { | |
73 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
74 | |
75 auto* trace_instance = | |
76 arc_bridge_service()->trace()->GetInstanceForMethod("StartTracing"); | |
77 if (!trace_instance) | |
78 return; | |
79 | |
80 std::vector<std::string> selected_categories; | |
81 for (const auto& category : categories_) { | |
82 if (trace_config.IsCategoryGroupEnabled(category.full_name.c_str())) | |
83 selected_categories.push_back(category.name); | |
84 } | |
85 | |
86 trace_instance->StartTracing(selected_categories, | |
87 base::Bind(&ArcTraceBridge::OnTraceStart, | |
88 weak_ptr_factory_.GetWeakPtr())); | |
89 } | |
90 | |
91 void ArcTraceBridge::StopTracing() { | |
92 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
93 auto* trace_instance = | |
94 arc_bridge_service()->trace()->GetInstanceForMethod("StopTracing"); | |
95 if (!trace_instance) | |
96 return; | |
97 trace_instance->StopTracing( | |
98 base::Bind(&ArcTraceBridge::OnTraceStop, weak_ptr_factory_.GetWeakPtr())); | |
99 } | |
100 | |
101 void ArcTraceBridge::OnTraceStart(bool success) { | |
Luis Héctor Chávez
2016/12/28 17:21:58
These two methods don't access members and can be
shunhsingou
2016/12/29 09:40:29
Done.
| |
102 if (!success) | |
103 LOG(ERROR) << "Failed to start tracing in the container."; | |
104 } | |
105 | |
106 void ArcTraceBridge::OnTraceStop(bool success) { | |
107 if (!success) | |
108 LOG(ERROR) << "Failed to stop tracing in the container."; | |
109 } | |
110 | |
111 } // namespace arc | |
OLD | NEW |