[Metrics] Refactor InitializeSystemProfileMetrics() using queue of tasks.

Previously ChromeMetricsServiceClient has 7 OnInitTask...() functions
that chain to one another. This was hard to maintain since it couples
adjacent tasks, e.g.:

doA(OnInitTaskGotA)

def OnInitTaskGotA():
  doB(OnInitTaskGotB)

def OnInitTaskGotB():
  doC(OnInitTaskGotC)
...

Usage of #define adds more complication. This CL cleans this up by
adding initialize_task_queue_ and OnInitNextTask(). The queue stores
the list of initialization tasks, and OnInitNextTask() mediates the
task chaining by passing itself as the callback to be executed on
completion by each task.

Review-Url: https://codereview.chromium.org/2467293005
Cr-Commit-Position: refs/heads/master@{#430007}
diff --git a/chrome/browser/metrics/chrome_metrics_service_client.h b/chrome/browser/metrics/chrome_metrics_service_client.h
index abd603d..e937202 100644
--- a/chrome/browser/metrics/chrome_metrics_service_client.h
+++ b/chrome/browser/metrics/chrome_metrics_service_client.h
@@ -8,6 +8,7 @@
 #include <stdint.h>
 
 #include <memory>
+#include <queue>
 #include <string>
 
 #include "base/callback.h"
@@ -96,31 +97,10 @@
   // Completes the two-phase initialization of ChromeMetricsServiceClient.
   void Initialize();
 
-  // Callback that continues the init task by getting a Bluetooth Adapter.
-  void OnInitTaskGotHardwareClass();
-
-  // Callback that continues the init task by loading plugin information.
-  void OnInitTaskGotBluetoothAdapter();
-
-  // Called after the Plugin init task has been completed that continues the
-  // init task by launching a task to gather Google Update statistics.
-  void OnInitTaskGotPluginInfo();
-
-  // Called after GoogleUpdate init task has been completed that continues the
-  // init task by loading AntiVirus metrics.
-  void OnInitTaskGotGoogleUpdateData();
-
-  // Called after AntiVirus init task has been completed that continues the
-  // init task by loading drive metrics.
-  void OnInitTaskGotAntiVirusData();
-
-  // Called after the drive metrics init task has been completed to continue
-  // the init task by optionally collecting postmortem reports.
-  void OnInitTaskGotDriveMetrics();
-
-  // Called after the postmortem report collection task has been completed to
-  // continue the init task by loading profiler data.
-  void OnInitTaskCollectedPostmortemReports();
+  // Callback to chain init tasks: Pops and executes the next init task from
+  // |initialize_task_queue_|, then passes itself as callback for each init task
+  // to call upon completion.
+  void OnInitNextTask();
 
   // Returns true iff profiler data should be included in the next metrics log.
   // NOTE: This method is probabilistic and also updates internal state as a
@@ -180,6 +160,10 @@
   ChromeOSMetricsProvider* chromeos_metrics_provider_;
 #endif
 
+  // A queue of tasks for initial metrics gathering. These may be asynchronous
+  // or synchronous.
+  std::deque<base::Closure> initialize_task_queue_;
+
   // Saved callback received from CollectFinalMetricsForLog().
   base::Closure collect_final_metrics_done_callback_;
 
@@ -217,9 +201,6 @@
   // Has the same lifetime as |metrics_service_|.
   metrics::DriveMetricsProvider* drive_metrics_provider_;
 
-  // Callback that is called when initial metrics gathering is complete.
-  base::Closure finished_init_task_callback_;
-
   // The MemoryGrowthTracker instance that tracks memory usage growth in
   // MemoryDetails.
   MemoryGrowthTracker memory_growth_tracker_;