Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / components / data_reduction_proxy / browser / data_reduction_proxy_usage_stats.cc
index a0af979..a7426f5 100644 (file)
@@ -9,8 +9,11 @@
 #include "base/message_loop/message_loop_proxy.h"
 #include "base/metrics/histogram.h"
 #include "base/metrics/sparse_histogram.h"
+#include "base/prefs/pref_member.h"
 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h"
 #include "net/base/net_errors.h"
+#include "net/http/http_response_headers.h"
+#include "net/http/http_status_code.h"
 #include "net/proxy/proxy_retry_info.h"
 #include "net/proxy/proxy_server.h"
 #include "net/proxy/proxy_service.h"
@@ -76,9 +79,29 @@ void DataReductionProxyUsageStats::RecordDataReductionProxyBypassInfo(
   }
 }
 
+// static
+void DataReductionProxyUsageStats::DetectAndRecordMissingViaHeaderResponseCode(
+      bool is_primary,
+      const net::HttpResponseHeaders* headers) {
+  if (HasDataReductionProxyViaHeader(headers, NULL)) {
+    // The data reduction proxy via header is present, so don't record anything.
+    return;
+  }
+
+  if (is_primary) {
+    UMA_HISTOGRAM_SPARSE_SLOWLY(
+        "DataReductionProxy.MissingViaHeader.ResponseCode.Primary",
+        headers->response_code());
+  } else {
+    UMA_HISTOGRAM_SPARSE_SLOWLY(
+        "DataReductionProxy.MissingViaHeader.ResponseCode.Fallback",
+        headers->response_code());
+  }
+}
+
 DataReductionProxyUsageStats::DataReductionProxyUsageStats(
     DataReductionProxyParams* params,
-    MessageLoopProxy* ui_thread_proxy)
+    const scoped_refptr<MessageLoopProxy>& ui_thread_proxy)
     : data_reduction_proxy_params_(params),
       last_bypass_type_(BYPASS_EVENT_TYPE_MAX),
       triggering_request_(true),
@@ -145,22 +168,31 @@ void DataReductionProxyUsageStats::SetBypassType(
   triggering_request_ = true;
 }
 
+void DataReductionProxyUsageStats::RecordBytesHistograms(
+    net::URLRequest* request,
+    const BooleanPrefMember& data_reduction_proxy_enabled,
+    const net::ProxyConfig& data_reduction_proxy_config) {
+  RecordBypassedBytesHistograms(request, data_reduction_proxy_enabled,
+                                data_reduction_proxy_config);
+  RecordMissingViaHeaderBytes(request);
+}
+
 void DataReductionProxyUsageStats::RecordBypassedBytesHistograms(
-    net::URLRequest& request,
+    net::URLRequest* request,
     const BooleanPrefMember& data_reduction_proxy_enabled,
     const net::ProxyConfig& data_reduction_proxy_config) {
-  int64 content_length = request.received_response_content_length();
+  int64 content_length = request->received_response_content_length();
 
   if (data_reduction_proxy_enabled.GetValue() &&
       !data_reduction_proxy_config.Equals(
-          request.context()->proxy_service()->config())) {
+          request->context()->proxy_service()->config())) {
     RecordBypassedBytes(last_bypass_type_,
                         DataReductionProxyUsageStats::MANAGED_PROXY_CONFIG,
                         content_length);
     return;
   }
 
-  if (data_reduction_proxy_params_->WasDataReductionProxyUsed(&request, NULL)) {
+  if (data_reduction_proxy_params_->WasDataReductionProxyUsed(request, NULL)) {
     RecordBypassedBytes(last_bypass_type_,
                         DataReductionProxyUsageStats::NOT_BYPASSED,
                         content_length);
@@ -168,7 +200,7 @@ void DataReductionProxyUsageStats::RecordBypassedBytesHistograms(
   }
 
   if (data_reduction_proxy_enabled.GetValue() &&
-      request.url().SchemeIs(url::kHttpsScheme)) {
+      request->url().SchemeIs(url::kHttpsScheme)) {
     RecordBypassedBytes(last_bypass_type_,
                         DataReductionProxyUsageStats::SSL,
                         content_length);
@@ -177,7 +209,7 @@ void DataReductionProxyUsageStats::RecordBypassedBytesHistograms(
 
   if (data_reduction_proxy_enabled.GetValue() &&
       data_reduction_proxy_params_->IsBypassedByDataReductionProxyLocalRules(
-          request, data_reduction_proxy_config)) {
+          *request, data_reduction_proxy_config)) {
     RecordBypassedBytes(last_bypass_type_,
                         DataReductionProxyUsageStats::LOCAL_BYPASS_RULES,
                         content_length);
@@ -191,7 +223,7 @@ void DataReductionProxyUsageStats::RecordBypassedBytesHistograms(
       last_bypass_type_ ==  BYPASS_EVENT_TYPE_MEDIUM ||
       last_bypass_type_ ==  BYPASS_EVENT_TYPE_LONG)) {
     std::string mime_type;
-    request.GetMimeType(&mime_type);
+    request->GetMimeType(&mime_type);
     // MIME types are named by <media-type>/<subtype>. Check to see if the
     // media type is audio or video. Only record when triggered by short bypass,
     // there isn't an audio or video bucket for medium or long bypasses.
@@ -218,7 +250,7 @@ void DataReductionProxyUsageStats::RecordBypassedBytesHistograms(
     return;
   }
 
-  if (data_reduction_proxy_params_->AreDataReductionProxiesBypassed(request,
+  if (data_reduction_proxy_params_->AreDataReductionProxiesBypassed(*request,
                                                                     NULL)) {
     RecordBypassedBytes(last_bypass_type_,
                         DataReductionProxyUsageStats::NETWORK_ERROR,
@@ -378,6 +410,30 @@ void DataReductionProxyUsageStats::RecordBypassedBytes(
   }
 }
 
+void DataReductionProxyUsageStats::RecordMissingViaHeaderBytes(
+    URLRequest* request) {
+  // Responses that were served from cache should have been filtered out
+  // already.
+  DCHECK(!request->was_cached());
+
+  if (!data_reduction_proxy_params_->WasDataReductionProxyUsed(request, NULL) ||
+      HasDataReductionProxyViaHeader(request->response_headers(), NULL)) {
+    // Only track requests that used the data reduction proxy and had responses
+    // that were missing the data reduction proxy via header.
+    return;
+  }
+
+  if (request->GetResponseCode() >= net::HTTP_BAD_REQUEST &&
+      request->GetResponseCode() < net::HTTP_INTERNAL_SERVER_ERROR) {
+    // Track 4xx responses that are missing via headers separately.
+    UMA_HISTOGRAM_COUNTS("DataReductionProxy.MissingViaHeader.Bytes.4xx",
+                         request->received_response_content_length());
+  } else {
+    UMA_HISTOGRAM_COUNTS("DataReductionProxy.MissingViaHeader.Bytes.Other",
+                         request->received_response_content_length());
+  }
+}
+
 }  // namespace data_reduction_proxy