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

Side by Side Diff: chrome/browser/download/download_manager.cc

Issue 10743: Use the most recently used download path when displaying a "save as" dialog.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 12 years, 1 month 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
« no previous file with comments | « chrome/browser/download/download_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <time.h> 5 #include <time.h>
6 6
7 #include "chrome/browser/download/download_manager.h" 7 #include "chrome/browser/download/download_manager.h"
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 SaveAutoOpens(); 391 SaveAutoOpens();
392 392
393 // Make sure the save as dialog doesn't notify us back if we're gone before 393 // Make sure the save as dialog doesn't notify us back if we're gone before
394 // it returns. 394 // it returns.
395 if (select_file_dialog_.get()) 395 if (select_file_dialog_.get())
396 select_file_dialog_->ListenerDestroyed(); 396 select_file_dialog_->ListenerDestroyed();
397 397
398 shutdown_needed_ = false; 398 shutdown_needed_ = false;
399 } 399 }
400 400
401 // Determines whether the "save as" dialog should be displayed to the user
402 // when downloading a file.
403 bool DownloadManager::ShouldDisplaySaveAsDialog(
404 const DownloadCreateInfo* info) {
405 return
406 *prompt_for_download_ || // User always wants a prompt.
407 info->save_as || // "Save as ..." operation.
408 info->path_uniquifier == -1; // Last attempt to generate a unique file
409 // name failed.
410 }
411
401 // Issue a history query for downloads matching 'search_text'. If 'search_text' 412 // Issue a history query for downloads matching 'search_text'. If 'search_text'
402 // is empty, return all downloads that we know about. 413 // is empty, return all downloads that we know about.
403 void DownloadManager::GetDownloads(Observer* observer, 414 void DownloadManager::GetDownloads(Observer* observer,
404 const std::wstring& search_text) { 415 const std::wstring& search_text) {
405 DCHECK(observer); 416 DCHECK(observer);
406 417
407 // Return a empty list if we've not yet received the set of downloads from the 418 // Return a empty list if we've not yet received the set of downloads from the
408 // history system (we'll update all observers once we get that list in 419 // history system (we'll update all observers once we get that list in
409 // OnQueryDownloadEntriesComplete), or if there are no downloads at all. 420 // OnQueryDownloadEntriesComplete), or if there are no downloads at all.
410 std::vector<DownloadItem*> download_copy; 421 std::vector<DownloadItem*> download_copy;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 // point. OnCreateDatabaseEntryComplete() handles that finalization of the the 527 // point. OnCreateDatabaseEntryComplete() handles that finalization of the the
517 // download creation as a callback from the history thread. 528 // download creation as a callback from the history thread.
518 void DownloadManager::StartDownload(DownloadCreateInfo* info) { 529 void DownloadManager::StartDownload(DownloadCreateInfo* info) {
519 DCHECK(MessageLoop::current() == ui_loop_); 530 DCHECK(MessageLoop::current() == ui_loop_);
520 DCHECK(info); 531 DCHECK(info);
521 532
522 // Determine the proper path for a download, by choosing either the default 533 // Determine the proper path for a download, by choosing either the default
523 // download directory, or prompting the user. 534 // download directory, or prompting the user.
524 std::wstring generated_name; 535 std::wstring generated_name;
525 GenerateFilename(info, &generated_name); 536 GenerateFilename(info, &generated_name);
526 if (*prompt_for_download_ && !last_download_path_.empty()) 537 if (ShouldDisplaySaveAsDialog(info) && !last_download_path_.empty())
527 info->suggested_path = last_download_path_; 538 info->suggested_path = last_download_path_;
528 else 539 else
529 info->suggested_path = *download_path_; 540 info->suggested_path = *download_path_;
530 file_util::AppendToPath(&info->suggested_path, generated_name); 541 file_util::AppendToPath(&info->suggested_path, generated_name);
531 542
532 // Let's check if this download is dangerous, based on its name. 543 // Let's check if this download is dangerous, based on its name.
533 if (!*prompt_for_download_ && !info->save_as) { 544 if (!ShouldDisplaySaveAsDialog(info)) {
534 const std::wstring filename = 545 const std::wstring filename =
535 file_util::GetFilenameFromPath(info->suggested_path); 546 file_util::GetFilenameFromPath(info->suggested_path);
536 info->is_dangerous = IsDangerous(filename); 547 info->is_dangerous = IsDangerous(filename);
537 } 548 }
538 549
539 // We need to move over to the download thread because we don't want to stat 550 // We need to move over to the download thread because we don't want to stat
540 // the suggested path on the UI thread. 551 // the suggested path on the UI thread.
541 file_loop_->PostTask(FROM_HERE, 552 file_loop_->PostTask(FROM_HERE,
542 NewRunnableMethod(this, 553 NewRunnableMethod(this,
543 &DownloadManager::CheckIfSuggestedPathExists, 554 &DownloadManager::CheckIfSuggestedPathExists,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 ui_loop_->PostTask(FROM_HERE, 601 ui_loop_->PostTask(FROM_HERE,
591 NewRunnableMethod(this, 602 NewRunnableMethod(this,
592 &DownloadManager::OnPathExistenceAvailable, 603 &DownloadManager::OnPathExistenceAvailable,
593 info)); 604 info));
594 } 605 }
595 606
596 void DownloadManager::OnPathExistenceAvailable(DownloadCreateInfo* info) { 607 void DownloadManager::OnPathExistenceAvailable(DownloadCreateInfo* info) {
597 DCHECK(MessageLoop::current() == ui_loop_); 608 DCHECK(MessageLoop::current() == ui_loop_);
598 DCHECK(info); 609 DCHECK(info);
599 610
600 if (*prompt_for_download_ || info->save_as || info->path_uniquifier == -1) { 611 if (ShouldDisplaySaveAsDialog(info)) {
601 // We must ask the user for the place to put the download. 612 // We must ask the user for the place to put the download.
602 if (!select_file_dialog_.get()) 613 if (!select_file_dialog_.get())
603 select_file_dialog_ = SelectFileDialog::Create(this); 614 select_file_dialog_ = SelectFileDialog::Create(this);
604 615
605 TabContents* contents = tab_util::GetTabContentsByID( 616 TabContents* contents = tab_util::GetTabContentsByID(
606 info->render_process_id, info->render_view_id); 617 info->render_process_id, info->render_view_id);
607 HWND owning_hwnd = 618 HWND owning_hwnd =
608 contents ? GetAncestor(contents->GetContainerHWND(), GA_ROOT) : NULL; 619 contents ? GetAncestor(contents->GetContainerHWND(), GA_ROOT) : NULL;
609 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, 620 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE,
610 std::wstring(), info->suggested_path, 621 std::wstring(), info->suggested_path,
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 extensions += *it + L":"; 1214 extensions += *it + L":";
1204 } 1215 }
1205 if (!extensions.empty()) 1216 if (!extensions.empty())
1206 extensions.erase(extensions.size() - 1); 1217 extensions.erase(extensions.size() - 1);
1207 prefs->SetString(prefs::kDownloadExtensionsToOpen, extensions); 1218 prefs->SetString(prefs::kDownloadExtensionsToOpen, extensions);
1208 } 1219 }
1209 } 1220 }
1210 1221
1211 void DownloadManager::FileSelected(const std::wstring& path, void* params) { 1222 void DownloadManager::FileSelected(const std::wstring& path, void* params) {
1212 DownloadCreateInfo* info = reinterpret_cast<DownloadCreateInfo*>(params); 1223 DownloadCreateInfo* info = reinterpret_cast<DownloadCreateInfo*>(params);
1213 if (*prompt_for_download_) 1224 if (ShouldDisplaySaveAsDialog(info))
1214 last_download_path_ = file_util::GetDirectoryFromPath(path); 1225 last_download_path_ = file_util::GetDirectoryFromPath(path);
1215 ContinueStartDownload(info, path); 1226 ContinueStartDownload(info, path);
1216 } 1227 }
1217 1228
1218 void DownloadManager::FileSelectionCanceled(void* params) { 1229 void DownloadManager::FileSelectionCanceled(void* params) {
1219 // The user didn't pick a place to save the file, so need to cancel the 1230 // The user didn't pick a place to save the file, so need to cancel the
1220 // download that's already in progress to the temporary location. 1231 // download that's already in progress to the temporary location.
1221 DownloadCreateInfo* info = reinterpret_cast<DownloadCreateInfo*>(params); 1232 DownloadCreateInfo* info = reinterpret_cast<DownloadCreateInfo*>(params);
1222 file_loop_->PostTask(FROM_HERE, 1233 file_loop_->PostTask(FROM_HERE,
1223 NewRunnableMethod(file_manager_, &DownloadFileManager::CancelDownload, 1234 NewRunnableMethod(file_manager_, &DownloadFileManager::CancelDownload,
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 std::vector<DownloadItem*> searched_downloads; 1338 std::vector<DownloadItem*> searched_downloads;
1328 for (std::vector<int64>::iterator it = results->begin(); 1339 for (std::vector<int64>::iterator it = results->begin();
1329 it != results->end(); ++it) { 1340 it != results->end(); ++it) {
1330 DownloadMap::iterator dit = downloads_.find(*it); 1341 DownloadMap::iterator dit = downloads_.find(*it);
1331 if (dit != downloads_.end()) 1342 if (dit != downloads_.end())
1332 searched_downloads.push_back(dit->second); 1343 searched_downloads.push_back(dit->second);
1333 } 1344 }
1334 1345
1335 requestor->SetDownloads(searched_downloads); 1346 requestor->SetDownloads(searched_downloads);
1336 } 1347 }
1348
1349 // Clears the last download path, used to initialize "save as" dialogs.
1350 void DownloadManager::ClearLastDownloadPath() {
1351 last_download_path_.clear();
1352 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698