OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/lazy_instance.h" | 5 #include "base/lazy_instance.h" |
6 #include "base/memory/singleton.h" | 6 #include "base/memory/singleton.h" |
| 7 #include "base/thread_task_runner_handle.h" |
7 #include "base/trace_event/trace_event_impl.h" | 8 #include "base/trace_event/trace_event_impl.h" |
8 #include "content/browser/tracing/battor_power_trace_provider.h" | 9 #include "content/browser/tracing/battor_power_trace_provider.h" |
9 #include "content/browser/tracing/power_tracing_agent.h" | 10 #include "content/browser/tracing/power_tracing_agent.h" |
10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 const char kPowerTracingAgentName[] = "battor"; | 17 const char kPowerTracingAgentName[] = "battor"; |
(...skipping 13 matching lines...) Expand all Loading... |
30 PowerTracingAgent::~PowerTracingAgent() {} | 31 PowerTracingAgent::~PowerTracingAgent() {} |
31 | 32 |
32 std::string PowerTracingAgent::GetTracingAgentName() { | 33 std::string PowerTracingAgent::GetTracingAgentName() { |
33 return kPowerTracingAgentName; | 34 return kPowerTracingAgentName; |
34 } | 35 } |
35 | 36 |
36 std::string PowerTracingAgent::GetTraceEventLabel() { | 37 std::string PowerTracingAgent::GetTraceEventLabel() { |
37 return kPowerTraceLabel; | 38 return kPowerTraceLabel; |
38 } | 39 } |
39 | 40 |
40 bool PowerTracingAgent::StartAgentTracing( | 41 void PowerTracingAgent::StartAgentTracing( |
41 const base::trace_event::TraceConfig& trace_config) { | 42 const base::trace_event::TraceConfig& trace_config, |
| 43 const StartAgentTracingCallback& callback) { |
42 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 44 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
43 | 45 |
44 // TODO(charliea): When system tracing is enabled in about://tracing, it will | 46 // TODO(charliea): When system tracing is enabled in about://tracing, it will |
45 // trigger power tracing. We need a way of checking if BattOr is connected. | 47 // trigger power tracing. We need a way of checking if BattOr is connected. |
46 // Currently, IsConnected() always returns false, so that we do not include | 48 // Currently, IsConnected() always returns false, so that we do not include |
47 // BattOr trace until it is hooked up. | 49 // BattOr trace until it is hooked up. |
48 if (!battor_trace_provider_->IsConnected()) | 50 if (!battor_trace_provider_->IsConnected()) { |
49 return false; | 51 base::ThreadTaskRunnerHandle::Get()->PostTask( |
50 | 52 FROM_HERE, |
| 53 base::Bind(callback, GetTracingAgentName(), false /* success */)); |
| 54 return; |
| 55 } |
51 thread_.Start(); | 56 thread_.Start(); |
52 | 57 |
53 thread_.task_runner()->PostTask( | 58 thread_.task_runner()->PostTask( |
54 FROM_HERE, | 59 FROM_HERE, |
55 base::Bind(&PowerTracingAgent::TraceOnThread, base::Unretained(this))); | 60 base::Bind(&PowerTracingAgent::TraceOnThread, base::Unretained(this))); |
56 return true; | 61 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 62 FROM_HERE, |
| 63 base::Bind(callback, GetTracingAgentName(), true /* success */)); |
57 } | 64 } |
58 | 65 |
59 void PowerTracingAgent::StopAgentTracing( | 66 void PowerTracingAgent::StopAgentTracing( |
60 const StopAgentTracingCallback& callback) { | 67 const StopAgentTracingCallback& callback) { |
61 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 68 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
62 DCHECK(thread_.IsRunning()); | 69 DCHECK(thread_.IsRunning()); |
63 | 70 |
64 thread_.task_runner()->PostTask( | 71 thread_.task_runner()->PostTask( |
65 FROM_HERE, | 72 FROM_HERE, |
66 base::Bind(&PowerTracingAgent::FlushOnThread, base::Unretained(this), | 73 base::Bind(&PowerTracingAgent::FlushOnThread, base::Unretained(this), |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 base::TimeTicks issue_ts = base::TimeTicks::Now(); | 137 base::TimeTicks issue_ts = base::TimeTicks::Now(); |
131 battor_trace_provider_->RecordClockSyncMarker(sync_id); | 138 battor_trace_provider_->RecordClockSyncMarker(sync_id); |
132 base::TimeTicks issue_end_ts = base::TimeTicks::Now(); | 139 base::TimeTicks issue_end_ts = base::TimeTicks::Now(); |
133 | 140 |
134 BrowserThread::PostTask( | 141 BrowserThread::PostTask( |
135 BrowserThread::UI, FROM_HERE, | 142 BrowserThread::UI, FROM_HERE, |
136 base::Bind(callback, sync_id, issue_ts, issue_end_ts)); | 143 base::Bind(callback, sync_id, issue_ts, issue_end_ts)); |
137 } | 144 } |
138 | 145 |
139 } // namespace content | 146 } // namespace content |
OLD | NEW |