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

Unified Diff: chromeos/trace/arc_trace_agent.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: chromeos/trace/arc_trace_agent.cc
diff --git a/chromeos/trace/arc_trace_agent.cc b/chromeos/trace/arc_trace_agent.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c8bd6ec3cc3d7c7dc5105aefe60d909dcb0df81b
--- /dev/null
+++ b/chromeos/trace/arc_trace_agent.cc
@@ -0,0 +1,92 @@
+// 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 "chromeos/trace/arc_trace_agent.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/singleton.h"
+#include "base/threading/thread_task_runner_handle.h"
+
+namespace chromeos {
+
+namespace {
+
+constexpr char kArcTracingAgentName[] = "arc";
+constexpr char kArcTraceLabel[] = "ArcTraceEvents";
+
+class ArcTraceAgentImpl : public ArcTraceAgent {
+ public:
+ ArcTraceAgentImpl() : delegate_(nullptr), weak_ptr_factory_(this) {}
+
+ ~ArcTraceAgentImpl() override = default;
+
+ // 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,
Luis Héctor Chávez 2017/01/17 19:20:32 Can you add DCHECK_CURRENTLY_ON(content::BrowserT
Earl Ou 2017/01/18 09:13:21 Add thread_checker here as we don't want to add de
+ const StartAgentTracingCallback& callback) override {
+ // 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 TraceAgent. 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 {
+ if (!delegate_) {
+ std::string no_data;
+ callback.Run(GetTracingAgentName(), GetTraceEventLabel(),
+ base::RefCountedString::TakeString(&no_data));
+ return;
+ }
+
+ delegate_->StopTracing(base::Bind(&ArcTraceAgentImpl::OnStopAgentTracing,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback));
+ }
+
+ // ArcTraceAgent overrides:
+ void SetDelegate(Delegate* delegate) override { delegate_ = delegate; }
+
+ static ArcTraceAgentImpl* GetInstance() {
+ return base::Singleton<ArcTraceAgentImpl>::get();
+ }
+
+ private:
+ // This allows constructor and destructor to be private and usable only
Yusuke Sato 2017/01/17 22:17:21 Then can you make them private: ?
Earl Ou 2017/01/18 09:13:21 Done.
+ // by the Singleton class.
+ friend struct base::DefaultSingletonTraits<ArcTraceAgentImpl>;
+
+ void OnStopAgentTracing(const StopAgentTracingCallback& callback,
+ const std::string& report) {
+ std::string data(report);
+ callback.Run(kArcTracingAgentName, kArcTraceLabel,
+ base::RefCountedString::TakeString(&data));
+ }
+
+ Delegate* delegate_; // Owned by ArcServiceLauncher.
+ base::WeakPtrFactory<ArcTraceAgentImpl> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(ArcTraceAgentImpl);
+};
+
+} // namespace
+
+// static
+ArcTraceAgent* ArcTraceAgent::GetInstance() {
+ return ArcTraceAgentImpl::GetInstance();
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698