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

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 according to the comments 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 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 LOG_IF(WARNING, !success) << "Failed to stop ARC tracing.";
25 }
26
27 class ArcTraceAgentImpl : public ArcTraceAgent {
28 public:
29 // base::trace_event::TracingAgent overrides:
30 std::string GetTracingAgentName() override { return kArcTracingAgentName; }
31
32 std::string GetTraceEventLabel() override { return kArcTraceLabel; }
33
34 void StartAgentTracing(const base::trace_event::TraceConfig& trace_config,
35 const StartAgentTracingCallback& callback) override {
36 DCHECK(thread_checker_.CalledOnValidThread());
37 // delegate_ may be nullptr if ARC is not enabled on the system. In such
38 // case, simply do nothing.
39 if (!delegate_) {
40 // Use PostTask as the convention of TraceAgent. The caller expects
41 // callback to be called after this function returns.
42 base::ThreadTaskRunnerHandle::Get()->PostTask(
43 FROM_HERE, base::Bind(callback, GetTracingAgentName(), false));
44 return;
45 }
46
47 delegate_->StartTracing(trace_config,
48 base::Bind(callback, GetTracingAgentName()));
49 }
50
51 void StopAgentTracing(const StopAgentTracingCallback& callback) override {
52 DCHECK(thread_checker_.CalledOnValidThread());
53 if (delegate_)
54 delegate_->StopTracing(base::Bind(OnStopTracing));
55
56 // Trace data is collect via systrace (debugd) in dev-mode. Simply
57 // return empty data here.
58 std::string no_data;
59 callback.Run(GetTracingAgentName(), GetTraceEventLabel(),
60 base::RefCountedString::TakeString(&no_data));
61 }
62
63 // ArcTraceAgent overrides:
64 void SetDelegate(Delegate* delegate) override {
65 DCHECK(thread_checker_.CalledOnValidThread());
66 delegate_ = delegate;
67 }
68
69 static ArcTraceAgentImpl* GetInstance() {
70 return base::Singleton<ArcTraceAgentImpl>::get();
71 }
72
73 private:
74 // This allows constructor and destructor to be private and usable only
75 // by the Singleton class.
76 friend struct base::DefaultSingletonTraits<ArcTraceAgentImpl>;
77
78 ArcTraceAgentImpl() : weak_ptr_factory_(this) {}
Luis Héctor Chávez 2017/03/02 18:45:50 this can now be |= default;|. Also, you won't need
Earl Ou 2017/03/03 05:37:50 Done.
79
80 ~ArcTraceAgentImpl() override = default;
81
82 Delegate* delegate_ = nullptr; // Owned by ArcServiceLauncher.
83 base::ThreadChecker thread_checker_;
84 base::WeakPtrFactory<ArcTraceAgentImpl> weak_ptr_factory_;
Luis Héctor Chávez 2017/03/02 18:45:50 unused.
Earl Ou 2017/03/03 05:37:50 Done.
85
86 DISALLOW_COPY_AND_ASSIGN(ArcTraceAgentImpl);
87 };
88
89 } // namespace
90
91 // static
92 ArcTraceAgent* ArcTraceAgent::GetInstance() {
93 return ArcTraceAgentImpl::GetInstance();
94 }
95
96 ArcTraceAgent::~ArcTraceAgent() = default;
97
98 ArcTraceAgent::Delegate::~Delegate() = default;
99
100 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698