Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1261)

Unified Diff: chrome/renderer/page_load_histograms.cc

Issue 156373002: Support for new data reduction proxy via header (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/page_load_histograms.cc
diff --git a/chrome/renderer/page_load_histograms.cc b/chrome/renderer/page_load_histograms.cc
index 6ce21e24031130bec14e039ac58dd12542ea7a3e..7aeeaa201dc2672fbb880cf2eeb319ea32db2847 100644
--- a/chrome/renderer/page_load_histograms.cc
+++ b/chrome/renderer/page_load_histograms.cc
@@ -32,6 +32,10 @@
#include "third_party/WebKit/public/web/WebView.h"
#include "url/gurl.h"
+#if defined(SPDY_PROXY_AUTH_ORIGIN)
+#include "net/http/http_response_headers.h"
+#endif
+
using blink::WebDataSource;
using blink::WebFrame;
using blink::WebPerformance;
@@ -191,13 +195,26 @@ bool ViaHeaderContains(WebFrame* frame, const std::string& via_value) {
// Returns true if the data reduction proxy was used. Note, this function will
// produce a false positive if a page is fetched using SPDY and using a proxy,
-// and |kDatReductionProxyViaValue| is added to the Via header.
-// TODO(bengr): Plumb the hostname of the proxy from |HttpNetworkTransaction|
-// and check if it matches |SPDY_PROXY_AUTH_ORIGIN|.
+// and the data reduction proxy's via value is added to the Via header.
+// TODO(bengr): Plumb the hostname of the proxy and check if it matches
+// |SPDY_PROXY_AUTH_ORIGIN|.
bool DataReductionProxyWasUsed(WebFrame* frame) {
#if defined(SPDY_PROXY_AUTH_ORIGIN)
- const char kDatReductionProxyViaValue[] = "1.1 Chrome Compression Proxy";
- return ViaHeaderContains(frame, kDatReductionProxyViaValue);
+ DocumentState* document_state =
+ DocumentState::FromDataSource(frame->dataSource());
+ if (!document_state->was_fetched_via_proxy())
+ return false;
+
+ std::string via_header =
+ base::UTF16ToUTF8(frame->dataSource()->response().httpHeaderField("Via"));
+
+ if (via_header.empty())
+ return false;
+ std::string headers = "HTTP/1.1 200 OK\nVia: " + via_header + "\n\n";
+ std::replace(headers.begin(), headers.end(), '\n', '\0');
+ scoped_refptr<net::HttpResponseHeaders> response_headers(
+ new net::HttpResponseHeaders(headers));
+ return response_headers->IsChromeProxyResponse();
#endif
return false;
}

Powered by Google App Engine
This is Rietveld 408576698