Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 "base/bind.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/memory/singleton.h" | |
| 11 #include "base/threading/thread_task_runner_handle.h" | |
| 12 | |
| 13 namespace chromeos { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 constexpr char kArcTracingAgentName[] = "arc"; | |
| 18 constexpr char kArcTraceLabel[] = "ArcTraceEvents"; | |
| 19 | |
| 20 class ArcTraceAgentImpl : public ArcTraceAgent { | |
| 21 public: | |
| 22 ArcTraceAgentImpl() : delegate_(nullptr), weak_ptr_factory_(this) {} | |
| 23 | |
| 24 ~ArcTraceAgentImpl() override = default; | |
| 25 | |
| 26 // base::trace_event::TracingAgent overrides: | |
| 27 std::string GetTracingAgentName() override { return kArcTracingAgentName; } | |
| 28 | |
| 29 std::string GetTraceEventLabel() override { return kArcTraceLabel; } | |
| 30 | |
| 31 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
| |
| 32 const StartAgentTracingCallback& callback) override { | |
| 33 // delegate_ may be nullptr if ARC is not enabled on the system. In such | |
| 34 // case, simply do nothing. | |
| 35 if (!delegate_) { | |
| 36 // Use PostTask as the convention of TraceAgent. The caller expects | |
| 37 // callback to be called after this function returns. | |
| 38 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 39 FROM_HERE, base::Bind(callback, GetTracingAgentName(), false)); | |
| 40 return; | |
| 41 } | |
| 42 | |
| 43 delegate_->StartTracing(trace_config, | |
| 44 base::Bind(callback, GetTracingAgentName())); | |
| 45 } | |
| 46 | |
| 47 void StopAgentTracing(const StopAgentTracingCallback& callback) override { | |
| 48 if (!delegate_) { | |
| 49 std::string no_data; | |
| 50 callback.Run(GetTracingAgentName(), GetTraceEventLabel(), | |
| 51 base::RefCountedString::TakeString(&no_data)); | |
| 52 return; | |
| 53 } | |
| 54 | |
| 55 delegate_->StopTracing(base::Bind(&ArcTraceAgentImpl::OnStopAgentTracing, | |
| 56 weak_ptr_factory_.GetWeakPtr(), | |
| 57 callback)); | |
| 58 } | |
| 59 | |
| 60 // ArcTraceAgent overrides: | |
| 61 void SetDelegate(Delegate* delegate) override { delegate_ = delegate; } | |
| 62 | |
| 63 static ArcTraceAgentImpl* GetInstance() { | |
| 64 return base::Singleton<ArcTraceAgentImpl>::get(); | |
| 65 } | |
| 66 | |
| 67 private: | |
| 68 // 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.
| |
| 69 // by the Singleton class. | |
| 70 friend struct base::DefaultSingletonTraits<ArcTraceAgentImpl>; | |
| 71 | |
| 72 void OnStopAgentTracing(const StopAgentTracingCallback& callback, | |
| 73 const std::string& report) { | |
| 74 std::string data(report); | |
| 75 callback.Run(kArcTracingAgentName, kArcTraceLabel, | |
| 76 base::RefCountedString::TakeString(&data)); | |
| 77 } | |
| 78 | |
| 79 Delegate* delegate_; // Owned by ArcServiceLauncher. | |
| 80 base::WeakPtrFactory<ArcTraceAgentImpl> weak_ptr_factory_; | |
| 81 | |
| 82 DISALLOW_COPY_AND_ASSIGN(ArcTraceAgentImpl); | |
| 83 }; | |
| 84 | |
| 85 } // namespace | |
| 86 | |
| 87 // static | |
| 88 ArcTraceAgent* ArcTraceAgent::GetInstance() { | |
| 89 return ArcTraceAgentImpl::GetInstance(); | |
| 90 } | |
| 91 | |
| 92 } // namespace chromeos | |
| OLD | NEW |