Add UMA for launcher search times.

Bug: 941590
Change-Id: Ic162bb3574599e85cefd43284e341aa0f7833742
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1524820
Commit-Queue: Stuart Langley <slangley@chromium.org>
Reviewed-by: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: Brian White <bcwhite@chromium.org>
Cr-Commit-Position: refs/heads/master@{#642388}
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index 369ea20..74dea85 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -37684,6 +37684,26 @@
   </summary>
 </histogram>
 
+<histogram name="FileBrowser.LauncherSearch.Drive" units="ms"
+    expires_after="M79">
+  <owner>slangley@chromium.org</owner>
+  <owner>weifangsun@chromium.org</owner>
+  <summary>
+    The time taken to execute launcher search for drive files. Recorded when the
+    complete result set is returned from drive.
+  </summary>
+</histogram>
+
+<histogram name="FileBrowser.LauncherSearch.Local" units="ms"
+    expires_after="M79">
+  <owner>slangley@chromium.org</owner>
+  <owner>weifangsun@chromium.org</owner>
+  <summary>
+    The time taken to execute launcher search for local files. Recorded when the
+    complete result set has been calculated for files on the local disk.
+  </summary>
+</histogram>
+
 <histogram name="FileBrowser.Load" units="ms" expires_after="M79">
   <owner>slangley@chromium.org</owner>
   <owner>weifangsun@chromium.org</owner>
diff --git a/ui/file_manager/file_manager/background/js/launcher_search.js b/ui/file_manager/file_manager/background/js/launcher_search.js
index 36c9580..072796f 100644
--- a/ui/file_manager/file_manager/background/js/launcher_search.js
+++ b/ui/file_manager/file_manager/background/js/launcher_search.js
@@ -113,6 +113,7 @@
 LauncherSearch.prototype.onQueryStarted_ = function(queryId, query, limit) {
   this.queryId_ = queryId;
 
+  const startTime = Date.now();
   // Request an instance of volume manager to ensure that all volumes are
   // initialized. When user searches while background page of the Files app is
   // not running, it happens that this method is executed before all volumes are
@@ -122,8 +123,8 @@
   volumeManagerFactory.getInstance()
       .then(() => {
         return Promise.all([
-          this.queryDriveEntries_(queryId, query, limit),
-          this.queryLocalEntries_(queryId, query)
+          this.queryDriveEntries_(queryId, query, limit, startTime),
+          this.queryLocalEntries_(queryId, query, startTime)
         ]);
       })
       .then((results) => {
@@ -228,10 +229,12 @@
  * @param {number} queryId
  * @param {string} query
  * @param {number} limit
+ * @param {number} startTime
  * @return {!Promise<!Array<!Entry>>}
  * @private
  */
-LauncherSearch.prototype.queryDriveEntries_ = (queryId, query, limit) => {
+LauncherSearch.prototype
+    .queryDriveEntries_ = (queryId, query, limit, startTime) => {
   const param = {query: query, types: 'ALL', maxResults: limit};
   return new Promise((resolve, reject) => {
     chrome.fileManagerPrivate.searchDriveMetadata(param, results => {
@@ -239,6 +242,8 @@
         if (connectionState.type !== 'online') {
           results = results.filter(result => result.availableOffline !== false);
         }
+        chrome.metricsPrivate.recordTime(
+            'FileBrowser.LauncherSearch.Drive', Date.now() - startTime);
         resolve(results.map(result => result.entry));
       });
     });
@@ -249,10 +254,12 @@
  * Queries entries which match the given query in Downloads.
  * @param {number} queryId
  * @param {string} query
+ * @param {number} startTime
  * @return {!Promise<!Array<!Entry>>}
  * @private
  */
-LauncherSearch.prototype.queryLocalEntries_ = function(queryId, query) {
+LauncherSearch.prototype.queryLocalEntries_ = function(
+    queryId, query, startTime) {
   if (!query) {
     return Promise.resolve([]);
   }
@@ -260,7 +267,7 @@
   return this.getDownloadsEntry_()
       .then((downloadsEntry) => {
         return this.queryEntriesRecursively_(
-            downloadsEntry, queryId, query.toLowerCase());
+            downloadsEntry, queryId, query.toLowerCase(), startTime);
       })
       .catch((error) => {
         if (error.name != 'AbortError') {
@@ -288,11 +295,12 @@
  * @param {!DirectoryEntry} rootEntry
  * @param {number} queryId
  * @param {string} query
+ * @param {number} startTime
  * @return {!Promise<!Array<!Entry>>}
  * @private
  */
 LauncherSearch.prototype.queryEntriesRecursively_ = function(
-    rootEntry, queryId, query) {
+    rootEntry, queryId, query, startTime) {
   return new Promise((resolve, reject) => {
     let foundEntries = [];
     util.readEntriesRecursively(
@@ -305,6 +313,8 @@
           }
         },
         () => {
+          chrome.metricsPrivate.recordTime(
+              'FileBrowser.LauncherSearch.Local', Date.now() - startTime);
           resolve(foundEntries);
         },
         reject,