Commit 8bd9e562 authored by jam@chromium.org's avatar jam@chromium.org

Move download UMA functions to their own file in content. Also fire the...

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
parent 8e9424b4
......@@ -5,7 +5,7 @@
#include "chrome/browser/download/download_throttling_resource_handler.h"
#include "base/logging.h"
#include "chrome/browser/download/download_util.h"
#include "content/browser/download/download_stats.h"
#include "content/browser/renderer_host/resource_dispatcher_host.h"
#include "content/common/resource_response.h"
#include "net/base/io_buffer.h"
......@@ -32,8 +32,8 @@ DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler(
tmp_buffer_length_(0),
ignore_on_read_complete_(in_complete),
request_closed_(false) {
download_util::RecordDownloadCount(
download_util::INITIATED_BY_NAVIGATION_COUNT);
download_stats::RecordDownloadCount(
download_stats::INITIATED_BY_NAVIGATION_COUNT);
// Pause the request.
host_->PauseRequest(render_process_host_id_, request_id_, true);
......@@ -45,10 +45,6 @@ DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler(
limiter->CanDownloadOnIOThread(
render_process_host_id_, render_view_id, request_id, this);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
NewRunnableFunction(&download_util::NotifyDownloadInitiated,
render_process_host_id_, render_view_id_));
}
DownloadThrottlingResourceHandler::~DownloadThrottlingResourceHandler() {
......
......@@ -15,7 +15,6 @@
#include "base/i18n/rtl.h"
#include "base/i18n/time_formatting.h"
#include "base/lazy_instance.h"
#include "base/metrics/histogram.h"
#include "base/path_service.h"
#include "base/string16.h"
#include "base/string_number_conversions.h"
......@@ -113,14 +112,6 @@ void GenerateFileNameInternal(const GURL& url,
mime_type, default_file_name);
}
// 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
};
} // namespace
// Download temporary file creation --------------------------------------------
......@@ -185,137 +176,6 @@ void GenerateFileNameFromSuggestedName(const GURL& url,
suggested_name, mime_type, generated_name);
}
void RecordDownloadCount(DownloadCountTypes type) {
UMA_HISTOGRAM_ENUMERATION(
"Download.Counts", type, DOWNLOAD_COUNT_TYPES_LAST_ENTRY);
}
void RecordDownloadCompleted(const base::TimeTicks& start) {
download_util::RecordDownloadCount(download_util::COMPLETED_COUNT);
UMA_HISTOGRAM_LONG_TIMES("Download.Time", (base::TimeTicks::Now() - start));
}
void RecordDownloadInterrupted(int error, int64 received, int64 total) {
download_util::RecordDownloadCount(download_util::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);
}
// Download progress painting --------------------------------------------------
// Common bitmaps used for download progress animations. We load them once the
......@@ -779,18 +639,6 @@ void DownloadUrl(
*context);
}
void NotifyDownloadInitiated(int render_process_id, int render_view_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
RenderViewHost* rvh = RenderViewHost::FromID(render_process_id,
render_view_id);
if (!rvh)
return;
NotificationService::current()->Notify(
chrome::NOTIFICATION_DOWNLOAD_INITIATED, Source<RenderViewHost>(rvh),
NotificationService::NoDetails());
}
int GetUniquePathNumberWithCrDownload(const FilePath& path) {
if (!file_util::PathExists(path) &&
!file_util::PathExists(GetCrDownloadPath(path)))
......
......@@ -112,60 +112,6 @@ enum PaintDownloadProgressSize {
BIG
};
// 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);
// Paint the common download animation progress foreground and background,
// clipping the foreground to 'percent' full. If percent is -1, then we don't
// know the total size, so we just draw a rotating segment until we're done.
......@@ -249,10 +195,6 @@ void DownloadUrl(const GURL& url,
int render_view_id,
const content::ResourceContext* context);
// Sends a notification on downloads being initiated
// Must be called on the UI thread.
void NotifyDownloadInitiated(int render_process_id, int render_view_id);
// Same as GetUniquePathNumber, except that it also checks the existence
// of its .crdownload intermediate path.
// If |path| does not exist, 0 is returned. If it fails to find such
......
......@@ -6,10 +6,10 @@
#include "base/file_util.h"
#include "base/message_loop.h"
#include "chrome/browser/download/download_util.h"
#include "chrome/browser/profiles/profile.h"
#include "content/browser/browser_thread.h"
#include "content/browser/download/download_item.h"
#include "content/browser/download/download_stats.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "net/base/file_stream.h"
......@@ -128,8 +128,8 @@ void DragDownloadFile::InitiateDownload() {
referrer_encoding_,
save_info,
tab_contents_);
download_util::RecordDownloadCount(
download_util::INITIATED_BY_DRAG_N_DROP_COUNT);
download_stats::RecordDownloadCount(
download_stats::INITIATED_BY_DRAG_N_DROP_COUNT);
}
void DragDownloadFile::DownloadCompleted(bool is_successful) {
......
......@@ -19,13 +19,16 @@
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/ui/autologin_infobar_delegate.h"
#include "chrome/browser/ui/login/login_prompt.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/extensions/user_script.h"
#include "chrome/common/render_messages.h"
#include "content/browser/browser_thread.h"
#include "content/browser/resource_context.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/renderer_host/resource_dispatcher_host.h"
#include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
#include "content/browser/renderer_host/resource_message_filter.h"
#include "content/common/notification_service.h"
#include "content/common/resource_messages.h"
#include "net/base/load_flags.h"
......@@ -53,6 +56,17 @@ void AddPrerenderOnUI(
referrer);
}
void NotifyDownloadInitiatedOnUI(int render_process_id, int render_view_id) {
RenderViewHost* rvh = RenderViewHost::FromID(render_process_id,
render_view_id);
if (!rvh)
return;
NotificationService::current()->Notify(
chrome::NOTIFICATION_DOWNLOAD_INITIATED, Source<RenderViewHost>(rvh),
NotificationService::NoDetails());
}
} // end namespace
ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate(
......@@ -155,6 +169,10 @@ ResourceHandler* ChromeResourceDispatcherHostDelegate::DownloadStarting(
bool is_new_request,
bool in_complete) {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
NewRunnableFunction(&NotifyDownloadInitiatedOnUI, child_id, route_id));
// If this isn't a new request, we've seen this before and added the safe
// browsing resource handler already so no need to add it again. This code
// path is only hit for requests initiated through the browser, and not the
......
......@@ -20,7 +20,6 @@
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/debugger/devtools_window.h"
#include "chrome/browser/download/download_util.h"
#include "chrome/browser/extensions/extension_event_router.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/google/google_util.h"
......@@ -51,6 +50,7 @@
#include "chrome/common/url_constants.h"
#include "content/browser/child_process_security_policy.h"
#include "content/browser/download/download_manager.h"
#include "content/browser/download/download_stats.h"
#include "content/browser/download/save_package.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/renderer_host/render_widget_host_view.h"
......@@ -1397,8 +1397,8 @@ void RenderViewContextMenu::ExecuteCommand(int id) {
case IDC_CONTENT_CONTEXT_SAVEAVAS:
case IDC_CONTENT_CONTEXT_SAVEIMAGEAS:
case IDC_CONTENT_CONTEXT_SAVELINKAS: {
download_util::RecordDownloadCount(
download_util::INITIATED_BY_CONTEXT_MENU_COUNT);
download_stats::RecordDownloadCount(
download_stats::INITIATED_BY_CONTEXT_MENU_COUNT);
const GURL& referrer =
params_.frame_url.is_empty() ? params_.page_url : params_.frame_url;
const GURL& url =
......
......@@ -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",
......
......@@ -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);
}
......
......@@ -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.
......
// 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
// 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_
......@@ -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(
......
......@@ -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_--;
......
......@@ -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;
}
}
......
......@@ -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',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment