update_client: refactor the parsing and serializing of XML.

This is a mechanical change.

It introduces ProtocolParser and ProtocolSerializer abstract classes
to allow different protocols in the future. Only the XML implementation
of these classes is provided in this changelist.

Bug: 848505
Change-Id: I4bda0f92f5b676f0f0eaca7dc841c8dca9c282ad
Reviewed-on: https://chromium-review.googlesource.com/c/1278476
Commit-Queue: Sorin Jianu <[email protected]>
Reviewed-by: Joshua Pawlicki <[email protected]>
Cr-Commit-Position: refs/heads/master@{#599366}
diff --git a/components/update_client/component.h b/components/update_client/component.h
index 64f6d7b..1e8ed14 100644
--- a/components/update_client/component.h
+++ b/components/update_client/component.h
@@ -25,6 +25,9 @@
 #include "components/update_client/update_client.h"
 #include "url/gurl.h"
 
+namespace base {
+class Value;
+}  // namespace base
 
 namespace update_client {
 
@@ -97,8 +100,6 @@
 
   bool is_foreground() const;
 
-  const std::vector<std::string>& events() const { return events_; }
-
   const std::vector<GURL>& crx_diffurls() const { return crx_diffurls_; }
 
   bool diff_update_failed() const { return !!diff_error_code_; }
@@ -116,6 +117,11 @@
 
   std::string session_id() const;
 
+  const std::vector<base::Value>& events() const { return events_; }
+
+  // Returns a clone of the component events.
+  std::vector<base::Value> GetEvents() const;
+
  private:
   friend class MockPingManagerImpl;
   friend class UpdateCheckerTest;
@@ -357,7 +363,7 @@
   // by a downloader which can do bandwidth throttling on the client side.
   bool CanDoBackgroundDownload() const;
 
-  void AppendEvent(const std::string& event);
+  void AppendEvent(base::Value event);
 
   // Changes the component state and notifies the caller of the |Handle|
   // function that the handling of this component state is complete.
@@ -368,6 +374,16 @@
 
   void SetParseResult(const ProtocolParser::Result& result);
 
+  // These functions return a specific event. Each data member of the event is
+  // represented as a key-value pair in a dictionary value.
+  base::Value MakeEventUpdateComplete() const;
+  base::Value MakeEventDownloadMetrics(
+      const CrxDownloader::DownloadMetrics& download_metrics) const;
+  base::Value MakeEventUninstalled() const;
+  base::Value MakeEventActionRun(bool succeeded,
+                                 int error_code,
+                                 int extra_code1) const;
+
   base::ThreadChecker thread_checker_;
 
   const std::string id_;
@@ -421,8 +437,8 @@
   int diff_error_code_ = 0;
   int diff_extra_code1_ = 0;
 
-  // Contains the events which are serialized in the pings.
-  std::vector<std::string> events_;
+  // Contains the events which are therefore serialized in the requests.
+  std::vector<base::Value> events_;
 
   CallbackHandleComplete callback_handle_complete_;
   std::unique_ptr<State> state_;