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

Side by Side Diff: chrome/browser/download/download_util.cc

Issue 7538007: Record type of content being downloaded. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Works Created 9 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Download utility implementation 5 // Download utility implementation
6 6
7 #include "chrome/browser/download/download_util.h" 7 #include "chrome/browser/download/download_util.h"
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <shobjidl.h> 10 #include <shobjidl.h>
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 -delta_bytes, 385 -delta_bytes,
386 1, 386 1,
387 kMaxKb, 387 kMaxKb,
388 kBuckets); 388 kBuckets);
389 } 389 }
390 } 390 }
391 391
392 UMA_HISTOGRAM_BOOLEAN("Download.InterruptedUnknownSize", unknown_size); 392 UMA_HISTOGRAM_BOOLEAN("Download.InterruptedUnknownSize", unknown_size);
393 } 393 }
394 394
395 namespace {
396
397 enum DownloadContent {
benjhayden 2011/08/01 18:53:03 Do all compilers number enums from 0 counting upwa
cbentzel 2011/08/01 19:00:33 Not guaranteed - thanks for the catch.
398 DOWNLOAD_CONTENT_TEXT,
399 DOWNLOAD_CONTENT_IMAGE,
400 DOWNLOAD_CONTENT_AUDIO,
401 DOWNLOAD_CONTENT_VIDEO,
402 DOWNLOAD_CONTENT_OCTET_STREAM,
403 DOWNLOAD_CONTENT_PDF,
404 DOWNLOAD_CONTENT_DOC,
405 DOWNLOAD_CONTENT_XLS,
406 DOWNLOAD_CONTENT_PPT,
407 DOWNLOAD_CONTENT_ARCHIVE,
408 DOWNLOAD_CONTENT_UNRECOGNIZED,
409 DOWNLOAD_CONTENT_MAX,
410 };
411
412 struct MimeTypeToDownloadContent {
413 const char* mime_type;
414 DownloadContent download_content;
415 };
416
417 static MimeTypeToDownloadContent kMapMimeTypeToDownloadContent[] = {
benjhayden 2011/08/01 18:53:03 Could you add exe, dmg, crx, and bzip? exe: appli
cbentzel 2011/08/01 19:00:33 Will do. Hoping I don't need to move to binary sea
cbentzel 2011/08/01 21:06:18 Do you know how frequently these happen? I mostly
benjhayden 2011/08/01 21:48:12 No idea. I just copied it from some website. Don't
418 {"application/octet-stream", DOWNLOAD_CONTENT_OCTET_STREAM},
419 {"binary/octet-stream", DOWNLOAD_CONTENT_OCTET_STREAM},
420 {"application/pdf", DOWNLOAD_CONTENT_PDF},
421 {"application/msword", DOWNLOAD_CONTENT_DOC},
422 {"application/vnd.ms-excel", DOWNLOAD_CONTENT_XLS},
423 {"application/vns.ms-powerpoint", DOWNLOAD_CONTENT_PPT},
424 {"application/zip", DOWNLOAD_CONTENT_ARCHIVE},
425 {"application/x-gzip", DOWNLOAD_CONTENT_ARCHIVE},
426 {"application/x-rar-compressed", DOWNLOAD_CONTENT_ARCHIVE},
427 {"application/x-tar", DOWNLOAD_CONTENT_ARCHIVE},
428 };
429
430 } // namespace
431
432 void RecordDownloadMimeType(const std::string& mime_type_string) {
433 DownloadContent download_content = DOWNLOAD_CONTENT_UNRECOGNIZED;
434
435 // Look up exact matches.
436 for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadContent); ++i) {
437 const MimeTypeToDownloadContent& entry =
438 kMapMimeTypeToDownloadContent[i];
439 if (mime_type_string == entry.mime_type) {
440 download_content = entry.download_content;
441 break;
442 }
443 }
444
445 // Do partial matches.
446 if (download_content == DOWNLOAD_CONTENT_UNRECOGNIZED) {
447 if (StartsWithASCII(mime_type_string, "text/", true)) {
448 download_content = DOWNLOAD_CONTENT_TEXT;
449 } else if (StartsWithASCII(mime_type_string, "image/", true)) {
450 download_content = DOWNLOAD_CONTENT_IMAGE;
451 } else if (StartsWithASCII(mime_type_string, "audio/", true)) {
452 download_content = DOWNLOAD_CONTENT_AUDIO;
453 } else if (StartsWithASCII(mime_type_string, "video/", true)) {
454 download_content = DOWNLOAD_CONTENT_VIDEO;
455 }
456 }
457
458 // Record the value.
459 UMA_HISTOGRAM_ENUMERATION("Download.ContentType",
460 download_content,
461 DOWNLOAD_CONTENT_MAX);
462 }
463
395 // Download progress painting -------------------------------------------------- 464 // Download progress painting --------------------------------------------------
396 465
397 // Common bitmaps used for download progress animations. We load them once the 466 // Common bitmaps used for download progress animations. We load them once the
398 // first time we do a progress paint, then reuse them as they are always the 467 // first time we do a progress paint, then reuse them as they are always the
399 // same. 468 // same.
400 SkBitmap* g_foreground_16 = NULL; 469 SkBitmap* g_foreground_16 = NULL;
401 SkBitmap* g_background_16 = NULL; 470 SkBitmap* g_background_16 = NULL;
402 SkBitmap* g_foreground_32 = NULL; 471 SkBitmap* g_foreground_32 = NULL;
403 SkBitmap* g_background_32 = NULL; 472 SkBitmap* g_background_32 = NULL;
404 473
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 FilePath GetCrDownloadPath(const FilePath& suggested_path) { 978 FilePath GetCrDownloadPath(const FilePath& suggested_path) {
910 FilePath::StringType file_name; 979 FilePath::StringType file_name;
911 base::SStringPrintf( 980 base::SStringPrintf(
912 &file_name, 981 &file_name,
913 PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"), 982 PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"),
914 suggested_path.value().c_str()); 983 suggested_path.value().c_str());
915 return FilePath(file_name); 984 return FilePath(file_name);
916 } 985 }
917 986
918 } // namespace download_util 987 } // namespace download_util
OLDNEW
« no previous file with comments | « chrome/browser/download/download_util.h ('k') | chrome/browser/renderer_host/download_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698