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

Side by Side Diff: chrome/browser/download/download_prefs.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: Redirect "http://mock.testfile.http/<random path>" to "chrome/test/data/a.htm" Created 9 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 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_prefs.h" 5 #include "chrome/browser/download/download_prefs.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_split.h" 9 #include "base/string_split.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 prefs->RegisterStringPref(prefs::kDownloadExtensionsToOpen, 53 prefs->RegisterStringPref(prefs::kDownloadExtensionsToOpen,
54 "", 54 "",
55 PrefService::UNSYNCABLE_PREF); 55 PrefService::UNSYNCABLE_PREF);
56 prefs->RegisterBooleanPref(prefs::kDownloadDirUpgraded, 56 prefs->RegisterBooleanPref(prefs::kDownloadDirUpgraded,
57 false, 57 false,
58 PrefService::UNSYNCABLE_PREF); 58 PrefService::UNSYNCABLE_PREF);
59 prefs->RegisterIntegerPref(prefs::kSaveFileType, 59 prefs->RegisterIntegerPref(prefs::kSaveFileType,
60 SavePackage::SAVE_AS_COMPLETE_HTML, 60 SavePackage::SAVE_AS_COMPLETE_HTML,
61 PrefService::UNSYNCABLE_PREF); 61 PrefService::UNSYNCABLE_PREF);
62 62
63 // The default download path is userprofile\download. 63 // The user's default "Downloads" folder.
64 const FilePath& default_download_path = 64 FilePath default_download_dir =
65 download_util::GetDefaultDownloadDirectory(); 65 download_util::GetDefaultDownloadDirectoryFromPathService();
66 prefs->RegisterFilePathPref(prefs::kDownloadDefaultDirectory, 66 prefs->RegisterFilePathPref(prefs::kDownloadDefaultDirectory,
67 default_download_path, 67 default_download_dir,
68 PrefService::UNSYNCABLE_PREF); 68 PrefService::UNSYNCABLE_PREF);
69 69
70 #if defined(OS_CHROMEOS) 70 #if defined(OS_CHROMEOS)
71 // Ensure that the download directory specified in the preferences exists. 71 // Ensure that the download directory specified in the preferences exists.
72 BrowserThread::PostTask( 72 BrowserThread::PostTask(
73 BrowserThread::FILE, FROM_HERE, 73 BrowserThread::FILE, FROM_HERE,
74 NewRunnableFunction(&file_util::CreateDirectory, default_download_path)); 74 NewRunnableFunction(&file_util::CreateDirectory, default_download_dir));
75 #endif // defined(OS_CHROMEOS) 75 #endif // defined(OS_CHROMEOS)
76 76
77 // If the download path is dangerous we forcefully reset it. But if we do 77 // If the download path is dangerous we forcefully reset it. But if we do
78 // so we set a flag to make sure we only do it once, to avoid fighting 78 // so we set a flag to make sure we only do it once, to avoid fighting
79 // the user if he really wants it on an unsafe place such as the desktop. 79 // the user if he really wants it on an unsafe place such as the desktop.
80 if (!prefs->GetBoolean(prefs::kDownloadDirUpgraded)) { 80 if (!prefs->GetBoolean(prefs::kDownloadDirUpgraded)) {
81 FilePath current_download_dir = prefs->GetFilePath( 81 FilePath current_download_dir = prefs->GetFilePath(
82 prefs::kDownloadDefaultDirectory); 82 prefs::kDownloadDefaultDirectory);
83 if (download_util::DownloadPathIsDangerous(current_download_dir)) { 83 if (download_util::DownloadPathIsDangerous(current_download_dir)) {
84 prefs->SetFilePath(prefs::kDownloadDefaultDirectory, 84 prefs->SetFilePath(prefs::kDownloadDefaultDirectory,
85 default_download_path); 85 default_download_dir);
86 } 86 }
87 prefs->SetBoolean(prefs::kDownloadDirUpgraded, true); 87 prefs->SetBoolean(prefs::kDownloadDirUpgraded, true);
88 } 88 }
89 } 89 }
90 90
91 bool DownloadPrefs::PromptForDownload() const { 91 bool DownloadPrefs::PromptForDownload() const {
92 // If the DownloadDirectory policy is set, then |prompt_for_download_| should 92 // If the DownloadDirectory policy is set, then |prompt_for_download_| should
93 // always be false. 93 // always be false.
94 DCHECK(!download_path_.IsManaged() || !prompt_for_download_.GetValue()); 94 DCHECK(!download_path_.IsManaged() || !prompt_for_download_.GetValue());
95 return *prompt_for_download_; 95 return *prompt_for_download_;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 extensions.erase(extensions.size() - 1); 151 extensions.erase(extensions.size() - 1);
152 152
153 prefs_->SetString(prefs::kDownloadExtensionsToOpen, extensions); 153 prefs_->SetString(prefs::kDownloadExtensionsToOpen, extensions);
154 } 154 }
155 155
156 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( 156 bool DownloadPrefs::AutoOpenCompareFunctor::operator()(
157 const FilePath::StringType& a, 157 const FilePath::StringType& a,
158 const FilePath::StringType& b) const { 158 const FilePath::StringType& b) const {
159 return FilePath::CompareLessIgnoreCase(a, b); 159 return FilePath::CompareLessIgnoreCase(a, b);
160 } 160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698