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

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

Issue 8008021: Add new UMA stats to get a handle on Downloads UI Usage (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: comments Created 9 years, 2 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_manager.h" 5 #include "content/browser/download/download_manager.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/i18n/case_conversion.h" 12 #include "base/i18n/case_conversion.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
16 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
17 #include "base/sys_string_conversions.h" 17 #include "base/sys_string_conversions.h"
18 #include "base/task.h" 18 #include "base/task.h"
19 #include "build/build_config.h" 19 #include "build/build_config.h"
20 #include "content/browser/browser_context.h" 20 #include "content/browser/browser_context.h"
21 #include "content/browser/browser_thread.h" 21 #include "content/browser/browser_thread.h"
22 #include "content/browser/content_browser_client.h" 22 #include "content/browser/content_browser_client.h"
23 #include "content/browser/download/download_create_info.h" 23 #include "content/browser/download/download_create_info.h"
24 #include "content/browser/download/download_file_manager.h" 24 #include "content/browser/download/download_file_manager.h"
25 #include "content/browser/download/download_item.h" 25 #include "content/browser/download/download_item.h"
26 #include "content/browser/download/download_manager_delegate.h" 26 #include "content/browser/download/download_manager_delegate.h"
27 #include "content/browser/download/download_persistent_store_info.h" 27 #include "content/browser/download/download_persistent_store_info.h"
28 #include "content/browser/download/download_stats.h"
28 #include "content/browser/download/download_status_updater.h" 29 #include "content/browser/download/download_status_updater.h"
29 #include "content/browser/renderer_host/render_process_host.h" 30 #include "content/browser/renderer_host/render_process_host.h"
30 #include "content/browser/renderer_host/render_view_host.h" 31 #include "content/browser/renderer_host/render_view_host.h"
31 #include "content/browser/renderer_host/resource_dispatcher_host.h" 32 #include "content/browser/renderer_host/resource_dispatcher_host.h"
32 #include "content/browser/tab_contents/tab_contents.h" 33 #include "content/browser/tab_contents/tab_contents.h"
33 #include "content/common/content_notification_types.h" 34 #include "content/common/content_notification_types.h"
34 #include "content/common/notification_service.h" 35 #include "content/common/notification_service.h"
35 36
36 namespace { 37 namespace {
37 38
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 } 676 }
676 } 677 }
677 return RemoveDownloadItems(pending_deletes); 678 return RemoveDownloadItems(pending_deletes);
678 } 679 }
679 680
680 int DownloadManager::RemoveDownloads(const base::Time remove_begin) { 681 int DownloadManager::RemoveDownloads(const base::Time remove_begin) {
681 return RemoveDownloadsBetween(remove_begin, base::Time()); 682 return RemoveDownloadsBetween(remove_begin, base::Time());
682 } 683 }
683 684
684 int DownloadManager::RemoveAllDownloads() { 685 int DownloadManager::RemoveAllDownloads() {
686 download_stats::RecordClearAllSize(history_downloads_.size());
685 // The null times make the date range unbounded. 687 // The null times make the date range unbounded.
686 return RemoveDownloadsBetween(base::Time(), base::Time()); 688 return RemoveDownloadsBetween(base::Time(), base::Time());
687 } 689 }
688 690
689 // Initiate a download of a specific URL. We send the request to the 691 // Initiate a download of a specific URL. We send the request to the
690 // ResourceDispatcherHost, and let it send us responses like a regular 692 // ResourceDispatcherHost, and let it send us responses like a regular
691 // download. 693 // download.
692 void DownloadManager::DownloadUrl(const GURL& url, 694 void DownloadManager::DownloadUrl(const GURL& url,
693 const GURL& referrer, 695 const GURL& referrer,
694 const std::string& referrer_charset, 696 const std::string& referrer_charset,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 // Operations posted to us from the history service ---------------------------- 812 // Operations posted to us from the history service ----------------------------
811 813
812 // The history service has retrieved all download entries. 'entries' contains 814 // The history service has retrieved all download entries. 'entries' contains
813 // 'DownloadPersistentStoreInfo's in sorted order (by ascending start_time). 815 // 'DownloadPersistentStoreInfo's in sorted order (by ascending start_time).
814 void DownloadManager::OnPersistentStoreQueryComplete( 816 void DownloadManager::OnPersistentStoreQueryComplete(
815 std::vector<DownloadPersistentStoreInfo>* entries) { 817 std::vector<DownloadPersistentStoreInfo>* entries) {
816 // TODO(rdsmith): Remove this and related logic when 818 // TODO(rdsmith): Remove this and related logic when
817 // http://crbug.com/84508 is fixed. 819 // http://crbug.com/84508 is fixed.
818 largest_db_handle_in_history_ = 0; 820 largest_db_handle_in_history_ = 0;
819 821
822 download_stats::RecordHistorySize(entries->size());
823
820 for (size_t i = 0; i < entries->size(); ++i) { 824 for (size_t i = 0; i < entries->size(); ++i) {
821 DownloadItem* download = new DownloadItem(this, entries->at(i)); 825 DownloadItem* download = new DownloadItem(this, entries->at(i));
822 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. 826 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved.
823 CHECK(!ContainsKey(history_downloads_, download->db_handle())); 827 CHECK(!ContainsKey(history_downloads_, download->db_handle()));
824 downloads_.insert(download); 828 downloads_.insert(download);
825 history_downloads_[download->db_handle()] = download; 829 history_downloads_[download->db_handle()] = download;
826 VLOG(20) << __FUNCTION__ << "()" << i << ">" 830 VLOG(20) << __FUNCTION__ << "()" << i << ">"
827 << " download = " << download->DebugString(true); 831 << " download = " << download->DebugString(true);
828 832
829 if (download->db_handle() > largest_db_handle_in_history_) 833 if (download->db_handle() > largest_db_handle_in_history_)
830 largest_db_handle_in_history_ = download->db_handle(); 834 largest_db_handle_in_history_ = download->db_handle();
831 } 835 }
832 NotifyModelChanged(); 836 NotifyModelChanged();
833 CheckForHistoryFilesRemoval(); 837 CheckForHistoryFilesRemoval();
834 } 838 }
835 839
836 void DownloadManager::AddDownloadItemToHistory(DownloadItem* download, 840 void DownloadManager::AddDownloadItemToHistory(DownloadItem* download,
837 int64 db_handle) { 841 int64 db_handle) {
838 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 842 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
839 843
840 // TODO(rdsmith): Convert to DCHECK() when http://crbug.com/84508 844 // TODO(rdsmith): Convert to DCHECK() when http://crbug.com/84508
841 // is fixed. 845 // is fixed.
842 CHECK_NE(DownloadItem::kUninitializedHandle, db_handle); 846 CHECK_NE(DownloadItem::kUninitializedHandle, db_handle);
843 847
848 download_stats::RecordHistorySize2(history_downloads_.size());
849
844 DCHECK(download->db_handle() == DownloadItem::kUninitializedHandle); 850 DCHECK(download->db_handle() == DownloadItem::kUninitializedHandle);
845 download->set_db_handle(db_handle); 851 download->set_db_handle(db_handle);
846 852
847 // TODO(rdsmith): Convert to DCHECK() when http://crbug.com/84508 853 // TODO(rdsmith): Convert to DCHECK() when http://crbug.com/84508
848 // is fixed. 854 // is fixed.
849 CHECK(!ContainsKey(history_downloads_, download->db_handle())); 855 CHECK(!ContainsKey(history_downloads_, download->db_handle()));
850 history_downloads_[download->db_handle()] = download; 856 history_downloads_[download->db_handle()] = download;
851 857
852 // Show in the appropriate browser UI. 858 // Show in the appropriate browser UI.
853 // This includes buttons to save or cancel, for a dangerous download. 859 // This includes buttons to save or cancel, for a dangerous download.
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 DCHECK(ContainsKey(save_page_downloads_, download->id())); 1067 DCHECK(ContainsKey(save_page_downloads_, download->id()));
1062 save_page_downloads_.erase(download->id()); 1068 save_page_downloads_.erase(download->id());
1063 1069
1064 if (download->IsComplete()) 1070 if (download->IsComplete())
1065 NotificationService::current()->Notify( 1071 NotificationService::current()->Notify(
1066 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, 1072 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
1067 Source<DownloadManager>(this), 1073 Source<DownloadManager>(this),
1068 Details<DownloadItem>(download)); 1074 Details<DownloadItem>(download));
1069 } 1075 }
1070 } 1076 }
1077
1078 void DownloadManager::MarkDownloadOpened(DownloadItem* download) {
1079 delegate_->UpdateItemInPersistentStore(download);
1080 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698