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

Unified Diff: base/metrics/histogram_base.cc

Issue 11682003: Serialize/Deserialize support in HistogramBase (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another friend change Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/metrics/histogram_base.h ('k') | base/metrics/histogram_base_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/histogram_base.cc
diff --git a/base/metrics/histogram_base.cc b/base/metrics/histogram_base.cc
index bcfb57feb231ce7be9b31bbf4eb34b0e8b441b0d..63961327a0422fdc9ef75f2f2e160459c8f1afcc 100644
--- a/base/metrics/histogram_base.cc
+++ b/base/metrics/histogram_base.cc
@@ -9,6 +9,10 @@
#include "base/logging.h"
#include "base/json/json_string_value_serializer.h"
#include "base/memory/scoped_ptr.h"
+#include "base/metrics/histogram.h"
+#include "base/metrics/histogram_samples.h"
+#include "base/metrics/sparse_histogram.h"
+#include "base/pickle.h"
#include "base/values.h"
namespace base {
@@ -31,6 +35,41 @@ std::string HistogramTypeToString(HistogramType type) {
return "UNKNOWN";
}
+HistogramBase* DeserializeHistogramInfo(PickleIterator* iter) {
+ int type;
+ if (!iter->ReadInt(&type))
+ return NULL;
+
+ switch (type) {
+ case HISTOGRAM:
+ return Histogram::DeserializeInfoImpl(iter);
+ case LINEAR_HISTOGRAM:
+ return LinearHistogram::DeserializeInfoImpl(iter);
+ case BOOLEAN_HISTOGRAM:
+ return BooleanHistogram::DeserializeInfoImpl(iter);
+ case CUSTOM_HISTOGRAM:
+ return CustomHistogram::DeserializeInfoImpl(iter);
+ case SPARSE_HISTOGRAM:
+ return SparseHistogram::DeserializeInfoImpl(iter);
+ default:
+ return NULL;
+ }
+}
+
+void DeserializeHistogramAndAddSamples(PickleIterator* iter) {
+ HistogramBase* histogram = DeserializeHistogramInfo(iter);
+ if (!histogram)
+ return;
+
+ if (histogram->flags() & base::HistogramBase::kIPCSerializationSourceFlag) {
+ DVLOG(1) << "Single process mode, histogram observed and not copied: "
+ << histogram->histogram_name();
+ return;
+ }
+ histogram->AddSamplesFromPickle(iter);
+}
+
+
const HistogramBase::Sample HistogramBase::kSampleType_MAX = INT_MAX;
HistogramBase::HistogramBase(const std::string& name)
@@ -47,6 +86,12 @@ void HistogramBase::ClearFlags(int32 flags) {
flags_ &= ~flags;
}
+bool HistogramBase::SerializeInfo(Pickle* pickle) const {
+ if (!pickle->WriteInt(GetHistogramType()))
+ return false;
+ return SerializeInfoImpl(pickle);
+}
+
void HistogramBase::WriteJSON(std::string* output) const {
Count count;
scoped_ptr<ListValue> buckets(new ListValue());
« no previous file with comments | « base/metrics/histogram_base.h ('k') | base/metrics/histogram_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698