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

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

Issue 12662032: Merge SavePackageFilePicker{,ChromeOS} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r198452 Created 7 years, 7 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) 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
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);
61 incognito_save_file_path_ = *save_file_path_;
60 62
61 // We store any file extension that should be opened automatically at 63 // We store any file extension that should be opened automatically at
62 // download completion in this pref. 64 // download completion in this pref.
63 std::string extensions_to_open = 65 std::string extensions_to_open =
64 prefs->GetString(prefs::kDownloadExtensionsToOpen); 66 prefs->GetString(prefs::kDownloadExtensionsToOpen);
65 std::vector<std::string> extensions; 67 std::vector<std::string> extensions;
66 base::SplitString(extensions_to_open, ':', &extensions); 68 base::SplitString(extensions_to_open, ':', &extensions);
67 69
68 for (size_t i = 0; i < extensions.size(); ++i) { 70 for (size_t i = 0; i < extensions.size(); ++i) {
69 #if defined(OS_POSIX) 71 #if defined(OS_POSIX)
(...skipping 30 matching lines...) Expand all
100 content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, 102 content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML,
101 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 103 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
102 104
103 // The default download path is userprofile\download. 105 // The default download path is userprofile\download.
104 const base::FilePath& default_download_path = 106 const base::FilePath& default_download_path =
105 download_util::GetDefaultDownloadDirectory(); 107 download_util::GetDefaultDownloadDirectory();
106 registry->RegisterFilePathPref( 108 registry->RegisterFilePathPref(
107 prefs::kDownloadDefaultDirectory, 109 prefs::kDownloadDefaultDirectory,
108 default_download_path, 110 default_download_path,
109 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 111 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
112 registry->RegisterFilePathPref(
113 prefs::kSaveFileDefaultDirectory,
114 default_download_path,
115 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
110 116
111 #if defined(OS_CHROMEOS) 117 #if defined(OS_CHROMEOS)
112 // Ensure that the download directory specified in the preferences exists. 118 // Ensure that the download directory specified in the preferences exists.
113 BrowserThread::PostTask( 119 BrowserThread::PostTask(
114 BrowserThread::FILE, FROM_HERE, 120 BrowserThread::FILE, FROM_HERE,
115 base::Bind(base::IgnoreResult(&file_util::CreateDirectory), 121 base::Bind(base::IgnoreResult(&file_util::CreateDirectory),
116 default_download_path)); 122 default_download_path));
117 #endif // defined(OS_CHROMEOS) 123 #endif // defined(OS_CHROMEOS)
118 } 124 }
119 125
(...skipping 17 matching lines...) Expand all
137 // If the download path is under /drive, and DriveSystemService isn't 143 // If the download path is under /drive, and DriveSystemService isn't
138 // available (which it isn't for incognito mode, for instance), use the 144 // available (which it isn't for incognito mode, for instance), use the
139 // default download directory (/Downloads). 145 // default download directory (/Downloads).
140 if (drive::util::IsUnderDriveMountPoint(*download_path_) && 146 if (drive::util::IsUnderDriveMountPoint(*download_path_) &&
141 !drive::DriveSystemServiceFactory::GetForProfile(profile_)) 147 !drive::DriveSystemServiceFactory::GetForProfile(profile_))
142 return download_util::GetDefaultDownloadDirectory(); 148 return download_util::GetDefaultDownloadDirectory();
143 #endif 149 #endif
144 return *download_path_; 150 return *download_path_;
145 } 151 }
146 152
153 void DownloadPrefs::SetDownloadPath(const base::FilePath& path) {
154 download_path_.SetValue(path);
asanka 2013/05/07 15:15:12 Suggestion: Should this also set save_file_path_ ?
benjhayden 2013/05/17 20:31:54 Done.
155 }
156
157 base::FilePath DownloadPrefs::SaveFilePath() const {
158 return profile_->IsOffTheRecord() ? incognito_save_file_path_ :
159 *save_file_path_;
160 }
161
162 void DownloadPrefs::SetSaveFilePath(const base::FilePath& path) {
163 if (path == SaveFilePath())
164 return;
165 if (profile_->IsOffTheRecord()) {
asanka 2013/05/07 15:15:12 Does this need to be handled this way? Isn't the i
benjhayden 2013/05/17 20:31:54 This is necessary. Without incognito_save_file_pat
166 incognito_save_file_path_ = path;
167 } else {
168 save_file_path_.SetValue(path);
169 }
170 }
171
172 void DownloadPrefs::SetSaveFileType(int type) {
173 save_file_type_.SetValue(type);
174 }
175
147 bool DownloadPrefs::PromptForDownload() const { 176 bool DownloadPrefs::PromptForDownload() const {
148 // If the DownloadDirectory policy is set, then |prompt_for_download_| should 177 // If the DownloadDirectory policy is set, then |prompt_for_download_| should
149 // always be false. 178 // always be false.
150 DCHECK(!download_path_.IsManaged() || !prompt_for_download_.GetValue()); 179 DCHECK(!download_path_.IsManaged() || !prompt_for_download_.GetValue());
151 return *prompt_for_download_; 180 return *prompt_for_download_;
152 } 181 }
153 182
154 bool DownloadPrefs::IsDownloadPathManaged() const { 183 bool DownloadPrefs::IsDownloadPathManaged() const {
155 return download_path_.IsManaged(); 184 return download_path_.IsManaged();
156 } 185 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 extensions.erase(extensions.size() - 1); 243 extensions.erase(extensions.size() - 1);
215 244
216 profile_->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, extensions); 245 profile_->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, extensions);
217 } 246 }
218 247
219 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( 248 bool DownloadPrefs::AutoOpenCompareFunctor::operator()(
220 const base::FilePath::StringType& a, 249 const base::FilePath::StringType& a,
221 const base::FilePath::StringType& b) const { 250 const base::FilePath::StringType& b) const {
222 return base::FilePath::CompareLessIgnoreCase(a, b); 251 return base::FilePath::CompareLessIgnoreCase(a, b);
223 } 252 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698