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

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: More mime types 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 {
398 DOWNLOAD_CONTENT_UNRECOGNIZED = 0,
399 DOWNLOAD_CONTENT_TEXT = 1,
400 DOWNLOAD_CONTENT_IMAGE = 2,
401 DOWNLOAD_CONTENT_AUDIO = 3,
402 DOWNLOAD_CONTENT_VIDEO = 4,
403 DOWNLOAD_CONTENT_OCTET_STREAM = 5,
404 DOWNLOAD_CONTENT_PDF = 6,
405 DOWNLOAD_CONTENT_DOC = 7,
406 DOWNLOAD_CONTENT_XLS = 8,
407 DOWNLOAD_CONTENT_PPT = 9,
408 DOWNLOAD_CONTENT_ARCHIVE = 10,
409 DOWNLOAD_CONTENT_EXE = 11,
410 DOWNLOAD_CONTENT_DMG = 12,
411 DOWNLOAD_CONTENT_CRX = 13,
412 DOWNLOAD_CONTENT_MAX = 14,
413 };
414
415 struct MimeTypeToDownloadContent {
416 const char* mime_type;
417 DownloadContent download_content;
418 };
419
420 static MimeTypeToDownloadContent kMapMimeTypeToDownloadContent[] = {
421 {"application/octet-stream", DOWNLOAD_CONTENT_OCTET_STREAM},
422 {"binary/octet-stream", DOWNLOAD_CONTENT_OCTET_STREAM},
423 {"application/pdf", DOWNLOAD_CONTENT_PDF},
424 {"application/msword", DOWNLOAD_CONTENT_DOC},
425 {"application/vnd.ms-excel", DOWNLOAD_CONTENT_XLS},
426 {"application/vns.ms-powerpoint", DOWNLOAD_CONTENT_PPT},
427 {"application/zip", DOWNLOAD_CONTENT_ARCHIVE},
428 {"application/x-gzip", DOWNLOAD_CONTENT_ARCHIVE},
429 {"application/x-rar-compressed", DOWNLOAD_CONTENT_ARCHIVE},
430 {"application/x-tar", DOWNLOAD_CONTENT_ARCHIVE},
431 {"application/x-bzip", DOWNLOAD_CONTENT_ARCHIVE},
432 {"application/x-exe", DOWNLOAD_CONTENT_EXE},
433 {"application/x-apple-diskimage", DOWNLOAD_CONTENT_DMG},
434 {"application/x-chrome-extension", DOWNLOAD_CONTENT_CRX},
435 };
436
437 } // namespace
438
439 void RecordDownloadMimeType(const std::string& mime_type_string) {
440 DownloadContent download_content = DOWNLOAD_CONTENT_UNRECOGNIZED;
441
442 // Look up exact matches.
443 for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadContent); ++i) {
444 const MimeTypeToDownloadContent& entry =
445 kMapMimeTypeToDownloadContent[i];
446 if (mime_type_string == entry.mime_type) {
447 download_content = entry.download_content;
448 break;
449 }
450 }
451
452 // Do partial matches.
453 if (download_content == DOWNLOAD_CONTENT_UNRECOGNIZED) {
454 if (StartsWithASCII(mime_type_string, "text/", true)) {
455 download_content = DOWNLOAD_CONTENT_TEXT;
456 } else if (StartsWithASCII(mime_type_string, "image/", true)) {
457 download_content = DOWNLOAD_CONTENT_IMAGE;
458 } else if (StartsWithASCII(mime_type_string, "audio/", true)) {
459 download_content = DOWNLOAD_CONTENT_AUDIO;
460 } else if (StartsWithASCII(mime_type_string, "video/", true)) {
461 download_content = DOWNLOAD_CONTENT_VIDEO;
462 }
463 }
464
465 // Record the value.
466 UMA_HISTOGRAM_ENUMERATION("Download.ContentType",
467 download_content,
468 DOWNLOAD_CONTENT_MAX);
469 }
470
395 // Download progress painting -------------------------------------------------- 471 // Download progress painting --------------------------------------------------
396 472
397 // Common bitmaps used for download progress animations. We load them once the 473 // 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 474 // first time we do a progress paint, then reuse them as they are always the
399 // same. 475 // same.
400 SkBitmap* g_foreground_16 = NULL; 476 SkBitmap* g_foreground_16 = NULL;
401 SkBitmap* g_background_16 = NULL; 477 SkBitmap* g_background_16 = NULL;
402 SkBitmap* g_foreground_32 = NULL; 478 SkBitmap* g_foreground_32 = NULL;
403 SkBitmap* g_background_32 = NULL; 479 SkBitmap* g_background_32 = NULL;
404 480
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 FilePath GetCrDownloadPath(const FilePath& suggested_path) { 985 FilePath GetCrDownloadPath(const FilePath& suggested_path) {
910 FilePath::StringType file_name; 986 FilePath::StringType file_name;
911 base::SStringPrintf( 987 base::SStringPrintf(
912 &file_name, 988 &file_name,
913 PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"), 989 PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"),
914 suggested_path.value().c_str()); 990 suggested_path.value().c_str());
915 return FilePath(file_name); 991 return FilePath(file_name);
916 } 992 }
917 993
918 } // namespace download_util 994 } // 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