diff options
author | asanka@chromium.org <asanka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-24 04:09:02 +0000 |
---|---|---|
committer | asanka@chromium.org <asanka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-24 04:09:02 +0000 |
commit | 71f55847499f7fa45e4468c27d593eb18f20fb10 (patch) | |
tree | f81e062f683d1d9fe78184da04295f1a933af2e9 | |
parent | 37b4ea2428b736617aa2f0f3236e6a99f5aa0ea6 (diff) | |
download | chromium_src-71f55847499f7fa45e4468c27d593eb18f20fb10.zip chromium_src-71f55847499f7fa45e4468c27d593eb18f20fb10.tar.gz chromium_src-71f55847499f7fa45e4468c27d593eb18f20fb10.tar.bz2 |
Mark GData downloads as temporary.
This patch does the following:
1. Allow DownloadItems to transition to temporary downloads after they are created.
2. Prevent temporary downloads from affecting the last download directory. The last download directory is used as the default for subsequent "Save as" downloads.
3. Disable "Open when complete" and "Always open files of this type" for temporary downloads.
4. Mark GData downloads as temporary.
BUG=none
TEST=GData downloads don't show up in history and are removed automatically from the shelf
Review URL: http://codereview.chromium.org/9796010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128682 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_download_observer.cc | 11 | ||||
-rw-r--r-- | chrome/browser/download/download_file_picker_chromeos.cc | 1 | ||||
-rw-r--r-- | chrome/browser/download/download_shelf_context_menu.cc | 12 | ||||
-rw-r--r-- | content/browser/download/download_item_impl.cc | 8 | ||||
-rw-r--r-- | content/browser/download/download_item_impl.h | 1 | ||||
-rw-r--r-- | content/browser/download/download_manager_impl.cc | 4 | ||||
-rw-r--r-- | content/public/browser/download_item.h | 1 | ||||
-rw-r--r-- | content/test/mock_download_item.h | 1 |
8 files changed, 32 insertions, 7 deletions
diff --git a/chrome/browser/chromeos/gdata/gdata_download_observer.cc b/chrome/browser/chromeos/gdata/gdata_download_observer.cc index 4910d59..15b8d7e 100644 --- a/chrome/browser/chromeos/gdata/gdata_download_observer.cc +++ b/chrome/browser/chromeos/gdata/gdata_download_observer.cc @@ -163,10 +163,15 @@ void GDataDownloadObserver::ModelChanged(DownloadManager* download_manager) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DownloadManager::DownloadVector downloads; - download_manager->GetAllDownloads(temp_download_path_, - &downloads); + // GData downloads are considered temporary downloads. + download_manager->GetTemporaryDownloads(temp_download_path_, + &downloads); for (size_t i = 0; i < downloads.size(); ++i) { - OnDownloadUpdated(downloads[i]); + // Only accept downloads that have the GData meta data associated with + // them. Otherwise we might trip over non-GData downloads being saved to + // temp_download_path_. + if (IsGDataDownload(downloads[i])) + OnDownloadUpdated(downloads[i]); } } diff --git a/chrome/browser/download/download_file_picker_chromeos.cc b/chrome/browser/download/download_file_picker_chromeos.cc index a538301..1ee498a 100644 --- a/chrome/browser/download/download_file_picker_chromeos.cc +++ b/chrome/browser/download/download_file_picker_chromeos.cc @@ -80,6 +80,7 @@ void DownloadFilePickerChromeOS::FileSelected(const FilePath& path, if (download) { gdata::GDataDownloadObserver::SetGDataPath(download, path); download->SetDisplayName(path.BaseName()); + download->SetIsTemporary(true); const FilePath download_cache_path = system_service->file_system()->GetGDataTempDownloadFolderPath(); diff --git a/chrome/browser/download/download_shelf_context_menu.cc b/chrome/browser/download/download_shelf_context_menu.cc index 6eb492f..6cb748e 100644 --- a/chrome/browser/download/download_shelf_context_menu.cc +++ b/chrome/browser/download/download_shelf_context_menu.cc @@ -44,10 +44,18 @@ bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const { switch (command_id) { case SHOW_IN_FOLDER: case OPEN_WHEN_COMPLETE: - return download_item_->CanShowInFolder(); + // Don't enable "Open when complete" if the download is no longer + // available or if it is temporary. We explicitly ignore "Open when + // complete" for temporary downloads. + return download_item_->CanShowInFolder() && + !download_item_->IsTemporary(); case ALWAYS_OPEN_TYPE: + // For temporary downloads, the target filename might be a temporary + // filename. Don't base an "Always open" decision based on it. Also + // exclude extensions. return download_item_->CanOpenDownload() && - !Extension::IsExtension(download_item_->GetTargetName()); + !Extension::IsExtension(download_item_->GetTargetName()) && + !download_item_->IsTemporary(); case CANCEL: return download_item_->IsPartialDownload(); case TOGGLE_PAUSE: diff --git a/content/browser/download/download_item_impl.cc b/content/browser/download/download_item_impl.cc index d8a808b..1a9e39e 100644 --- a/content/browser/download/download_item_impl.cc +++ b/content/browser/download/download_item_impl.cc @@ -347,7 +347,10 @@ void DownloadItemImpl::OpenDownload() { CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); if (IsPartialDownload()) { - open_when_complete_ = !open_when_complete_; + // We don't honor the open_when_complete_ flag for temporary + // downloads. Don't set it because it shows up in the UI. + if (!IsTemporary()) + open_when_complete_ = !open_when_complete_; return; } @@ -1111,6 +1114,9 @@ const FilePath& DownloadItemImpl::GetSuggestedPath() const { return state_info_.suggested_path; } bool DownloadItemImpl::IsTemporary() const { return is_temporary_; } +void DownloadItemImpl::SetIsTemporary(bool temporary) { + is_temporary_ = temporary; +} void DownloadItemImpl::SetOpened(bool opened) { opened_ = opened; } bool DownloadItemImpl::GetOpened() const { return opened_; } const std::string& DownloadItemImpl::GetLastModifiedTime() const { diff --git a/content/browser/download/download_item_impl.h b/content/browser/download/download_item_impl.h index 0d52138..e6128cd 100644 --- a/content/browser/download/download_item_impl.h +++ b/content/browser/download/download_item_impl.h @@ -190,6 +190,7 @@ class CONTENT_EXPORT DownloadItemImpl : public content::DownloadItem { virtual bool IsOtr() const OVERRIDE; virtual const FilePath& GetSuggestedPath() const OVERRIDE; virtual bool IsTemporary() const OVERRIDE; + virtual void SetIsTemporary(bool temporary) OVERRIDE; virtual void SetOpened(bool opened) OVERRIDE; virtual bool GetOpened() const OVERRIDE; virtual const std::string& GetLastModifiedTime() const OVERRIDE; diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc index f6d16f7..33b32d8 100644 --- a/content/browser/download/download_manager_impl.cc +++ b/content/browser/download/download_manager_impl.cc @@ -904,7 +904,9 @@ void DownloadManagerImpl::FileSelected(const FilePath& path, VLOG(20) << __FUNCTION__ << "()" << " path = \"" << path.value() << "\"" << " download = " << download->DebugString(true); - if (download->PromptUserForSaveLocation()) + // Retain the last directory that was picked by the user. Exclude temporary + // downloads since the path likely points at the location of a temporary file. + if (download->PromptUserForSaveLocation() && !download->IsTemporary()) last_download_path_ = path.DirName(); // Make sure the initial file name is set only once. diff --git a/content/public/browser/download_item.h b/content/public/browser/download_item.h index a399db8..cdabae8 100644 --- a/content/public/browser/download_item.h +++ b/content/public/browser/download_item.h @@ -295,6 +295,7 @@ class CONTENT_EXPORT DownloadItem { virtual bool IsOtr() const = 0; virtual const FilePath& GetSuggestedPath() const = 0; virtual bool IsTemporary() const = 0; + virtual void SetIsTemporary(bool temporary) = 0; virtual void SetOpened(bool opened) = 0; virtual bool GetOpened() const = 0; diff --git a/content/test/mock_download_item.h b/content/test/mock_download_item.h index 5825378..e028096 100644 --- a/content/test/mock_download_item.h +++ b/content/test/mock_download_item.h @@ -99,6 +99,7 @@ class MockDownloadItem : public content::DownloadItem { MOCK_CONST_METHOD0(IsOtr, bool()); MOCK_CONST_METHOD0(GetSuggestedPath, const FilePath&()); MOCK_CONST_METHOD0(IsTemporary, bool()); + MOCK_METHOD1(SetIsTemporary, void(bool)); MOCK_METHOD1(SetOpened, void(bool)); MOCK_CONST_METHOD0(GetOpened, bool()); MOCK_CONST_METHOD0(GetLastModifiedTime, const std::string&()); |