diff options
| author | rdsmith@chromium.org <rdsmith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-10 22:10:34 +0000 |
|---|---|---|
| committer | rdsmith@chromium.org <rdsmith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-10 22:10:34 +0000 |
| commit | 798daa9328e12a331ba321ec7d96ba94cfe7dba3 (patch) | |
| tree | af46263423dd7f86dd55fe8154b9090ca0622f60 | |
| parent | f52676fe88cadbfe3be9ba3d83d020fdf89c3e85 (diff) | |
| download | chromium_src-798daa9328e12a331ba321ec7d96ba94cfe7dba3.zip chromium_src-798daa9328e12a331ba321ec7d96ba94cfe7dba3.tar.gz chromium_src-798daa9328e12a331ba321ec7d96ba94cfe7dba3.tar.bz2 | |
Revert 84866 - Merge 84648 - Fix failure to update history to reflect new COMPLETE state meaning.
BUG=81014
TEST=New DownloadHistoryCheck test.
Review URL: http://codereview.chromium.org/6911036
TBR=rdsmith@chromium.org
Review URL: http://codereview.chromium.org/7004009
TBR=rdsmith@chromium.org
Review URL: http://codereview.chromium.org/7003012
git-svn-id: svn://svn.chromium.org/chrome/branches/742/src@84874 0039d316-1c4b-4281-b951-d872f2087c98
| -rw-r--r-- | chrome/browser/download/download_browsertest.cc | 118 | ||||
| -rw-r--r-- | chrome/browser/download/download_item.cc | 13 | ||||
| -rw-r--r-- | chrome/browser/download/download_manager.cc | 6 | ||||
| -rw-r--r-- | chrome/browser/download/download_manager.h | 5 |
4 files changed, 20 insertions, 122 deletions
diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc index 8030eb1..55a9e6e 100644 --- a/chrome/browser/download/download_browsertest.cc +++ b/chrome/browser/download/download_browsertest.cc @@ -15,8 +15,6 @@ #include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/download_prefs.h" #include "chrome/browser/download/download_shelf.h" -#include "chrome/browser/history/download_create_info.h" -#include "chrome/browser/history/history.h" #include "chrome/browser/net/url_request_mock_http_job.h" #include "chrome/browser/net/url_request_slow_download_job.h" #include "chrome/browser/prefs/pref_service.h" @@ -29,7 +27,6 @@ #include "chrome/common/url_constants.h" #include "chrome/test/in_process_browser_test.h" #include "chrome/test/ui_test_utils.h" -#include "content/browser/cancelable_request.h" #include "content/browser/renderer_host/resource_dispatcher_host.h" #include "content/common/page_transition_types.h" #include "net/base/net_util.h" @@ -262,7 +259,7 @@ class DownloadsFlushObserver virtual ~DownloadsFlushObserver() { download_manager_->RemoveObserver(this); for (std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); - it != downloads_observed_.end(); ++it) { + it != downloads_observed_.end(); it++) { (*it)->RemoveObserver(this); } } @@ -297,7 +294,7 @@ class DownloadsFlushObserver // of DownloadManager so that we don't have to independently track // whether we are observing it for conditional destruction. for (std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); - it != downloads_observed_.end(); ++it) { + it != downloads_observed_.end(); it++) { (*it)->RemoveObserver(this); } downloads_observed_.clear(); @@ -434,16 +431,6 @@ class DownloadTest : public InProcessBrowserTest { SIZE_TEST_TYPE_UNKNOWN, }; - // Location of the file source (the place from which it is downloaded). - FilePath OriginFile(FilePath file) { - return test_dir_.Append(file); - } - - // Location of the file destination (place to which it is downloaded). - FilePath DestinationFile(Browser* browser, FilePath file) { - return GetDownloadDirectory(browser).Append(file); - } - // Must be called after browser creation. Creates a temporary // directory for downloads that is auto-deleted on destruction. // Returning false indicates a failure of the function, and should be asserted @@ -543,10 +530,11 @@ class DownloadTest : public InProcessBrowserTest { const FilePath& downloaded_filename, const FilePath& origin_filename) { // Find the path to which the data will be downloaded. - FilePath downloaded_file(DestinationFile(browser, downloaded_filename)); + FilePath downloaded_file = + GetDownloadDirectory(browser).Append(downloaded_filename); // Find the origin path (from which the data comes). - FilePath origin_file(OriginFile(origin_filename)); + FilePath origin_file(test_dir_.Append(origin_filename)); bool origin_file_exists = file_util::PathExists(origin_file); EXPECT_TRUE(origin_file_exists); if (!origin_file_exists) @@ -643,12 +631,6 @@ class DownloadTest : public InProcessBrowserTest { return true; } - void GetDownloads(Browser* browser, std::vector<DownloadItem*>* downloads) { - DCHECK(downloads); - DownloadManager* manager = browser->profile()->GetDownloadManager(); - manager->SearchDownloads(string16(), downloads); - } - // Figure out if the appropriate download visibility was done. A // utility function to support ChromeOS variations. On ChromeOS // a webui panel is used instead of the download shelf; the @@ -684,55 +666,6 @@ class DownloadTest : public InProcessBrowserTest { ScopedTempDir downloads_directory_; }; -// Get History Information. -class DownloadsHistoryDataCollector { - public: - explicit DownloadsHistoryDataCollector(int64 download_db_handle, - DownloadManager* manager) - : result_valid_(false), - download_db_handle_(download_db_handle) { - HistoryService* hs = - manager->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); - DCHECK(hs); - hs->QueryDownloads( - &callback_consumer_, - NewCallback(this, - &DownloadsHistoryDataCollector::OnQueryDownloadsComplete)); - - // Cannot complete immediately because the history backend runs on a - // separate thread, so we can assume that the RunMessageLoop below will - // be exited by the Quit in OnQueryDownloadsComplete. - ui_test_utils::RunMessageLoop(); - } - - bool GetDownloadsHistoryEntry(DownloadCreateInfo* result) { - DCHECK(result); - *result = result_; - return result_valid_; - } - - private: - void OnQueryDownloadsComplete( - std::vector<DownloadCreateInfo>* entries) { - result_valid_ = false; - for (std::vector<DownloadCreateInfo>::const_iterator it = entries->begin(); - it != entries->end(); ++it) { - if (it->db_handle == download_db_handle_) { - result_ = *it; - result_valid_ = true; - } - } - MessageLoopForUI::current()->Quit(); - } - - DownloadCreateInfo result_; - bool result_valid_; - int64 download_db_handle_; - CancelableRequestConsumer callback_consumer_; - - DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector); -}; - // NOTES: // // Files for these tests are found in DIR_TEST_DATA (currently @@ -768,7 +701,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { // Check state. Special file state must be checked before CheckDownload, // as CheckDownload will delete the output file. EXPECT_EQ(1, browser()->tab_count()); - FilePath downloaded_file(DestinationFile(browser(), file)); + FilePath downloaded_file = GetDownloadDirectory(browser()).Append(file); if (file_util::VolumeSupportsADS(downloaded_file)) EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); CheckDownload(browser(), file, file); @@ -805,7 +738,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { ASSERT_TRUE(InitialSetup(false)); FilePath file(FILE_PATH_LITERAL("download-test2.html")); GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); - FilePath file_path(DestinationFile(browser(), file)); + FilePath file_path = GetDownloadDirectory(browser()).Append(file); // Open a web page and wait. ui_test_utils::NavigateToURL(browser(), url); @@ -1261,40 +1194,3 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { EXPECT_FALSE(IsDownloadUIVisible(browser())); #endif } - -// Confirm a download makes it into the history properly. -IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { - ASSERT_TRUE(InitialSetup(false)); - FilePath file(FILE_PATH_LITERAL("download-test1.lib")); - GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); - FilePath origin_file(OriginFile(file)); - int64 origin_size; - file_util::GetFileSize(origin_file, &origin_size); - - // Download the file and wait. We do not expect the Select File dialog. - DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); - - // Get details of what downloads have just happened. - std::vector<DownloadItem*> downloads; - GetDownloads(browser(), &downloads); - ASSERT_EQ(1u, downloads.size()); - int64 db_handle = downloads[0]->db_handle(); - - // Check state. - EXPECT_EQ(1, browser()->tab_count()); - CheckDownload(browser(), file, file); - EXPECT_TRUE(IsDownloadUIVisible(browser())); - - // Check history results. - DownloadsHistoryDataCollector history_collector( - db_handle, - browser()->profile()->GetDownloadManager()); - DownloadCreateInfo info; - EXPECT_TRUE(history_collector.GetDownloadsHistoryEntry(&info)) << db_handle; - EXPECT_EQ(file, info.path.BaseName()); - EXPECT_EQ(url, info.url()); - // Ignore start_time. - EXPECT_EQ(origin_size, info.received_bytes); - EXPECT_EQ(origin_size, info.total_bytes); - EXPECT_EQ(DownloadItem::COMPLETE, info.state); -} diff --git a/chrome/browser/download/download_item.cc b/chrome/browser/download/download_item.cc index 7ccb4f1..54165a9 100644 --- a/chrome/browser/download/download_item.cc +++ b/chrome/browser/download/download_item.cc @@ -388,10 +388,15 @@ void DownloadItem::Completed() { auto_opened_ = true; } - DCHECK(all_data_saved_); - state_ = COMPLETE; - UpdateObservers(); - download_manager_->DownloadCompleted(id()); + // The download file is meant to be completed if both the filename is + // finalized and the file data is downloaded. The ordering of these two + // actions is indeterministic. Thus, if the filename is not finalized yet, + // delay the notification. + if (name_finalized()) { + state_ = COMPLETE; + UpdateObservers(); + download_manager_->RemoveFromActiveList(id()); + } } void DownloadItem::Interrupted(int64 size, int os_error) { diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index 7155001..f2cfe19 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -642,17 +642,15 @@ void DownloadManager::MaybeCompleteDownload(DownloadItem* download) { in_progress_.erase(download->id()); UpdateAppIcon(); // Reflect removal from in_progress_. + // Final update of download item and history. download_history_->UpdateEntry(download); // Finish the download. download->OnDownloadCompleting(file_manager_); } -void DownloadManager::DownloadCompleted(int32 download_id) { +void DownloadManager::RemoveFromActiveList(int32 download_id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DownloadItem* download = GetDownloadItem(download_id); - DCHECK(download); - download_history_->UpdateEntry(download); active_downloads_.erase(download_id); } diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h index 5af8932..84b8399 100644 --- a/chrome/browser/download/download_manager.h +++ b/chrome/browser/download/download_manager.h @@ -162,9 +162,8 @@ class DownloadManager // deleted is returned back to the caller. int RemoveAllDownloads(); - // Final download manager transition for download: Update the download - // history and remove the download from |active_downloads_|. - void DownloadCompleted(int32 download_id); + // Remove the download with id |download_id| from |active_downloads_|. + void RemoveFromActiveList(int32 download_id); // Called when a Save Page As download is started. Transfers ownership // of |download_item| to the DownloadManager. |
