Histogram for WebRTC text log upload failure reason.

This histogram is for all web apps in contrast with the other WebRTC text logging histograms.

Bug: 915679
Change-Id: I7f90cc6438db9a9e25f5c64e60ce9a4d4cf0f7a1
Reviewed-on: https://chromium-review.googlesource.com/c/1379957
Reviewed-by: Brian White <bcwhite@chromium.org>
Reviewed-by: Tommi <tommi@chromium.org>
Reviewed-by: Oskar Sundbom <ossu@chromium.org>
Commit-Queue: Henrik Grunell <grunell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#618221}
diff --git a/chrome/browser/media/webrtc/webrtc_log_uploader.cc b/chrome/browser/media/webrtc/webrtc_log_uploader.cc
index b0ab4876..eeb8134 100644
--- a/chrome/browser/media/webrtc/webrtc_log_uploader.cc
+++ b/chrome/browser/media/webrtc/webrtc_log_uploader.cc
@@ -18,6 +18,7 @@
 #include "base/time/time.h"
 #include "build/build_config.h"
 #include "chrome/browser/browser_process.h"
+#include "chrome/browser/media/webrtc/webrtc_logging_handler_host.h"
 #include "chrome/browser/net/system_network_context_manager.h"
 #include "components/version_info/version_info.h"
 #include "components/webrtc_logging/browser/log_cleanup.h"
@@ -197,6 +198,9 @@
     DPLOG(WARNING) << "Could not read WebRTC log file.";
     base::UmaHistogramSparse("WebRtcTextLogging.UploadFailed",
                              upload_data.web_app_id);
+    base::UmaHistogramSparse(
+        "WebRtcTextLogging.UploadFailureReason",
+        WebRtcLoggingHandlerHost::UploadFailureReason::kStoredLogNotFound);
     base::PostTaskWithTraits(
         FROM_HERE, {BrowserThread::UI},
         base::BindOnce(upload_data.callback, false, "", "Log doesn't exist."));
@@ -648,6 +652,8 @@
     } else {
       base::UmaHistogramSparse("WebRtcTextLogging.UploadFailed",
                                upload_done_data.web_app_id);
+      base::UmaHistogramSparse("WebRtcTextLogging.UploadFailureReason",
+                               response_code);
       error_message = "Uploading failed, response code: " +
                       base::IntToString(response_code);
     }
diff --git a/chrome/browser/media/webrtc/webrtc_logging_handler_host.cc b/chrome/browser/media/webrtc/webrtc_logging_handler_host.cc
index 0404c2a..35872e0 100644
--- a/chrome/browser/media/webrtc/webrtc_logging_handler_host.cc
+++ b/chrome/browser/media/webrtc/webrtc_logging_handler_host.cc
@@ -530,8 +530,11 @@
     // If the channel is closing we don't log failure to UMA for consistency,
     // since there are other cases during shutdown were we don't get a chance
     // to log.
