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

Unified Diff: chrome/browser/chromeos/arc/trace/arc_trace_bridge.cc

Issue 2400163003: arc: enable Android tracing in verified-boot mode (Closed)
Patch Set: Fix some nits 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/arc/trace/arc_trace_bridge.cc
diff --git a/chrome/browser/chromeos/arc/trace/arc_trace_bridge.cc b/chrome/browser/chromeos/arc/trace/arc_trace_bridge.cc
new file mode 100644
index 0000000000000000000000000000000000000000..38a8d33fe40a20320f1d47780a6172d0000c15eb
--- /dev/null
+++ b/chrome/browser/chromeos/arc/trace/arc_trace_bridge.cc
@@ -0,0 +1,91 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/arc/trace/arc_trace_bridge.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "components/arc/arc_bridge_service.h"
+#include "components/arc/arc_service_manager.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace arc {
+
+namespace {
+
+// The prefix of the categories to be shown on the trace selection UI.
+constexpr char kCategoryPrefix[] = TRACE_DISABLED_BY_DEFAULT("android ");
+
+} // namespace
+
+ArcTraceBridge::ArcTraceBridge(ArcBridgeService* bridge_service)
+ : ArcService(bridge_service), weak_ptr_factory_(this) {
+ arc_bridge_service()->trace()->AddObserver(this);
+ chromeos::ArcTraceAgent::GetInstance()->SetDelegate(this);
+}
+
+ArcTraceBridge::~ArcTraceBridge() {
+ arc_bridge_service()->trace()->RemoveObserver(this);
Yusuke Sato 2017/01/17 22:17:20 swap L29 and L30 to do the removal in the reversed
Earl Ou 2017/01/18 09:13:21 Done.
+ chromeos::ArcTraceAgent::GetInstance()->SetDelegate(nullptr);
+}
+
+void ArcTraceBridge::OnInstanceReady() {
+ QueryAvailableCategories();
+}
+
+void ArcTraceBridge::QueryAvailableCategories() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ auto* trace_instance = ARC_GET_INSTANCE_FOR_METHOD(
+ arc_bridge_service()->trace(), QueryAvailableCategories);
+ if (!trace_instance)
+ return;
+ trace_instance->QueryAvailableCategories(base::Bind(
+ &ArcTraceBridge::OnCategoriesReady, weak_ptr_factory_.GetWeakPtr()));
+}
+
+void ArcTraceBridge::OnCategoriesReady(
+ const std::vector<std::string>& categories) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+
+ categories_.clear();
+ for (const auto& category : categories) {
+ categories_.push_back(
+ Category{category, std::string(kCategoryPrefix) + category});
+ // Show the category name in the selection UI.
+ base::trace_event::TraceLog::GetCategoryGroupEnabled(
+ categories_.back().full_name.c_str());
+ }
+}
+
+void ArcTraceBridge::StartTracing(
+ const base::trace_event::TraceConfig& trace_config,
+ const base::Callback<void(bool)>& callback) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+
+ auto* trace_instance =
+ ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->trace(), StartTracing);
+ if (!trace_instance)
+ return;
Yusuke Sato 2017/01/17 22:17:20 Shouldn't we run the |callback| with false in this
Earl Ou 2017/01/18 09:13:21 Done.
+
+ std::vector<std::string> selected_categories;
+ for (const auto& category : categories_) {
+ if (trace_config.IsCategoryGroupEnabled(category.full_name.c_str()))
+ selected_categories.push_back(category.name);
+ }
+
+ trace_instance->StartTracing(selected_categories, callback);
+}
+
+void ArcTraceBridge::StopTracing(
+ const base::Callback<void(const std::string&)>& callback) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ auto* trace_instance =
+ ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->trace(), StopTracing);
+ if (!trace_instance)
+ return;
Yusuke Sato 2017/01/17 22:17:20 same
Earl Ou 2017/01/18 09:13:20 Done.
+
+ trace_instance->StopTracing(callback);
+}
+
+} // namespace arc

Powered by Google App Engine
This is Rietveld 408576698