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

Unified Diff: content/shell/shell_download_manager_delegate.cc

Issue 10867060: Move some download tests to content from chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated comments. Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/shell/shell_download_manager_delegate.h ('k') | content/test/data/download/download-test.lib » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/shell/shell_download_manager_delegate.cc
diff --git a/content/shell/shell_download_manager_delegate.cc b/content/shell/shell_download_manager_delegate.cc
index 0a8548185aa112657b64de453aec9eae3afd6f78..5dfb4921678ec9c88ea2f8089ab59b2293cf8903 100644
--- a/content/shell/shell_download_manager_delegate.cc
+++ b/content/shell/shell_download_manager_delegate.cc
@@ -28,7 +28,9 @@
namespace content {
ShellDownloadManagerDelegate::ShellDownloadManagerDelegate()
- : download_manager_(NULL) {
+ : download_manager_(NULL),
+ suppress_prompting_(false),
+ last_download_db_handle_(DownloadItem::kUninitializedHandle) {
// Balanced in Shutdown();
AddRef();
}
@@ -49,6 +51,14 @@ void ShellDownloadManagerDelegate::Shutdown() {
bool ShellDownloadManagerDelegate::DetermineDownloadTarget(
DownloadItem* download,
const DownloadTargetCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ // This assignment needs to be here because even at the call to
+ // SetDownloadManager, the system is not fully initialized.
+ if (default_download_path_.empty()) {
+ default_download_path_ = download_manager_->GetBrowserContext()->GetPath().
+ Append(FILE_PATH_LITERAL("Downloads"));
+ }
+
if (!download->GetForcedFilePath().empty()) {
callback.Run(download->GetForcedFilePath(),
DownloadItem::TARGET_DISPOSITION_OVERWRITE,
@@ -70,32 +80,49 @@ bool ShellDownloadManagerDelegate::DetermineDownloadTarget(
FROM_HERE,
base::Bind(
&ShellDownloadManagerDelegate::GenerateFilename,
- this, download->GetId(), callback, generated_name));
- return false;
+ this, download->GetId(), callback, generated_name,
+ default_download_path_));
+ return true;
}
void ShellDownloadManagerDelegate::GenerateFilename(
int32 download_id,
const DownloadTargetCallback& callback,
- const FilePath& generated_name) {
- FilePath suggested_path = download_manager_->GetBrowserContext()->GetPath().
- Append(FILE_PATH_LITERAL("Downloads"));
- if (!file_util::PathExists(suggested_path))
- file_util::CreateDirectory(suggested_path);
+ const FilePath& generated_name,
+ const FilePath& suggested_directory) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ if (!file_util::PathExists(suggested_directory))
+ file_util::CreateDirectory(suggested_directory);
- suggested_path = suggested_path.Append(generated_name);
+ FilePath suggested_path(suggested_directory.Append(generated_name));
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(
- &ShellDownloadManagerDelegate::ChooseDownloadPath,
+ &ShellDownloadManagerDelegate::OnDownloadPathGenerated,
this, download_id, callback, suggested_path));
}
+void ShellDownloadManagerDelegate::OnDownloadPathGenerated(
+ int32 download_id,
+ const DownloadTargetCallback& callback,
+ const FilePath& suggested_path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (suppress_prompting_) {
+ // Testing exit.
+ callback.Run(suggested_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE,
+ DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, suggested_path);
+ return;
+ }
+
+ ChooseDownloadPath(download_id, callback, suggested_path);
+}
+
void ShellDownloadManagerDelegate::ChooseDownloadPath(
int32 download_id,
const DownloadTargetCallback& callback,
const FilePath& suggested_path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DownloadItem* item =
download_manager_->GetActiveDownloadItem(download_id);
if (!item)
@@ -154,4 +181,16 @@ void ShellDownloadManagerDelegate::ChooseDownloadPath(
DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, result);
}
+void ShellDownloadManagerDelegate::AddItemToPersistentStore(
+ DownloadItem* item) {
+ download_manager_->OnItemAddedToPersistentStore(
+ item->GetId(), --last_download_db_handle_);
+}
+
+void ShellDownloadManagerDelegate::SetDownloadBehaviorForTesting(
+ const FilePath& default_download_path) {
+ default_download_path_ = default_download_path;
+ suppress_prompting_ = true;
+}
+
} // namespace content
« no previous file with comments | « content/shell/shell_download_manager_delegate.h ('k') | content/test/data/download/download-test.lib » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698