-    if (!channel_is_closing)
+    if (!channel_is_closing) {
       base::UmaHistogramSparse("WebRtcTextLogging.UploadFailed", web_app_id_);
+      base::UmaHistogramSparse("WebRtcTextLogging.UploadFailureReason",
+                               UploadFailureReason::kInvalidState);
+    }
     base::PostTaskWithTraits(
         FROM_HERE, {content::BrowserThread::UI},
         base::BindOnce(callback, false, "",
diff --git a/chrome/browser/media/webrtc/webrtc_logging_handler_host.h b/chrome/browser/media/webrtc/webrtc_logging_handler_host.h
index 235fb09..34404c8 100644
--- a/chrome/browser/media/webrtc/webrtc_logging_handler_host.h
+++ b/chrome/browser/media/webrtc/webrtc_logging_handler_host.h
@@ -65,6 +65,14 @@
   // Key used to attach the handler to the RenderProcessHost.
   static const char kWebRtcLoggingHandlerHostKey[];
 
+  // Upload failure reasons used for UMA stats. A failure reason can be one of
+  // those listed here or a response code for the upload HTTP request. The
+  // values in this list must be less than 100 and cannot be changed.
+  enum UploadFailureReason {
+    kInvalidState = 0,
+    kStoredLogNotFound = 1,
+  };
+
   WebRtcLoggingHandlerHost(int render_process_id,
                            content::BrowserContext* browser_context,
                            WebRtcLogUploader* log_uploader);
diff --git a/tools/metrics/histograms/enums.xml b/tools/metrics/histograms/enums.xml
index b74e3bf..375324c2 100644
--- a/tools/metrics/histograms/enums.xml
+++ b/tools/metrics/histograms/enums.xml
@@ -54512,6 +54512,58 @@
   <int value="1" label="Error"/>
 </enum>
 
+<enum name="WebRtcLoggingUploadFailureReason">
+  <summary>
+    Failure reason can be either a response code (except 200 OK) for the upload
+    HTTP request, or another reason prior to uploading (values less than 100).
+    HTTP response codes copied from enum &quot;HttpResponseCode&quot;.
+  </summary>
+  <int value="0" label="Invalid state"/>
+  <int value="1" label="Stored log not found"/>
+  <int value="100" label="100: Continue"/>
+  <int value="101" label="101: Switching Protocols"/>
+  <int value="102" label="102: Processing"/>
+  <int value="103" label="103: Early Hints"/>
+  <int value="201" label="201: Created"/>
+  <int value="202" label="202: Accepted"/>
+  <int value="203" label="203: Non-Authoritative Information"/>
+  <int value="204" label="204: No Content"/>
+  <int value="205" label="205: Reset Content"/>
+  <int value="206" label="206: Partial Content"/>
+  <int value="300" label="300: Multiple Choices"/>
+  <int value="301" label="301: Moved Permanently"/>
+  <int value="302" label="302: Found"/>
+  <int value="303" label="303: See Other"/>
+  <int value="304" label="304: Not Modified"/>
+  <int value="305" label="305: Use Proxy"/>
+  <int value="306" label="306: (Unused)"/>
+  <int value="307" label="307: Temporary Redirect"/>
+  <int value="400" label="400: Bad Request"/>
+  <int value="401" label="401: Unauthorized"/>
+  <int value="402" label="402: Payment Required"/>
+  <int value="403" label="403: Forbidden"/>
+  <int value="404" label="404: Not Found"/>
+  <int value="405" label="405: Method Not Allowed"/>
+  <int value="406" label="406: Not Acceptable"/>
+  <int value="407" label="407: Proxy Authentication Required"/>
+  <int value="408" label="408: Request Timeout"/>
+  <int value="409" label="409: Conflict"/>
+  <int value="410" label="410: Gone"/>
+  <int value="411" label="411: Length Required"/>
+  <int value="412" label="412: Precondition Failed"/>
+  <int value="413" label="413: Request Entity Too Large"/>
+  <int value="414" label="414: Request-URI Too Long"/>
+  <int value="415" label="415: Unsupported Media Type"/>
+  <int value="416" label="416: Requested Range Not Satisfiable"/>
+  <int value="417" label="417: Expectation Failed"/>
+  <int value="500" label="500: Internal Server Error"/>
+  <int value="501" label="501: Not Implemented"/>
+  <int value="502" label="502: Bad Gateway"/>
+  <int value="503" label="503: Service Unavailable"/>
+  <int value="504" label="504: Gateway Timeout"/>
+  <int value="505" label="505: HTTP Version Not Supported"/>
+</enum>
+
 <enum name="WebRtcLoggingWebAppIdHash">
   <int value="-100222544" label="Hangouts"/>
   <int value="0" label="Undefined"/>
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index f791073..e6ef300 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -127324,7 +127324,7 @@
 </histogram>
 
 <histogram base="true" name="WebRtcTextLogging"
-    enum="WebRtcLoggingWebAppIdHash">
+    enum="WebRtcLoggingWebAppIdHash" expires_after="2019-07-01">
   <owner>grunell@chromium.org</owner>
   <summary>
     Counts the number of WebRTC text log events per web application. Suffixed by
@@ -127332,6 +127332,15 @@
   </summary>
 </histogram>
 
+<histogram name="WebRtcTextLogging.UploadFailureReason"
+    enum="WebRtcLoggingUploadFailureReason" expires_after="2019-07-01">
+  <owner>grunell@chromium.org</owner>
+  <summary>
+    Counts upload failures for WebRTC text log. Recorded when an upload attempt
+    fails.
+  </summary>
+</histogram>
+
 <histogram name="WebShare.ApiCount" enum="WebShareMethod">
   <owner>mgiuca@chromium.org</owner>
   <summary>