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

Unified Diff: content/browser/tracing/arc_tracing_agent.cc

Issue 2749283003: arc: enable Android tracing from chrome://tracing in dev mode (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/tracing/arc_tracing_agent.h ('k') | content/browser/tracing/tracing_controller_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/tracing/arc_tracing_agent.cc
diff --git a/content/browser/tracing/arc_tracing_agent.cc b/content/browser/tracing/arc_tracing_agent.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d71cd647ae870308c2d5c68e3f600c2345115814
--- /dev/null
+++ b/content/browser/tracing/arc_tracing_agent.cc
@@ -0,0 +1,100 @@
+// 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 "content/browser/tracing/arc_tracing_agent.h"
+
+#include <string>
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/memory/singleton.h"
+#include "base/threading/thread_checker.h"
+#include "base/threading/thread_task_runner_handle.h"
+
+namespace content {
+
+namespace {
+
+constexpr char kArcTracingAgentName[] = "arc";
+constexpr char kArcTraceLabel[] = "ArcTraceEvents";
+
+void OnStopTracing(bool success) {
+ DLOG_IF(WARNING, !success) << "Failed to stop ARC tracing.";
+}
+
+class ArcTracingAgentImpl : public ArcTracingAgent {
+ public:
+ // base::trace_event::TracingAgent overrides:
+ std::string GetTracingAgentName() override { return kArcTracingAgentName; }
+
+ std::string GetTraceEventLabel() override { return kArcTraceLabel; }
+
+ void StartAgentTracing(const base::trace_event::TraceConfig& trace_config,
+ const StartAgentTracingCallback& callback) override {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ // delegate_ may be nullptr if ARC is not enabled on the system. In such
+ // case, simply do nothing.
+ if (!delegate_) {
+ // Use PostTask as the convention of TracingAgent. The caller expects
+ // callback to be called after this function returns.
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(callback, GetTracingAgentName(), false));
+ return;
+ }
+
+ delegate_->StartTracing(trace_config,
+ base::Bind(callback, GetTracingAgentName()));
+ }
+
+ void StopAgentTracing(const StopAgentTracingCallback& callback) override {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (delegate_)
+ delegate_->StopTracing(base::Bind(OnStopTracing));
+
+ // Trace data is collect via systrace (debugd) in dev-mode. Simply
+ // return empty data here.
+ std::string no_data;
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(callback, GetTracingAgentName(), GetTraceEventLabel(),
+ base::RefCountedString::TakeString(&no_data)));
+ }
+
+ // ArcTracingAgent overrides:
+ void SetDelegate(Delegate* delegate) override {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ delegate_ = delegate;
+ }
+
+ static ArcTracingAgentImpl* GetInstance() {
+ return base::Singleton<ArcTracingAgentImpl>::get();
+ }
+
+ private:
+ // This allows constructor and destructor to be private and usable only
+ // by the Singleton class.
+ friend struct base::DefaultSingletonTraits<ArcTracingAgentImpl>;
+
+ ArcTracingAgentImpl() = default;
+ ~ArcTracingAgentImpl() override = default;
+
+ Delegate* delegate_ = nullptr; // Owned by ArcServiceLauncher.
+ base::ThreadChecker thread_checker_;
+
+ DISALLOW_COPY_AND_ASSIGN(ArcTracingAgentImpl);
+};
+
+} // namespace
+
+// static
+ArcTracingAgent* ArcTracingAgent::GetInstance() {
+ return ArcTracingAgentImpl::GetInstance();
+}
+
+ArcTracingAgent::ArcTracingAgent() = default;
+ArcTracingAgent::~ArcTracingAgent() = default;
+
+ArcTracingAgent::Delegate::~Delegate() = default;
+
+} // namespace content
« no previous file with comments | « content/browser/tracing/arc_tracing_agent.h ('k') | content/browser/tracing/tracing_controller_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698