OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/shell/browser/shell_download_manager_delegate.h" | 5 #include "content/shell/browser/shell_download_manager_delegate.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <commdlg.h> | 9 #include <commdlg.h> |
10 #endif | 10 #endif |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 void ShellDownloadManagerDelegate::Shutdown() { | 52 void ShellDownloadManagerDelegate::Shutdown() { |
53 // Revoke any pending callbacks. download_manager_ et. al. are no longer safe | 53 // Revoke any pending callbacks. download_manager_ et. al. are no longer safe |
54 // to access after this point. | 54 // to access after this point. |
55 weak_ptr_factory_.InvalidateWeakPtrs(); | 55 weak_ptr_factory_.InvalidateWeakPtrs(); |
56 download_manager_ = NULL; | 56 download_manager_ = NULL; |
57 } | 57 } |
58 | 58 |
59 bool ShellDownloadManagerDelegate::DetermineDownloadTarget( | 59 bool ShellDownloadManagerDelegate::DetermineDownloadTarget( |
60 DownloadItem* download, | 60 DownloadItem* download, |
61 const DownloadTargetCallback& callback) { | 61 const DownloadTargetCallback& callback) { |
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 62 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
63 // This assignment needs to be here because even at the call to | 63 // This assignment needs to be here because even at the call to |
64 // SetDownloadManager, the system is not fully initialized. | 64 // SetDownloadManager, the system is not fully initialized. |
65 if (default_download_path_.empty()) { | 65 if (default_download_path_.empty()) { |
66 default_download_path_ = download_manager_->GetBrowserContext()->GetPath(). | 66 default_download_path_ = download_manager_->GetBrowserContext()->GetPath(). |
67 Append(FILE_PATH_LITERAL("Downloads")); | 67 Append(FILE_PATH_LITERAL("Downloads")); |
68 } | 68 } |
69 | 69 |
70 if (!download->GetForcedFilePath().empty()) { | 70 if (!download->GetForcedFilePath().empty()) { |
71 callback.Run(download->GetForcedFilePath(), | 71 callback.Run(download->GetForcedFilePath(), |
72 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 72 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 107 } |
108 | 108 |
109 // static | 109 // static |
110 void ShellDownloadManagerDelegate::GenerateFilename( | 110 void ShellDownloadManagerDelegate::GenerateFilename( |
111 const GURL& url, | 111 const GURL& url, |
112 const std::string& content_disposition, | 112 const std::string& content_disposition, |
113 const std::string& suggested_filename, | 113 const std::string& suggested_filename, |
114 const std::string& mime_type, | 114 const std::string& mime_type, |
115 const base::FilePath& suggested_directory, | 115 const base::FilePath& suggested_directory, |
116 const FilenameDeterminedCallback& callback) { | 116 const FilenameDeterminedCallback& callback) { |
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 117 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
118 base::FilePath generated_name = net::GenerateFileName(url, | 118 base::FilePath generated_name = net::GenerateFileName(url, |
119 content_disposition, | 119 content_disposition, |
120 std::string(), | 120 std::string(), |
121 suggested_filename, | 121 suggested_filename, |
122 mime_type, | 122 mime_type, |
123 "download"); | 123 "download"); |
124 | 124 |
125 if (!base::PathExists(suggested_directory)) | 125 if (!base::PathExists(suggested_directory)) |
126 base::CreateDirectory(suggested_directory); | 126 base::CreateDirectory(suggested_directory); |
127 | 127 |
128 base::FilePath suggested_path(suggested_directory.Append(generated_name)); | 128 base::FilePath suggested_path(suggested_directory.Append(generated_name)); |
129 BrowserThread::PostTask( | 129 BrowserThread::PostTask( |
130 BrowserThread::UI, FROM_HERE, base::Bind(callback, suggested_path)); | 130 BrowserThread::UI, FROM_HERE, base::Bind(callback, suggested_path)); |
131 } | 131 } |
132 | 132 |
133 void ShellDownloadManagerDelegate::OnDownloadPathGenerated( | 133 void ShellDownloadManagerDelegate::OnDownloadPathGenerated( |
134 uint32 download_id, | 134 uint32 download_id, |
135 const DownloadTargetCallback& callback, | 135 const DownloadTargetCallback& callback, |
136 const base::FilePath& suggested_path) { | 136 const base::FilePath& suggested_path) { |
137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 137 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
138 if (suppress_prompting_) { | 138 if (suppress_prompting_) { |
139 // Testing exit. | 139 // Testing exit. |
140 callback.Run(suggested_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 140 callback.Run(suggested_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
141 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 141 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
142 suggested_path.AddExtension(FILE_PATH_LITERAL(".crdownload"))); | 142 suggested_path.AddExtension(FILE_PATH_LITERAL(".crdownload"))); |
143 return; | 143 return; |
144 } | 144 } |
145 | 145 |
146 ChooseDownloadPath(download_id, callback, suggested_path); | 146 ChooseDownloadPath(download_id, callback, suggested_path); |
147 } | 147 } |
148 | 148 |
149 void ShellDownloadManagerDelegate::ChooseDownloadPath( | 149 void ShellDownloadManagerDelegate::ChooseDownloadPath( |
150 uint32 download_id, | 150 uint32 download_id, |
151 const DownloadTargetCallback& callback, | 151 const DownloadTargetCallback& callback, |
152 const base::FilePath& suggested_path) { | 152 const base::FilePath& suggested_path) { |
153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 153 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
154 DownloadItem* item = download_manager_->GetDownload(download_id); | 154 DownloadItem* item = download_manager_->GetDownload(download_id); |
155 if (!item || (item->GetState() != DownloadItem::IN_PROGRESS)) | 155 if (!item || (item->GetState() != DownloadItem::IN_PROGRESS)) |
156 return; | 156 return; |
157 | 157 |
158 base::FilePath result; | 158 base::FilePath result; |
159 #if defined(OS_WIN) | 159 #if defined(OS_WIN) |
160 std::wstring file_part = base::FilePath(suggested_path).BaseName().value(); | 160 std::wstring file_part = base::FilePath(suggested_path).BaseName().value(); |
161 wchar_t file_name[MAX_PATH]; | 161 wchar_t file_name[MAX_PATH]; |
162 base::wcslcpy(file_name, file_part.c_str(), arraysize(file_name)); | 162 base::wcslcpy(file_name, file_part.c_str(), arraysize(file_name)); |
163 OPENFILENAME save_as; | 163 OPENFILENAME save_as; |
(...skipping 22 matching lines...) Expand all Loading... |
186 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, result); | 186 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, result); |
187 } | 187 } |
188 | 188 |
189 void ShellDownloadManagerDelegate::SetDownloadBehaviorForTesting( | 189 void ShellDownloadManagerDelegate::SetDownloadBehaviorForTesting( |
190 const base::FilePath& default_download_path) { | 190 const base::FilePath& default_download_path) { |
191 default_download_path_ = default_download_path; | 191 default_download_path_ = default_download_path; |
192 suppress_prompting_ = true; | 192 suppress_prompting_ = true; |
193 } | 193 } |
194 | 194 |
195 } // namespace content | 195 } // namespace content |
OLD | NEW |