blob: 0fa97fe5dd58ea35c4952309ea7d6501df41e68f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// Copyright 2015 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.
#ifndef CONTENT_BROWSER_TRACING_POWER_TRACING_AGENT_H_
#define CONTENT_BROWSER_TRACING_POWER_TRACING_AGENT_H_
#include "base/macros.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/thread.h"
#include "base/trace_event/tracing_agent.h"
#include "content/public/browser/browser_thread.h"
#include "tools/battor_agent/battor_agent.h"
#include "tools/battor_agent/battor_error.h"
namespace base {
template <typename Type>
struct DefaultSingletonTraits;
} // namespace base
namespace content {
class PowerTracingAgent : public base::trace_event::TracingAgent,
public battor::BattOrAgent::Listener {
public:
// Retrieve the singleton instance.
static PowerTracingAgent* GetInstance();
void StartAgentTracing(const base::trace_event::TraceConfig& trace_config,
const StartAgentTracingCallback& callback) override;
void StopAgentTracing(const StopAgentTracingCallback& callback) override;
void RecordClockSyncMarker(
const std::string& sync_id,
const RecordClockSyncMarkerCallback& callback) override;
bool SupportsExplicitClockSync() override;
// base::trace_event::TracingAgent implementation.
std::string GetTracingAgentName() override;
std::string GetTraceEventLabel() override;
// BattOrAgent::Listener implementation.
void OnStartTracingComplete(battor::BattOrError error) override;
void OnStopTracingComplete(const std::string& trace,
battor::BattOrError error) override;
void OnRecordClockSyncMarkerComplete(battor::BattOrError error) override;
private:
// This allows constructor and destructor to be private and usable only
// by the Singleton class.
friend struct base::DefaultSingletonTraits<PowerTracingAgent>;
PowerTracingAgent();
~PowerTracingAgent() override;
void FindBattOrOnFileThread(const StartAgentTracingCallback& callback);
void StartAgentTracingOnIOThread(const std::string& path,
const StartAgentTracingCallback& callback);
void StopAgentTracingOnIOThread(const StopAgentTracingCallback& callback);
void RecordClockSyncMarkerOnIOThread(
const std::string& sync_id,
const RecordClockSyncMarkerCallback& callback);
// Returns the path of a BattOr (e.g. /dev/ttyUSB0), or an empty string if
// none are found.
std::string GetBattOrPath();
// All interactions with the BattOrAgent (after construction) must happen on
// the IO thread.
scoped_ptr<battor::BattOrAgent, BrowserThread::DeleteOnIOThread>
battor_agent_;
StartAgentTracingCallback start_tracing_callback_;
StopAgentTracingCallback stop_tracing_callback_;
std::string record_clock_sync_marker_sync_id_;
base::TimeTicks record_clock_sync_marker_start_time_;
RecordClockSyncMarkerCallback record_clock_sync_marker_callback_;
DISALLOW_COPY_AND_ASSIGN(PowerTracingAgent);
};
} // namespace content
#endif // CONTENT_BROWSER_TRACING_POWER_TRACING_AGENT_H_
|