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

Unified Diff: components/data_use_measurement/content/content_url_request_classifier.cc

Issue 2595503002: Record the data use by content type (Closed)
Patch Set: fixed nits Created 4 years 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: components/data_use_measurement/content/content_url_request_classifier.cc
diff --git a/components/data_use_measurement/content/content_url_request_classifier.cc b/components/data_use_measurement/content/content_url_request_classifier.cc
index 23bbd8baa9624a0515bfab3b4bf2026ab5e4243a..2c723b6968498b4b395e022a950f4b39d58fde34 100644
--- a/components/data_use_measurement/content/content_url_request_classifier.cc
+++ b/components/data_use_measurement/content/content_url_request_classifier.cc
@@ -4,7 +4,12 @@
#include "components/data_use_measurement/content/content_url_request_classifier.h"
+#include <string>
+
+#include "base/strings/string_util.h"
#include "content/public/browser/resource_request_info.h"
+#include "content/public/common/resource_type.h"
+#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
namespace data_use_measurement {
@@ -26,4 +31,40 @@ bool ContentURLRequestClassifier::IsUserRequest(
return data_use_measurement::IsUserRequest(request);
}
+DataUseUserData::DataUseContentType ContentURLRequestClassifier::GetContentType(
+ const net::URLRequest& request,
+ const net::HttpResponseHeaders& response_headers) const {
+ const content::ResourceRequestInfo* request_info =
+ content::ResourceRequestInfo::ForRequest(&request);
+ std::string mime_type;
+ if (response_headers.GetMimeType(&mime_type)) {
+ if (mime_type == "text/html" && request_info &&
+ request_info->GetResourceType() ==
+ content::ResourceType::RESOURCE_TYPE_MAIN_FRAME) {
+ return DataUseUserData::MAIN_FRAME_HTML;
+ } else if (mime_type == "text/html") {
+ return DataUseUserData::NON_MAIN_FRAME_HTML;
+ } else if (mime_type == "text/css") {
+ return DataUseUserData::CSS;
+ } else if (base::StartsWith(mime_type, "image/",
+ base::CompareCase::SENSITIVE)) {
+ return DataUseUserData::IMAGE;
+ } else if (base::EndsWith(mime_type, "javascript",
+ base::CompareCase::SENSITIVE) ||
+ base::EndsWith(mime_type, "ecmascript",
+ base::CompareCase::SENSITIVE)) {
+ return DataUseUserData::JAVASCRIPT;
+ } else if (mime_type.find("font") != std::string::npos) {
+ return DataUseUserData::FONT;
+ } else if (base::StartsWith(mime_type, "audio/",
+ base::CompareCase::SENSITIVE)) {
+ return DataUseUserData::AUDIO;
+ } else if (base::StartsWith(mime_type, "video/",
+ base::CompareCase::SENSITIVE)) {
+ return DataUseUserData::VIDEO;
+ }
+ }
+ return DataUseUserData::OTHER;
+}
+
} // namespace data_use_measurement

Powered by Google App Engine
This is Rietveld 408576698