OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 prefs::kDownloadDefaultDirectory); | 49 prefs::kDownloadDefaultDirectory); |
50 if (download_util::DownloadPathIsDangerous(current_download_dir)) { | 50 if (download_util::DownloadPathIsDangerous(current_download_dir)) { |
51 prefs->SetFilePath(prefs::kDownloadDefaultDirectory, | 51 prefs->SetFilePath(prefs::kDownloadDefaultDirectory, |
52 download_util::GetDefaultDownloadDirectory()); | 52 download_util::GetDefaultDownloadDirectory()); |
53 } | 53 } |
54 prefs->SetBoolean(prefs::kDownloadDirUpgraded, true); | 54 prefs->SetBoolean(prefs::kDownloadDirUpgraded, true); |
55 } | 55 } |
56 | 56 |
57 prompt_for_download_.Init(prefs::kPromptForDownload, prefs); | 57 prompt_for_download_.Init(prefs::kPromptForDownload, prefs); |
58 download_path_.Init(prefs::kDownloadDefaultDirectory, prefs); | 58 download_path_.Init(prefs::kDownloadDefaultDirectory, prefs); |
| 59 save_file_path_.Init(prefs::kSaveFileDefaultDirectory, prefs); |
59 save_file_type_.Init(prefs::kSaveFileType, prefs); | 60 save_file_type_.Init(prefs::kSaveFileType, prefs); |
60 | 61 |
61 // We store any file extension that should be opened automatically at | 62 // We store any file extension that should be opened automatically at |
62 // download completion in this pref. | 63 // download completion in this pref. |
63 std::string extensions_to_open = | 64 std::string extensions_to_open = |
64 prefs->GetString(prefs::kDownloadExtensionsToOpen); | 65 prefs->GetString(prefs::kDownloadExtensionsToOpen); |
65 std::vector<std::string> extensions; | 66 std::vector<std::string> extensions; |
66 base::SplitString(extensions_to_open, ':', &extensions); | 67 base::SplitString(extensions_to_open, ':', &extensions); |
67 | 68 |
68 for (size_t i = 0; i < extensions.size(); ++i) { | 69 for (size_t i = 0; i < extensions.size(); ++i) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, | 101 content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, |
101 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 102 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
102 | 103 |
103 // The default download path is userprofile\download. | 104 // The default download path is userprofile\download. |
104 const base::FilePath& default_download_path = | 105 const base::FilePath& default_download_path = |
105 download_util::GetDefaultDownloadDirectory(); | 106 download_util::GetDefaultDownloadDirectory(); |
106 registry->RegisterFilePathPref( | 107 registry->RegisterFilePathPref( |
107 prefs::kDownloadDefaultDirectory, | 108 prefs::kDownloadDefaultDirectory, |
108 default_download_path, | 109 default_download_path, |
109 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 110 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 111 registry->RegisterFilePathPref( |
| 112 prefs::kSaveFileDefaultDirectory, |
| 113 default_download_path, |
| 114 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
110 | 115 |
111 #if defined(OS_CHROMEOS) | 116 #if defined(OS_CHROMEOS) |
112 // Ensure that the download directory specified in the preferences exists. | 117 // Ensure that the download directory specified in the preferences exists. |
113 BrowserThread::PostTask( | 118 BrowserThread::PostTask( |
114 BrowserThread::FILE, FROM_HERE, | 119 BrowserThread::FILE, FROM_HERE, |
115 base::Bind(base::IgnoreResult(&file_util::CreateDirectory), | 120 base::Bind(base::IgnoreResult(&file_util::CreateDirectory), |
116 default_download_path)); | 121 default_download_path)); |
117 #endif // defined(OS_CHROMEOS) | 122 #endif // defined(OS_CHROMEOS) |
118 } | 123 } |
119 | 124 |
(...skipping 17 matching lines...) Expand all Loading... |
137 // If the download path is under /drive, and DriveIntegrationService isn't | 142 // If the download path is under /drive, and DriveIntegrationService isn't |
138 // available (which it isn't for incognito mode, for instance), use the | 143 // available (which it isn't for incognito mode, for instance), use the |
139 // default download directory (/Downloads). | 144 // default download directory (/Downloads). |
140 if (drive::util::IsUnderDriveMountPoint(*download_path_) && | 145 if (drive::util::IsUnderDriveMountPoint(*download_path_) && |
141 !drive::DriveIntegrationServiceFactory::GetForProfile(profile_)) | 146 !drive::DriveIntegrationServiceFactory::GetForProfile(profile_)) |
142 return download_util::GetDefaultDownloadDirectory(); | 147 return download_util::GetDefaultDownloadDirectory(); |
143 #endif | 148 #endif |
144 return *download_path_; | 149 return *download_path_; |
145 } | 150 } |
146 | 151 |
| 152 void DownloadPrefs::SetDownloadPath(const base::FilePath& path) { |
| 153 download_path_.SetValue(path); |
| 154 SetSaveFilePath(path); |
| 155 } |
| 156 |
| 157 base::FilePath DownloadPrefs::SaveFilePath() const { |
| 158 return *save_file_path_; |
| 159 } |
| 160 |
| 161 void DownloadPrefs::SetSaveFilePath(const base::FilePath& path) { |
| 162 save_file_path_.SetValue(path); |
| 163 } |
| 164 |
| 165 void DownloadPrefs::SetSaveFileType(int type) { |
| 166 save_file_type_.SetValue(type); |
| 167 } |
| 168 |
147 bool DownloadPrefs::PromptForDownload() const { | 169 bool DownloadPrefs::PromptForDownload() const { |
148 // If the DownloadDirectory policy is set, then |prompt_for_download_| should | 170 // If the DownloadDirectory policy is set, then |prompt_for_download_| should |
149 // always be false. | 171 // always be false. |
150 DCHECK(!download_path_.IsManaged() || !prompt_for_download_.GetValue()); | 172 DCHECK(!download_path_.IsManaged() || !prompt_for_download_.GetValue()); |
151 return *prompt_for_download_; | 173 return *prompt_for_download_; |
152 } | 174 } |
153 | 175 |
154 bool DownloadPrefs::IsDownloadPathManaged() const { | 176 bool DownloadPrefs::IsDownloadPathManaged() const { |
155 return download_path_.IsManaged(); | 177 return download_path_.IsManaged(); |
156 } | 178 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 extensions.erase(extensions.size() - 1); | 236 extensions.erase(extensions.size() - 1); |
215 | 237 |
216 profile_->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, extensions); | 238 profile_->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, extensions); |
217 } | 239 } |
218 | 240 |
219 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( | 241 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( |
220 const base::FilePath::StringType& a, | 242 const base::FilePath::StringType& a, |
221 const base::FilePath::StringType& b) const { | 243 const base::FilePath::StringType& b) const { |
222 return base::FilePath::CompareLessIgnoreCase(a, b); | 244 return base::FilePath::CompareLessIgnoreCase(a, b); |
223 } | 245 } |
OLD | NEW |