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

Side by Side Diff: content/browser/download/download_item.cc

Issue 7664019: Move download UMA functions to their own file in content. Also fire the chrome-only notification ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' 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 #include "content/browser/download/download_item.h" 5 #include "content/browser/download/download_item.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/i18n/case_conversion.h" 10 #include "base/i18n/case_conversion.h"
(...skipping 14 matching lines...) Expand all
25 #include "chrome/browser/platform_util.h" 25 #include "chrome/browser/platform_util.h"
26 #include "chrome/browser/prefs/pref_service.h" 26 #include "chrome/browser/prefs/pref_service.h"
27 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/common/chrome_notification_types.h" 28 #include "chrome/common/chrome_notification_types.h"
29 #include "chrome/common/extensions/extension.h" 29 #include "chrome/common/extensions/extension.h"
30 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
31 #include "content/browser/browser_thread.h" 31 #include "content/browser/browser_thread.h"
32 #include "content/browser/download/download_create_info.h" 32 #include "content/browser/download/download_create_info.h"
33 #include "content/browser/download/download_file_manager.h" 33 #include "content/browser/download/download_file_manager.h"
34 #include "content/browser/download/download_manager.h" 34 #include "content/browser/download/download_manager.h"
35 #include "content/browser/download/download_stats.h"
35 #include "content/common/notification_source.h" 36 #include "content/common/notification_source.h"
36 37
37 // A DownloadItem normally goes through the following states: 38 // A DownloadItem normally goes through the following states:
38 // * Created (when download starts) 39 // * Created (when download starts)
39 // * Made visible to consumers (e.g. Javascript) after the 40 // * Made visible to consumers (e.g. Javascript) after the
40 // destination file has been determined. 41 // destination file has been determined.
41 // * Entered into the history database. 42 // * Entered into the history database.
42 // * Made visible in the download shelf. 43 // * Made visible in the download shelf.
43 // * All data is saved. Note that the actual data download occurs 44 // * All data is saved. Note that the actual data download occurs
44 // in parallel with the above steps, but until those steps are 45 // in parallel with the above steps, but until those steps are
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 381 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
381 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 382 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
382 383
383 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); 384 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true);
384 if (!IsPartialDownload()) { 385 if (!IsPartialDownload()) {
385 // Small downloads might be complete before this method has 386 // Small downloads might be complete before this method has
386 // a chance to run. 387 // a chance to run.
387 return; 388 return;
388 } 389 }
389 390
390 download_util::RecordDownloadCount(download_util::CANCELLED_COUNT); 391 download_stats::RecordDownloadCount(download_stats::CANCELLED_COUNT);
391 392
392 TransitionTo(CANCELLED); 393 TransitionTo(CANCELLED);
393 StopProgressTimer(); 394 StopProgressTimer();
394 if (update_history) 395 if (update_history)
395 download_manager_->DownloadCancelled(download_id_); 396 download_manager_->DownloadCancelled(download_id_);
396 } 397 }
397 398
398 void DownloadItem::MarkAsComplete() { 399 void DownloadItem::MarkAsComplete() {
399 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 400 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
400 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 401 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 19 matching lines...) Expand all
420 421
421 void DownloadItem::Completed() { 422 void DownloadItem::Completed() {
422 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 423 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
423 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 424 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
424 425
425 VLOG(20) << __FUNCTION__ << "() " << DebugString(false); 426 VLOG(20) << __FUNCTION__ << "() " << DebugString(false);
426 427
427 DCHECK(all_data_saved_); 428 DCHECK(all_data_saved_);
428 TransitionTo(COMPLETE); 429 TransitionTo(COMPLETE);
429 download_manager_->DownloadCompleted(id()); 430 download_manager_->DownloadCompleted(id());
430 download_util::RecordDownloadCompleted(start_tick_); 431 download_stats::RecordDownloadCompleted(start_tick_);
431 432
432 if (is_extension_install()) { 433 if (is_extension_install()) {
433 // Extensions should already have been unpacked and opened. 434 // Extensions should already have been unpacked and opened.
434 DCHECK(auto_opened_); 435 DCHECK(auto_opened_);
435 } else if (open_when_complete() || 436 } else if (open_when_complete() ||
436 ShouldOpenFileBasedOnExtension() || 437 ShouldOpenFileBasedOnExtension() ||
437 is_temporary()) { 438 is_temporary()) {
438 // If the download is temporary, like in drag-and-drop, do not open it but 439 // If the download is temporary, like in drag-and-drop, do not open it but
439 // we still need to set it auto-opened so that it can be removed from the 440 // we still need to set it auto-opened so that it can be removed from the
440 // download shelf. 441 // download shelf.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 void DownloadItem::Interrupted(int64 size, int os_error) { 521 void DownloadItem::Interrupted(int64 size, int os_error) {
521 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 522 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
522 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 523 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
523 524
524 if (!IsInProgress()) 525 if (!IsInProgress())
525 return; 526 return;
526 527
527 last_os_error_ = os_error; 528 last_os_error_ = os_error;
528 UpdateSize(size); 529 UpdateSize(size);
529 StopProgressTimer(); 530 StopProgressTimer();
530 download_util::RecordDownloadInterrupted(os_error, 531 download_stats::RecordDownloadInterrupted(os_error,
531 received_bytes_, 532 received_bytes_,
532 total_bytes_); 533 total_bytes_);
533 TransitionTo(INTERRUPTED); 534 TransitionTo(INTERRUPTED);
534 } 535 }
535 536
536 void DownloadItem::Delete(DeleteReason reason) { 537 void DownloadItem::Delete(DeleteReason reason) {
537 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 538 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
538 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 539 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
539 540
540 switch (reason) { 541 switch (reason) {
541 case DELETE_DUE_TO_USER_DISCARD: 542 case DELETE_DUE_TO_USER_DISCARD:
542 UMA_HISTOGRAM_ENUMERATION("Download.UserDiscard", GetDangerType(), 543 UMA_HISTOGRAM_ENUMERATION("Download.UserDiscard", GetDangerType(),
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 GetTargetFilePath() : full_path_; 773 GetTargetFilePath() : full_path_;
773 } 774 }
774 775
775 void DownloadItem::Init(bool active) { 776 void DownloadItem::Init(bool active) {
776 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 777 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
777 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 778 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
778 779
779 UpdateTarget(); 780 UpdateTarget();
780 if (active) { 781 if (active) {
781 StartProgressTimer(); 782 StartProgressTimer();
782 download_util::RecordDownloadCount(download_util::START_COUNT); 783 download_stats::RecordDownloadCount(download_stats::START_COUNT);
783 } 784 }
784 VLOG(20) << __FUNCTION__ << "() " << DebugString(true); 785 VLOG(20) << __FUNCTION__ << "() " << DebugString(true);
785 } 786 }
786 787
787 // TODO(ahendrickson) -- Move |INTERRUPTED| from |IsCancelled()| to 788 // TODO(ahendrickson) -- Move |INTERRUPTED| from |IsCancelled()| to
788 // |IsPartialDownload()|, when resuming interrupted downloads is implemented. 789 // |IsPartialDownload()|, when resuming interrupted downloads is implemented.
789 bool DownloadItem::IsPartialDownload() const { 790 bool DownloadItem::IsPartialDownload() const {
790 return (state_ == IN_PROGRESS); 791 return (state_ == IN_PROGRESS);
791 } 792 }
792 793
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 state_info_.target_name.value().c_str(), 857 state_info_.target_name.value().c_str(),
857 full_path().value().c_str()); 858 full_path().value().c_str());
858 } else { 859 } else {
859 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); 860 description += base::StringPrintf(" url = \"%s\"", url_list.c_str());
860 } 861 }
861 862
862 description += " }"; 863 description += " }";
863 864
864 return description; 865 return description;
865 } 866 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698