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

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

Issue 3043024: Creating download directory on chromeos when its registered as the default do... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 5 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
« no previous file with comments | « no previous file | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 void DownloadManager::RegisterUserPrefs(PrefService* prefs) { 77 void DownloadManager::RegisterUserPrefs(PrefService* prefs) {
78 prefs->RegisterBooleanPref(prefs::kPromptForDownload, false); 78 prefs->RegisterBooleanPref(prefs::kPromptForDownload, false);
79 prefs->RegisterStringPref(prefs::kDownloadExtensionsToOpen, ""); 79 prefs->RegisterStringPref(prefs::kDownloadExtensionsToOpen, "");
80 prefs->RegisterBooleanPref(prefs::kDownloadDirUpgraded, false); 80 prefs->RegisterBooleanPref(prefs::kDownloadDirUpgraded, false);
81 81
82 // The default download path is userprofile\download. 82 // The default download path is userprofile\download.
83 const FilePath& default_download_path = 83 const FilePath& default_download_path =
84 download_util::GetDefaultDownloadDirectory(); 84 download_util::GetDefaultDownloadDirectory();
85 prefs->RegisterFilePathPref(prefs::kDownloadDefaultDirectory, 85 prefs->RegisterFilePathPref(prefs::kDownloadDefaultDirectory,
86 default_download_path); 86 default_download_path);
87 #if defined(OS_CHROMEOS)
88 // Ensure that the download directory specified in the preferences exists.
89 ChromeThread::PostTask(
90 ChromeThread::FILE, FROM_HERE,
91 NewRunnableFunction(&file_util::CreateDirectory, default_download_path));
92 #endif
87 93
88 // If the download path is dangerous we forcefully reset it. But if we do 94 // If the download path is dangerous we forcefully reset it. But if we do
89 // so we set a flag to make sure we only do it once, to avoid fighting 95 // so we set a flag to make sure we only do it once, to avoid fighting
90 // the user if he really wants it on an unsafe place such as the desktop. 96 // the user if he really wants it on an unsafe place such as the desktop.
91 97
92 if (!prefs->GetBoolean(prefs::kDownloadDirUpgraded)) { 98 if (!prefs->GetBoolean(prefs::kDownloadDirUpgraded)) {
93 FilePath current_download_dir = prefs->GetFilePath( 99 FilePath current_download_dir = prefs->GetFilePath(
94 prefs::kDownloadDefaultDirectory); 100 prefs::kDownloadDefaultDirectory);
95 if (download_util::DownloadPathIsDangerous(current_download_dir)) { 101 if (download_util::DownloadPathIsDangerous(current_download_dir)) {
96 prefs->SetFilePath(prefs::kDownloadDefaultDirectory, 102 prefs->SetFilePath(prefs::kDownloadDefaultDirectory,
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 file_manager_ = rdh->download_file_manager(); 341 file_manager_ = rdh->download_file_manager();
336 DCHECK(file_manager_); 342 DCHECK(file_manager_);
337 } 343 }
338 344
339 // Get our user preference state. 345 // Get our user preference state.
340 PrefService* prefs = profile_->GetPrefs(); 346 PrefService* prefs = profile_->GetPrefs();
341 DCHECK(prefs); 347 DCHECK(prefs);
342 prompt_for_download_.Init(prefs::kPromptForDownload, prefs, NULL); 348 prompt_for_download_.Init(prefs::kPromptForDownload, prefs, NULL);
343 349
344 download_path_.Init(prefs::kDownloadDefaultDirectory, prefs, NULL); 350 download_path_.Init(prefs::kDownloadDefaultDirectory, prefs, NULL);
345
346 // Ensure that the download directory specified in the preferences exists. 351 // Ensure that the download directory specified in the preferences exists.
347 ChromeThread::PostTask( 352 ChromeThread::PostTask(
348 ChromeThread::FILE, FROM_HERE, 353 ChromeThread::FILE, FROM_HERE,
349 NewRunnableFunction(&file_util::CreateDirectory, download_path())); 354 NewRunnableFunction(&file_util::CreateDirectory, download_path()));
350 355
351 // We store any file extension that should be opened automatically at 356 // We store any file extension that should be opened automatically at
352 // download completion in this pref. 357 // download completion in this pref.
353 std::string extensions_to_open = 358 std::string extensions_to_open =
354 prefs->GetString(prefs::kDownloadExtensionsToOpen); 359 prefs->GetString(prefs::kDownloadExtensionsToOpen);
355 std::vector<std::string> extensions; 360 std::vector<std::string> extensions;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 // 2) Filetypes marked "always open." If the user just wants this file 431 // 2) Filetypes marked "always open." If the user just wants this file
427 // opened, don't bother asking where to keep it. 432 // opened, don't bother asking where to keep it.
428 if (!info->is_extension_install && 433 if (!info->is_extension_install &&
429 !ShouldOpenFileBasedOnExtension(generated_name)) 434 !ShouldOpenFileBasedOnExtension(generated_name))
430 info->prompt_user_for_save_location = true; 435 info->prompt_user_for_save_location = true;
431 } 436 }
432 437
433 // Determine the proper path for a download, by either one of the following: 438 // Determine the proper path for a download, by either one of the following:
434 // 1) using the default download directory. 439 // 1) using the default download directory.
435 // 2) prompting the user. 440 // 2) prompting the user.
436 if (info->prompt_user_for_save_location && !last_download_path_.empty()) 441 if (info->prompt_user_for_save_location && !last_download_path_.empty()){
437 info->suggested_path = last_download_path_; 442 info->suggested_path = last_download_path_;
438 else 443 } else {
439 info->suggested_path = download_path(); 444 info->suggested_path = download_path();
445 }
440 info->suggested_path = info->suggested_path.Append(generated_name); 446 info->suggested_path = info->suggested_path.Append(generated_name);
441 } else { 447 } else {
442 info->suggested_path = info->save_info.file_path; 448 info->suggested_path = info->save_info.file_path;
443 } 449 }
444 450
445 if (!info->prompt_user_for_save_location && 451 if (!info->prompt_user_for_save_location &&
446 info->save_info.file_path.empty()) { 452 info->save_info.file_path.empty()) {
447 // Downloads can be marked as dangerous for two reasons: 453 // Downloads can be marked as dangerous for two reasons:
448 // a) They have a dangerous-looking filename 454 // a) They have a dangerous-looking filename
449 // b) They are an extension that is not from the gallery 455 // b) They are an extension that is not from the gallery
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 observing_download_manager_->NotifyModelChanged(); 1638 observing_download_manager_->NotifyModelChanged();
1633 } 1639 }
1634 1640
1635 void DownloadManager::OtherDownloadManagerObserver::SetDownloads( 1641 void DownloadManager::OtherDownloadManagerObserver::SetDownloads(
1636 std::vector<DownloadItem*>& downloads) { 1642 std::vector<DownloadItem*>& downloads) {
1637 } 1643 }
1638 1644
1639 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { 1645 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() {
1640 observed_download_manager_ = NULL; 1646 observed_download_manager_ = NULL;
1641 } 1647 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698