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

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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 } 836 }
835 837
836 void DownloadManager::AddDownloadItemToHistory(DownloadItem* download, 838 void DownloadManager::AddDownloadItemToHistory(DownloadItem* download,
837 int64 db_handle) { 839 int64 db_handle) {
838 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 840 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
839 841
840 // TODO(rdsmith): Convert to DCHECK() when http://crbug.com/84508 842 // TODO(rdsmith): Convert to DCHECK() when http://crbug.com/84508
841 // is fixed. 843 // is fixed.
842 CHECK_NE(DownloadItem::kUninitializedHandle, db_handle); 844 CHECK_NE(DownloadItem::kUninitializedHandle, db_handle);
843 845
846 download_stats::RecordHistorySize(history_downloads_.size());
847
844 DCHECK(download->db_handle() == DownloadItem::kUninitializedHandle); 848 DCHECK(download->db_handle() == DownloadItem::kUninitializedHandle);
845 download->set_db_handle(db_handle); 849 download->set_db_handle(db_handle);
846 850
847 // TODO(rdsmith): Convert to DCHECK() when http://crbug.com/84508 851 // TODO(rdsmith): Convert to DCHECK() when http://crbug.com/84508
848 // is fixed. 852 // is fixed.
849 CHECK(!ContainsKey(history_downloads_, download->db_handle())); 853 CHECK(!ContainsKey(history_downloads_, download->db_handle()));
850 history_downloads_[download->db_handle()] = download; 854 history_downloads_[download->db_handle()] = download;
851 855
852 // Show in the appropriate browser UI. 856 // Show in the appropriate browser UI.
853 // This includes buttons to save or cancel, for a dangerous download. 857 // 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())); 1065 DCHECK(ContainsKey(save_page_downloads_, download->id()));
1062 save_page_downloads_.erase(download->id()); 1066 save_page_downloads_.erase(download->id());
1063 1067
1064 if (download->IsComplete()) 1068 if (download->IsComplete())
1065 NotificationService::current()->Notify( 1069 NotificationService::current()->Notify(
1066 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, 1070 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
1067 Source<DownloadManager>(this), 1071 Source<DownloadManager>(this),
1068 Details<DownloadItem>(download)); 1072 Details<DownloadItem>(download));
1069 } 1073 }
1070 } 1074 }
1075
1076 void DownloadManager::MarkDownloadOpened(DownloadItem* download) {
1077 delegate_->UpdateItemInPersistentStore(download);
1078 int num_unopened = 0;
1079 for (DownloadMap::iterator it = history_downloads_.begin();
1080 it != history_downloads_.end(); ++it) {
1081 if (it->second->IsComplete() && !it->second->opened())
1082 ++num_unopened;
1083 }
1084 download_stats::RecordOpensOutstanding(num_unopened);
1085 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698