summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-16 23:55:46 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-16 23:55:46 +0000
commit8bd9e5623c17e845acbc182772b63f818f1d0bd5 (patch)
tree9e93966555cc92acb9799fd2a94ad07155691ec0 /content
parent8e9424b48974b88422d873dab17058f53506437a (diff)
downloadchromium_src-8bd9e5623c17e845acbc182772b63f818f1d0bd5.zip
chromium_src-8bd9e5623c17e845acbc182772b63f818f1d0bd5.tar.gz
chromium_src-8bd9e5623c17e845acbc182772b63f818f1d0bd5.tar.bz2
Move download UMA functions to their own file in content. Also fire the chrome-only notification for download initiated in chrome code from the chrome delegate.
BUG=82782 Review URL: http://codereview.chromium.org/7664019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97059 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/DEPS9
-rw-r--r--content/browser/download/download_item.cc13
-rw-r--r--content/browser/download/download_resource_handler.cc6
-rw-r--r--content/browser/download/download_stats.cc151
-rw-r--r--content/browser/download/download_stats.h77
-rw-r--r--content/browser/renderer_host/render_message_filter.cc6
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host.cc6
-rw-r--r--content/browser/tab_contents/tab_contents.cc6
-rw-r--r--content/content_browser.gypi2
9 files changed, 246 insertions, 30 deletions
diff --git a/content/browser/DEPS b/content/browser/DEPS
index ef18b72..4623a01 100644
--- a/content/browser/DEPS
+++ b/content/browser/DEPS
@@ -7,15 +7,6 @@ include_rules = [
# See https://sites.google.com/a/chromium.org/dev/developers/content-module
# for more information.
- # http://crbug.com/82782
- "+chrome/browser/download/download_file_manager.h",
- "+chrome/browser/download/download_manager.h",
- "+chrome/browser/download/download_request_limiter.h",
- "+chrome/browser/download/download_types.h",
- "+chrome/browser/download/download_util.h",
- "+chrome/browser/renderer_host/download_resource_handler.h",
- "+chrome/browser/renderer_host/download_throttling_resource_handler.h",
-
# http://crbug.com/76788
"+chrome/browser/profiles/profile.h",
diff --git a/content/browser/download/download_item.cc b/content/browser/download/download_item.cc
index e2648d3..508185d8 100644
--- a/content/browser/download/download_item.cc
+++ b/content/browser/download/download_item.cc
@@ -32,6 +32,7 @@
#include "content/browser/download/download_file_manager.h"
#include "content/browser/download/download_manager.h"
#include "content/browser/download/download_manager_delegate.h"
+#include "content/browser/download/download_stats.h"
#include "content/common/notification_source.h"
// A DownloadItem normally goes through the following states:
@@ -387,7 +388,7 @@ void DownloadItem::Cancel(bool update_history) {
return;
}
- download_util::RecordDownloadCount(download_util::CANCELLED_COUNT);
+ download_stats::RecordDownloadCount(download_stats::CANCELLED_COUNT);
TransitionTo(CANCELLED);
StopProgressTimer();
@@ -427,7 +428,7 @@ void DownloadItem::Completed() {
DCHECK(all_data_saved_);
TransitionTo(COMPLETE);
download_manager_->DownloadCompleted(id());
- download_util::RecordDownloadCompleted(start_tick_);
+ download_stats::RecordDownloadCompleted(start_tick_);
if (is_extension_install()) {
// Extensions should already have been unpacked and opened.
@@ -527,9 +528,9 @@ void DownloadItem::Interrupted(int64 size, int os_error) {
last_os_error_ = os_error;
UpdateSize(size);
StopProgressTimer();
- download_util::RecordDownloadInterrupted(os_error,
- received_bytes_,
- total_bytes_);
+ download_stats::RecordDownloadInterrupted(os_error,
+ received_bytes_,
+ total_bytes_);
TransitionTo(INTERRUPTED);
}
@@ -779,7 +780,7 @@ void DownloadItem::Init(bool active) {
UpdateTarget();
if (active) {
StartProgressTimer();
- download_util::RecordDownloadCount(download_util::START_COUNT);
+ download_stats::RecordDownloadCount(download_stats::START_COUNT);
}
VLOG(20) << __FUNCTION__ << "() " << DebugString(true);
}
diff --git a/content/browser/download/download_resource_handler.cc b/content/browser/download/download_resource_handler.cc
index 059fb95..cd03db8 100644
--- a/content/browser/download/download_resource_handler.cc
+++ b/content/browser/download/download_resource_handler.cc
@@ -10,12 +10,12 @@
#include "base/metrics/histogram.h"
#include "base/metrics/stats_counters.h"
#include "base/stringprintf.h"
-#include "chrome/browser/download/download_util.h"
#include "content/browser/browser_thread.h"
#include "content/browser/download/download_create_info.h"
#include "content/browser/download/download_file_manager.h"
#include "content/browser/download/download_item.h"
#include "content/browser/download/download_request_handle.h"
+#include "content/browser/download/download_stats.h"
#include "content/browser/renderer_host/global_request_id.h"
#include "content/browser/renderer_host/resource_dispatcher_host.h"
#include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
@@ -45,7 +45,7 @@ DownloadResourceHandler::DownloadResourceHandler(
buffer_(new DownloadBuffer),
rdh_(rdh),
is_paused_(false) {
- download_util::RecordDownloadCount(download_util::UNTHROTTLED_COUNT);
+ download_stats::RecordDownloadCount(download_stats::UNTHROTTLED_COUNT);
}
bool DownloadResourceHandler::OnUploadProgress(int request_id,
@@ -95,7 +95,7 @@ bool DownloadResourceHandler::OnResponseStarted(int request_id,
global_id_.request_id);
info->content_disposition = content_disposition_;
info->mime_type = response->response_head.mime_type;
- download_util::RecordDownloadMimeType(info->mime_type);
+ download_stats::RecordDownloadMimeType(info->mime_type);
// TODO(ahendrickson) -- Get the last modified time and etag, so we can
// resume downloading.
diff --git a/content/browser/download/download_stats.cc b/content/browser/download/download_stats.cc
new file mode 100644
index 0000000..c51f68a
--- /dev/null
+++ b/content/browser/download/download_stats.cc
@@ -0,0 +1,151 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/download/download_stats.h"
+
+#include "base/metrics/histogram.h"
+#include "base/string_util.h"
+
+namespace download_stats {
+
+// All possible error codes from the network module. Note that the error codes
+// are all positive (since histograms expect positive sample values).
+const int kAllNetErrorCodes[] = {
+#define NET_ERROR(label, value) -(value),
+#include "net/base/net_error_list.h"
+#undef NET_ERROR
+};
+
+void RecordDownloadCount(DownloadCountTypes type) {
+ UMA_HISTOGRAM_ENUMERATION(
+ "Download.Counts", type, DOWNLOAD_COUNT_TYPES_LAST_ENTRY);
+}
+
+void RecordDownloadCompleted(const base::TimeTicks& start) {
+ RecordDownloadCount(COMPLETED_COUNT);
+ UMA_HISTOGRAM_LONG_TIMES("Download.Time", (base::TimeTicks::Now() - start));
+}
+
+void RecordDownloadInterrupted(int error, int64 received, int64 total) {
+ RecordDownloadCount(INTERRUPTED_COUNT);
+ UMA_HISTOGRAM_CUSTOM_ENUMERATION(
+ "Download.InterruptedError",
+ -error,
+ base::CustomHistogram::ArrayToCustomRanges(
+ kAllNetErrorCodes, arraysize(kAllNetErrorCodes)));
+
+ // The maximum should be 2^kBuckets, to have the logarithmic bucket
+ // boundaries fall on powers of 2.
+ static const int kBuckets = 30;
+ static const int64 kMaxKb = 1 << kBuckets; // One Terabyte, in Kilobytes.
+ int64 delta_bytes = total - received;
+ bool unknown_size = total <= 0;
+ int64 received_kb = received / 1024;
+ int64 total_kb = total / 1024;
+ UMA_HISTOGRAM_CUSTOM_COUNTS("Download.InterruptedReceivedSizeK",
+ received_kb,
+ 1,
+ kMaxKb,
+ kBuckets);
+ if (!unknown_size) {
+ UMA_HISTOGRAM_CUSTOM_COUNTS("Download.InterruptedTotalSizeK",
+ total_kb,
+ 1,
+ kMaxKb,
+ kBuckets);
+ if (delta_bytes >= 0) {
+ UMA_HISTOGRAM_CUSTOM_COUNTS("Download.InterruptedOverrunBytes",
+ delta_bytes,
+ 1,
+ kMaxKb,
+ kBuckets);
+ } else {
+ UMA_HISTOGRAM_CUSTOM_COUNTS("Download.InterruptedUnderrunBytes",
+ -delta_bytes,
+ 1,
+ kMaxKb,
+ kBuckets);
+ }
+ }
+
+ UMA_HISTOGRAM_BOOLEAN("Download.InterruptedUnknownSize", unknown_size);
+}
+
+namespace {
+
+enum DownloadContent {
+ DOWNLOAD_CONTENT_UNRECOGNIZED = 0,
+ DOWNLOAD_CONTENT_TEXT = 1,
+ DOWNLOAD_CONTENT_IMAGE = 2,
+ DOWNLOAD_CONTENT_AUDIO = 3,
+ DOWNLOAD_CONTENT_VIDEO = 4,
+ DOWNLOAD_CONTENT_OCTET_STREAM = 5,
+ DOWNLOAD_CONTENT_PDF = 6,
+ DOWNLOAD_CONTENT_DOC = 7,
+ DOWNLOAD_CONTENT_XLS = 8,
+ DOWNLOAD_CONTENT_PPT = 9,
+ DOWNLOAD_CONTENT_ARCHIVE = 10,
+ DOWNLOAD_CONTENT_EXE = 11,
+ DOWNLOAD_CONTENT_DMG = 12,
+ DOWNLOAD_CONTENT_CRX = 13,
+ DOWNLOAD_CONTENT_MAX = 14,
+};
+
+struct MimeTypeToDownloadContent {
+ const char* mime_type;
+ DownloadContent download_content;
+};
+
+static MimeTypeToDownloadContent kMapMimeTypeToDownloadContent[] = {
+ {"application/octet-stream", DOWNLOAD_CONTENT_OCTET_STREAM},
+ {"binary/octet-stream", DOWNLOAD_CONTENT_OCTET_STREAM},
+ {"application/pdf", DOWNLOAD_CONTENT_PDF},
+ {"application/msword", DOWNLOAD_CONTENT_DOC},
+ {"application/vnd.ms-excel", DOWNLOAD_CONTENT_XLS},
+ {"application/vns.ms-powerpoint", DOWNLOAD_CONTENT_PPT},
+ {"application/zip", DOWNLOAD_CONTENT_ARCHIVE},
+ {"application/x-gzip", DOWNLOAD_CONTENT_ARCHIVE},
+ {"application/x-rar-compressed", DOWNLOAD_CONTENT_ARCHIVE},
+ {"application/x-tar", DOWNLOAD_CONTENT_ARCHIVE},
+ {"application/x-bzip", DOWNLOAD_CONTENT_ARCHIVE},
+ {"application/x-exe", DOWNLOAD_CONTENT_EXE},
+ {"application/x-apple-diskimage", DOWNLOAD_CONTENT_DMG},
+ {"application/x-chrome-extension", DOWNLOAD_CONTENT_CRX},
+};
+
+} // namespace
+
+void RecordDownloadMimeType(const std::string& mime_type_string) {
+ DownloadContent download_content = DOWNLOAD_CONTENT_UNRECOGNIZED;
+
+ // Look up exact matches.
+ for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadContent); ++i) {
+ const MimeTypeToDownloadContent& entry =
+ kMapMimeTypeToDownloadContent[i];
+ if (mime_type_string == entry.mime_type) {
+ download_content = entry.download_content;
+ break;
+ }
+ }
+
+ // Do partial matches.
+ if (download_content == DOWNLOAD_CONTENT_UNRECOGNIZED) {
+ if (StartsWithASCII(mime_type_string, "text/", true)) {
+ download_content = DOWNLOAD_CONTENT_TEXT;
+ } else if (StartsWithASCII(mime_type_string, "image/", true)) {
+ download_content = DOWNLOAD_CONTENT_IMAGE;
+ } else if (StartsWithASCII(mime_type_string, "audio/", true)) {
+ download_content = DOWNLOAD_CONTENT_AUDIO;
+ } else if (StartsWithASCII(mime_type_string, "video/", true)) {
+ download_content = DOWNLOAD_CONTENT_VIDEO;
+ }
+ }
+
+ // Record the value.
+ UMA_HISTOGRAM_ENUMERATION("Download.ContentType",
+ download_content,
+ DOWNLOAD_CONTENT_MAX);
+}
+
+} // namespace download_stats
diff --git a/content/browser/download/download_stats.h b/content/browser/download/download_stats.h
new file mode 100644
index 0000000..b1e7624
--- /dev/null
+++ b/content/browser/download/download_stats.h
@@ -0,0 +1,77 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// Holds helpers for gathering UMA stats about downloads.
+
+#ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_STATS_H_
+#define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_STATS_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+
+namespace base {
+class TimeTicks;
+}
+
+namespace download_stats {
+
+// We keep a count of how often various events occur in the
+// histogram "Download.Counts".
+enum DownloadCountTypes {
+ // The download was initiated by navigating to a URL (e.g. by user
+ // click).
+ INITIATED_BY_NAVIGATION_COUNT = 0,
+
+ // The download was initiated by invoking a context menu within a page.
+ INITIATED_BY_CONTEXT_MENU_COUNT,
+
+ // The download was initiated when the SavePackage system rejected
+ // a Save Page As ... by returning false from
+ // SavePackage::IsSaveableContents().
+ INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT,
+
+ // The download was initiated by a drag and drop from a drag-and-drop
+ // enabled web application.
+ INITIATED_BY_DRAG_N_DROP_COUNT,
+
+ // The download was initiated by explicit RPC from the renderer process
+ // (e.g. by Alt-click).
+ INITIATED_BY_RENDERER_COUNT,
+
+ // Downloads that made it to DownloadResourceHandler -- all of the
+ // above minus those blocked by DownloadThrottlingResourceHandler.
+ UNTHROTTLED_COUNT,
+
+ // Downloads that actually complete.
+ COMPLETED_COUNT,
+
+ // Downloads that are cancelled before completion (user action or error).
+ CANCELLED_COUNT,
+
+ // Downloads that are started. Should be equal to UNTHROTTLED_COUNT.
+ START_COUNT,
+
+ // Downloads that were interrupted by the OS.
+ INTERRUPTED_COUNT,
+
+ DOWNLOAD_COUNT_TYPES_LAST_ENTRY
+};
+
+// Increment one of the above counts.
+void RecordDownloadCount(DownloadCountTypes type);
+
+// Record COMPLETED_COUNT and how long the download took.
+void RecordDownloadCompleted(const base::TimeTicks& start);
+
+// Record INTERRUPTED_COUNT, |error|, |received| and |total| bytes.
+void RecordDownloadInterrupted(int error, int64 received, int64 total);
+
+// Records the mime type of the download.
+void RecordDownloadMimeType(const std::string& mime_type);
+
+} // namespace download_stats
+
+#endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_STATS_H_
diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc
index e4ed9a5..791dc9e 100644
--- a/content/browser/renderer_host/render_message_filter.cc
+++ b/content/browser/renderer_host/render_message_filter.cc
@@ -13,11 +13,11 @@
#include "base/threading/thread.h"
#include "base/threading/worker_pool.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/download/download_util.h"
#include "content/browser/browser_context.h"
#include "content/browser/browser_thread.h"
#include "content/browser/child_process_security_policy.h"
#include "content/browser/content_browser_client.h"
+#include "content/browser/download/download_stats.h"
#include "content/browser/download/download_types.h"
#include "content/browser/plugin_process_host.h"
#include "content/browser/plugin_service.h"
@@ -609,8 +609,8 @@ void RenderMessageFilter::OnDownloadUrl(const IPC::Message& message,
render_process_id_,
message.routing_id(),
resource_context_);
- download_util::RecordDownloadCount(
- download_util::INITIATED_BY_RENDERER_COUNT);
+ download_stats::RecordDownloadCount(
+ download_stats::INITIATED_BY_RENDERER_COUNT);
}
void RenderMessageFilter::OnCheckNotificationPermission(
diff --git a/content/browser/renderer_host/resource_dispatcher_host.cc b/content/browser/renderer_host/resource_dispatcher_host.cc
index f360590..1d8aa6c 100644
--- a/content/browser/renderer_host/resource_dispatcher_host.cc
+++ b/content/browser/renderer_host/resource_dispatcher_host.cc
@@ -18,7 +18,6 @@
#include "base/metrics/histogram.h"
#include "base/shared_memory.h"
#include "base/stl_util.h"
-#include "chrome/browser/download/download_util.h"
#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/cert_store.h"
#include "content/browser/child_process_security_policy.h"
@@ -742,11 +741,6 @@ void ResourceDispatcherHost::BeginDownload(
return;
}
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- NewRunnableFunction(&download_util::NotifyDownloadInitiated,
- child_id, route_id));
-
net::URLRequest* request = new net::URLRequest(url, this);
request_id_--;
diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc
index 5db2590..4f08d74 100644
--- a/content/browser/tab_contents/tab_contents.cc
+++ b/content/browser/tab_contents/tab_contents.cc
@@ -13,12 +13,12 @@
#include "base/string_util.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/download/download_util.h"
#include "content/browser/browser_context.h"
#include "content/browser/child_process_security_policy.h"
#include "content/browser/content_browser_client.h"
#include "content/browser/debugger/devtools_manager.h"
#include "content/browser/download/download_manager.h"
+#include "content/browser/download/download_stats.h"
#include "content/browser/host_zoom_map.h"
#include "content/browser/in_process_webkit/session_storage_namespace.h"
#include "content/browser/load_from_memory_cache_details.h"
@@ -760,8 +760,8 @@ void TabContents::OnSavePage() {
const GURL& current_page_url = GetURL();
if (dlm && current_page_url.is_valid()) {
dlm->DownloadUrl(current_page_url, GURL(), "", this);
- download_util::RecordDownloadCount(
- download_util::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
+ download_stats::RecordDownloadCount(
+ download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
return;
}
}
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index 0e0213ce..1ede1a6 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -124,6 +124,8 @@
'browser/download/download_resource_handler.h',
'browser/download/download_state_info.cc',
'browser/download/download_state_info.h',
+ 'browser/download/download_stats.cc',
+ 'browser/download/download_stats.h',
'browser/download/download_status_updater.cc',
'browser/download/download_status_updater.h',
'browser/download/download_status_updater_delegate.h',