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

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 nit 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..1a0ba37a78b645dcf32da1b126998cf50b4d420d
--- /dev/null
+++ b/chrome/browser/chromeos/arc/trace/arc_trace_bridge.cc
@@ -0,0 +1,98 @@
+// Copyright 2017 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 "base/threading/thread_task_runner_handle.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() {
+ chromeos::ArcTraceAgent::GetInstance()->SetDelegate(nullptr);
+ arc_bridge_service()->trace()->RemoveObserver(this);
+}
+
+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 StartTracingCallback& callback) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+
+ auto* trace_instance =
+ ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->trace(), StartTracing);
+ if (!trace_instance) {
+ // Use PostTask as the convention of TraceAgent. The caller expects
+ // callback to be called after this function returns.
+ base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
+ base::Bind(callback, false));
+ return;
+ }
+
+ 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 StopTracingCallback& callback) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ auto* trace_instance =
+ ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->trace(), StopTracing);
+ if (!trace_instance) {
+ callback.Run("");
Yusuke Sato 2017/01/19 23:06:18 So PostTask is not needed here right? Can you docu
Earl Ou 2017/01/25 03:50:59 Done.
+ return;
+ }
+
+ trace_instance->StopTracing(callback);
+}
+
+} // namespace arc

Powered by Google App Engine
This is Rietveld 408576698