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

Side by Side Diff: chromeos/trace/arc_trace_agent.cc

Issue 2699833003: arc: enable Android tracing from chrome://tracing in dev mode (Closed)
Patch Set: Fix nits Created 3 years, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 "chromeos/trace/arc_trace_agent.h"
6
7 #include <string>
8
9 #include "base/bind.h"
10 #include "base/logging.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/singleton.h"
13 #include "base/threading/thread_checker.h"
14 #include "base/threading/thread_task_runner_handle.h"
15
16 namespace chromeos {
17
18 namespace {
19
20 constexpr char kArcTracingAgentName[] = "arc";
21 constexpr char kArcTraceLabel[] = "ArcTraceEvents";
22
23 void OnStopTracing(bool success) {
24 if (!success)
25 LOG(WARNING) << "Failed to stop ARC tracing.";
Luis Héctor Chávez 2017/02/27 20:47:18 nit: LOG_IF(WARNING, !success)
Earl Ou 2017/03/02 07:57:59 Done.
26 }
27
28 class ArcTraceAgentImpl : public ArcTraceAgent {
29 public:
30 // base::trace_event::TracingAgent overrides:
31 std::string GetTracingAgentName() override { return kArcTracingAgentName; }
32
33 std::string GetTraceEventLabel() override { return kArcTraceLabel; }
34
35 void StartAgentTracing(const base::trace_event::TraceConfig& trace_config,
36 const StartAgentTracingCallback& callback) override {
37 DCHECK(thread_checker_.CalledOnValidThread());
38 // delegate_ may be nullptr if ARC is not enabled on the system. In such
39 // case, simply do nothing.
40 if (!delegate_) {
41 // Use PostTask as the convention of TraceAgent. The caller expects
42 // callback to be called after this function returns.
43 base::ThreadTaskRunnerHandle::Get()->PostTask(
44 FROM_HERE, base::Bind(callback, GetTracingAgentName(), false));
45 return;
46 }
47
48 delegate_->StartTracing(trace_config,
49 base::Bind(callback, GetTracingAgentName()));
50 }
51
52 void StopAgentTracing(const StopAgentTracingCallback& callback) override {
53 DCHECK(thread_checker_.CalledOnValidThread());
54 if (delegate_)
55 delegate_->StopTracing(base::Bind(OnStopTracing));
56
57 // Trace data is collect via systrace (debugd) in dev-mode. Simply
58 // return empty data here.
59 std::string no_data;
60 callback.Run(GetTracingAgentName(), GetTraceEventLabel(),
61 base::RefCountedString::TakeString(&no_data));
62 }
63
64 // ArcTraceAgent overrides:
65 void SetDelegate(Delegate* delegate) override {
66 DCHECK(thread_checker_.CalledOnValidThread());
67 delegate_ = delegate;
68 }
69
70 static ArcTraceAgentImpl* GetInstance() {
71 return base::Singleton<ArcTraceAgentImpl>::get();
72 }
73
74 private:
75 // This allows constructor and destructor to be private and usable only
76 // by the Singleton class.
77 friend struct base::DefaultSingletonTraits<ArcTraceAgentImpl>;
78
79 ArcTraceAgentImpl() : weak_ptr_factory_(this) {}
80
81 ~ArcTraceAgentImpl() override = default;
82
83 Delegate* delegate_ = nullptr; // Owned by ArcServiceLauncher.
84 base::ThreadChecker thread_checker_;
85 base::WeakPtrFactory<ArcTraceAgentImpl> weak_ptr_factory_;
86
87 DISALLOW_COPY_AND_ASSIGN(ArcTraceAgentImpl);
88 };
89
90 } // namespace
91
92 // static
93 ArcTraceAgent* ArcTraceAgent::GetInstance() {
94 return ArcTraceAgentImpl::GetInstance();
95 }
96
97 ArcTraceAgent::~ArcTraceAgent() = default;
98
99 ArcTraceAgent::Delegate::~Delegate() = default;
100
101 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698