blob: bf09b518252cd9e7ce7a6d2fba45d5bf20e6ab25 [file] [log] [blame]
rtenneti72546962014-12-15 21:41:591// Copyright 2014 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
mefc2bd1aa2015-04-09 03:26:535#ifndef COMPONENTS_CRONET_HISTOGRAM_MANAGER_H_
6#define COMPONENTS_CRONET_HISTOGRAM_MANAGER_H_
rtenneti72546962014-12-15 21:41:597
avibc5337b2015-12-25 23:16:338#include <stdint.h>
9
dchengfe3745e6242016-04-21 23:49:5810#include <memory>
rtenneti72546962014-12-15 21:41:5911#include <string>
12#include <vector>
13
rtenneti72546962014-12-15 21:41:5914#include "base/lazy_instance.h"
15#include "base/macros.h"
rtenneti72546962014-12-15 21:41:5916#include "base/metrics/histogram_flattener.h"
17#include "base/metrics/histogram_snapshot_manager.h"
pauljensen487de2d2016-04-13 17:05:3718#include "base/synchronization/lock.h"
rtenneti72546962014-12-15 21:41:5919#include "components/metrics/proto/chrome_user_metrics_extension.pb.h"
20
mefc2bd1aa2015-04-09 03:26:5321namespace cronet {
rtenneti72546962014-12-15 21:41:5922
mefc2bd1aa2015-04-09 03:26:5323// A HistogramManager instance is created by the app. It is the central
24// controller for the acquisition of log data, and recording deltas for
pauljensen487de2d2016-04-13 17:05:3725// transmission to an external server. Public APIs are all thread-safe.
rtenneti72546962014-12-15 21:41:5926class HistogramManager : public base::HistogramFlattener {
27 public:
28 HistogramManager();
dcheng6a89b902014-12-30 21:40:5829 ~HistogramManager() override;
rtenneti72546962014-12-15 21:41:5930
31 // Snapshot all histograms to record the delta into |uma_proto_| and then
32 // returns the serialized protobuf representation of the record in |data|.
33 // Returns true if it was successfully serialized.
avibc5337b2015-12-25 23:16:3334 bool GetDeltas(std::vector<uint8_t>* data);
rtenneti72546962014-12-15 21:41:5935
36 // TODO(mef): Hang Histogram Manager off java object instead of singleton.
37 static HistogramManager* GetInstance();
38
39 private:
40 friend struct base::DefaultLazyInstanceTraits<HistogramManager>;
41
42 // base::HistogramFlattener:
43 void RecordDelta(const base::HistogramBase& histogram,
44 const base::HistogramSamples& snapshot) override;
45 void InconsistencyDetected(
46 base::HistogramBase::Inconsistency problem) override;
47 void UniqueInconsistencyDetected(
48 base::HistogramBase::Inconsistency problem) override;
49 void InconsistencyDetectedInLoggedCount(int amount) override;
50
51 base::HistogramSnapshotManager histogram_snapshot_manager_;
52
53 // Stores the protocol buffer representation for this log.
54 metrics::ChromeUserMetricsExtension uma_proto_;
55
pauljensen487de2d2016-04-13 17:05:3756 // Should be acquired whenever GetDeltas() is executing to maintain
57 // thread-safety.
58 base::Lock get_deltas_lock_;
59
rtenneti72546962014-12-15 21:41:5960 DISALLOW_COPY_AND_ASSIGN(HistogramManager);
61};
62
mefc2bd1aa2015-04-09 03:26:5363} // namespace cronet
rtenneti72546962014-12-15 21:41:5964
mefc2bd1aa2015-04-09 03:26:5365#endif // COMPONENTS_CRONET_HISTOGRAM_MANAGER_H_