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

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

Issue 6973052: When the download folder does not exist, change the download folder to a user's "Downloads" (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Correct typo Created 9 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/download/download_manager.h" 5 #include "chrome/browser/download/download_manager.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 download->id(), 361 download->id(),
362 state, 362 state,
363 download_prefs()->download_path())); 363 download_prefs()->download_path()));
364 } 364 }
365 365
366 void DownloadManager::CheckIfSuggestedPathExists(int32 download_id, 366 void DownloadManager::CheckIfSuggestedPathExists(int32 download_id,
367 DownloadStateInfo state, 367 DownloadStateInfo state,
368 const FilePath& default_path) { 368 const FilePath& default_path) {
369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
370 370
371 // Make sure the default download directory exists.
372 // TODO(phajdan.jr): only create the directory when we're sure the user
373 // is going to save there and not to another directory of his choice.
374 file_util::CreateDirectory(default_path);
375
376 // Check writability of the suggested path. If we can't write to it, default 371 // Check writability of the suggested path. If we can't write to it, default
377 // to the user's "My Documents" directory. We'll prompt them in this case. 372 // to the user's "Downloads" directory. We'll prompt them in this case.
378 FilePath dir = state.suggested_path.DirName(); 373 FilePath dir = state.suggested_path.DirName();
379 FilePath filename = state.suggested_path.BaseName(); 374 FilePath filename = state.suggested_path.BaseName();
380 if (!file_util::PathIsWritable(dir)) { 375 if (!file_util::PathIsWritable(dir)) {
381 VLOG(1) << "Unable to write to directory \"" << dir.value() << "\""; 376 VLOG(1) << "Unable to write to directory \"" << dir.value() << "\"";
382 state.prompt_user_for_save_location = true; 377 state.prompt_user_for_save_location = true;
383 PathService::Get(chrome::DIR_USER_DOCUMENTS, &state.suggested_path); 378 PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &state.suggested_path);
Paweł Hajdan Jr. 2011/05/31 17:15:53 Oh, this code didn't check return value of PathSer
haraken1 2011/06/02 09:13:22 Done.
384 state.suggested_path = state.suggested_path.Append(filename); 379 state.suggested_path = state.suggested_path.Append(filename);
385 } 380 }
386 381
387 // If the download is deemed dangerous, we'll use a temporary name for it. 382 // If the download is deemed dangerous, we'll use a temporary name for it.
388 if (state.IsDangerous()) { 383 if (state.IsDangerous()) {
389 state.target_name = FilePath(state.suggested_path).BaseName(); 384 state.target_name = FilePath(state.suggested_path).BaseName();
390 // Create a temporary file to hold the file until the user approves its 385 // Create a temporary file to hold the file until the user approves its
391 // download. 386 // download.
392 FilePath::StringType file_name; 387 FilePath::StringType file_name;
393 FilePath path; 388 FilePath path;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 // FileSelectionCancelled(). 483 // FileSelectionCancelled().
489 int32* id_ptr = new int32; 484 int32* id_ptr = new int32;
490 *id_ptr = download_id; 485 *id_ptr = download_id;
491 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, 486 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE,
492 string16(), 487 string16(),
493 suggested_path, 488 suggested_path,
494 &file_type_info, 0, FILE_PATH_LITERAL(""), 489 &file_type_info, 0, FILE_PATH_LITERAL(""),
495 contents, owning_window, 490 contents, owning_window,
496 reinterpret_cast<void*>(id_ptr)); 491 reinterpret_cast<void*>(id_ptr));
497 FOR_EACH_OBSERVER(Observer, observers_, 492 FOR_EACH_OBSERVER(Observer, observers_,
498 SelectFileDialogDisplayed(download_id)); 493 SelectFileDialogDisplayed(download_id, suggested_path));
499 } else { 494 } else {
500 // No prompting for download, just continue with the suggested name. 495 // No prompting for download, just continue with the suggested name.
501 ContinueDownloadWithPath(download, suggested_path); 496 ContinueDownloadWithPath(download, suggested_path);
502 } 497 }
503 } 498 }
504 499
505 void DownloadManager::CreateDownloadItem(DownloadCreateInfo* info) { 500 void DownloadManager::CreateDownloadItem(DownloadCreateInfo* info) {
506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 501 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
507 502
508 DownloadItem* download = new DownloadItem(this, *info, 503 DownloadItem* download = new DownloadItem(this, *info,
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 observed_download_manager_->RemoveObserver(this); 1272 observed_download_manager_->RemoveObserver(this);
1278 } 1273 }
1279 1274
1280 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { 1275 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() {
1281 observing_download_manager_->NotifyModelChanged(); 1276 observing_download_manager_->NotifyModelChanged();
1282 } 1277 }
1283 1278
1284 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { 1279 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() {
1285 observed_download_manager_ = NULL; 1280 observed_download_manager_ = NULL;
1286 } 1281 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698