Serialize/Deserialize support in HistogramBase

BUG=139612,167343


Review URL: https://chromiumcodereview.appspot.com/11682003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176449 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/base/metrics/histogram_base.h b/base/metrics/histogram_base.h
index 302795a..69e1437 100644
--- a/base/metrics/histogram_base.h
+++ b/base/metrics/histogram_base.h
@@ -11,9 +11,13 @@
 #include "base/basictypes.h"
 #include "base/memory/scoped_ptr.h"
 
+class Pickle;
+class PickleIterator;
+
 namespace base {
 
 class DictionaryValue;
+class HistogramBase;
 class HistogramSamples;
 class ListValue;
 
@@ -32,6 +36,15 @@
 
 std::string HistogramTypeToString(HistogramType type);
 
+// Create or find existing histogram that matches the pickled info.
+// Returns NULL if the pickled data has problems.
+BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo(
+    PickleIterator* iter);
+
+// Create or find existing histogram and add the samples from pickle.
+// Silently returns when seeing any data problem in the pickle.
+BASE_EXPORT void DeserializeHistogramAndAddSamples(PickleIterator* iter);
+
 ////////////////////////////////////////////////////////////////////////////////
 
 class BASE_EXPORT HistogramBase {
@@ -69,14 +82,22 @@
   virtual HistogramType GetHistogramType() const = 0;
 
   // Whether the histogram has construction arguments as parameters specified.
-  // For histograms that don't have the concept of minimum, maximum or
-  // bucket_count, this function always returns false.
+  // For histograms that don't have the concept of |minimum|, |maximum| or
+  // |bucket_count|, this function always returns false.
   virtual bool HasConstructionArguments(Sample minimum,
                                         Sample maximum,
                                         size_t bucket_count) const = 0;
 
   virtual void Add(Sample value) = 0;
 
+  virtual void AddSamples(const HistogramSamples& samples) = 0;
+  virtual bool AddSamplesFromPickle(PickleIterator* iter) = 0;
+
+  // Serialize the histogram info into |pickle|.
+  // Note: This only serializes the construction arguments of the histogram, but
+  // does not serialize the samples.
+  bool SerializeInfo(Pickle* pickle) const;
+
   // Snapshot the current complete set of sample data.
   // Override with atomic/locked snapshot if needed.
   virtual scoped_ptr<HistogramSamples> SnapshotSamples() const = 0;
@@ -91,6 +112,9 @@
   void WriteJSON(std::string* output) const;
 
 protected:
+  // Subclasses should implement this function to make SerializeInfo work.
+  virtual bool SerializeInfoImpl(Pickle* pickle) const = 0;
+
   // Writes information about the construction parameters in |params|.
   virtual void GetParameters(DictionaryValue* params) const = 0;