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 25 matching lines...) Expand all Loading... |
94 registry->RegisterIntegerPref(prefs::kSaveFileType, | 95 registry->RegisterIntegerPref(prefs::kSaveFileType, |
95 content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, | 96 content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, |
96 PrefRegistrySyncable::UNSYNCABLE_PREF); | 97 PrefRegistrySyncable::UNSYNCABLE_PREF); |
97 | 98 |
98 // The default download path is userprofile\download. | 99 // The default download path is userprofile\download. |
99 const base::FilePath& default_download_path = | 100 const base::FilePath& default_download_path = |
100 download_util::GetDefaultDownloadDirectory(); | 101 download_util::GetDefaultDownloadDirectory(); |
101 registry->RegisterFilePathPref(prefs::kDownloadDefaultDirectory, | 102 registry->RegisterFilePathPref(prefs::kDownloadDefaultDirectory, |
102 default_download_path, | 103 default_download_path, |
103 PrefRegistrySyncable::UNSYNCABLE_PREF); | 104 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 105 registry->RegisterFilePathPref(prefs::kSaveFileDefaultDirectory, |
| 106 default_download_path, |
| 107 PrefRegistrySyncable::UNSYNCABLE_PREF); |
104 | 108 |
105 #if defined(OS_CHROMEOS) | 109 #if defined(OS_CHROMEOS) |
106 // Ensure that the download directory specified in the preferences exists. | 110 // Ensure that the download directory specified in the preferences exists. |
107 BrowserThread::PostTask( | 111 BrowserThread::PostTask( |
108 BrowserThread::FILE, FROM_HERE, | 112 BrowserThread::FILE, FROM_HERE, |
109 base::Bind(base::IgnoreResult(&file_util::CreateDirectory), | 113 base::Bind(base::IgnoreResult(&file_util::CreateDirectory), |
110 default_download_path)); | 114 default_download_path)); |
111 #endif // defined(OS_CHROMEOS) | 115 #endif // defined(OS_CHROMEOS) |
112 } | 116 } |
113 | 117 |
(...skipping 17 matching lines...) Expand all Loading... |
131 // If the download path is under /drive, and DriveSystemService isn't | 135 // If the download path is under /drive, and DriveSystemService isn't |
132 // available (which it isn't for incognito mode, for instance), use the | 136 // available (which it isn't for incognito mode, for instance), use the |
133 // default download directory (/Downloads). | 137 // default download directory (/Downloads). |
134 if (drive::util::IsUnderDriveMountPoint(*download_path_) && | 138 if (drive::util::IsUnderDriveMountPoint(*download_path_) && |
135 !drive::DriveSystemServiceFactory::GetForProfile(profile_)) | 139 !drive::DriveSystemServiceFactory::GetForProfile(profile_)) |
136 return download_util::GetDefaultDownloadDirectory(); | 140 return download_util::GetDefaultDownloadDirectory(); |
137 #endif | 141 #endif |
138 return *download_path_; | 142 return *download_path_; |
139 } | 143 } |
140 | 144 |
| 145 base::FilePath DownloadPrefs::SaveFilePath() const { |
| 146 return *save_file_path_; |
| 147 } |
| 148 |
| 149 void DownloadPrefs::SetSaveFilePath(const base::FilePath& path) { |
| 150 if (path == SaveFilePath()) |
| 151 return; |
| 152 save_file_path_.SetValue(path); |
| 153 } |
| 154 |
| 155 void DownloadPrefs::SetSaveFileType(int type) { |
| 156 save_file_type_.SetValue(type); |
| 157 } |
| 158 |
141 bool DownloadPrefs::PromptForDownload() const { | 159 bool DownloadPrefs::PromptForDownload() const { |
142 // If the DownloadDirectory policy is set, then |prompt_for_download_| should | 160 // If the DownloadDirectory policy is set, then |prompt_for_download_| should |
143 // always be false. | 161 // always be false. |
144 DCHECK(!download_path_.IsManaged() || !prompt_for_download_.GetValue()); | 162 DCHECK(!download_path_.IsManaged() || !prompt_for_download_.GetValue()); |
145 return *prompt_for_download_; | 163 return *prompt_for_download_; |
146 } | 164 } |
147 | 165 |
148 bool DownloadPrefs::IsDownloadPathManaged() const { | 166 bool DownloadPrefs::IsDownloadPathManaged() const { |
149 return download_path_.IsManaged(); | 167 return download_path_.IsManaged(); |
150 } | 168 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 extensions.erase(extensions.size() - 1); | 221 extensions.erase(extensions.size() - 1); |
204 | 222 |
205 profile_->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, extensions); | 223 profile_->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, extensions); |
206 } | 224 } |
207 | 225 |
208 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( | 226 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( |
209 const base::FilePath::StringType& a, | 227 const base::FilePath::StringType& a, |
210 const base::FilePath::StringType& b) const { | 228 const base::FilePath::StringType& b) const { |
211 return base::FilePath::CompareLessIgnoreCase(a, b); | 229 return base::FilePath::CompareLessIgnoreCase(a, b); |
212 } | 230 } |
OLD | NEW |