| OLD | NEW |
| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/sys_string_conversions.h" | 12 #include "base/sys_string_conversions.h" |
| 13 #include "base/task.h" | 13 #include "base/task.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 15 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 16 #include "chrome/browser/download/download_extensions.h" | 16 #include "chrome/browser/download/download_extensions.h" |
| 17 #include "chrome/browser/download/download_service.h" | |
| 18 #include "chrome/browser/download/download_util.h" | 17 #include "chrome/browser/download/download_util.h" |
| 19 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 20 #include "chrome/browser/profiles/profile.h" | |
| 21 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 22 #include "content/browser/download/download_manager.h" | 20 #include "content/browser/download/download_manager.h" |
| 23 #include "content/browser/download/save_package.h" | 21 #include "content/browser/download/save_package.h" |
| 24 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 25 #include "chrome/browser/download/download_service_factory.h" | |
| 26 | 23 |
| 27 using content::BrowserThread; | 24 using content::BrowserThread; |
| 28 | 25 |
| 29 DownloadPrefs::DownloadPrefs(PrefService* prefs) : prefs_(prefs) { | 26 DownloadPrefs::DownloadPrefs(PrefService* prefs) : prefs_(prefs) { |
| 30 prompt_for_download_.Init(prefs::kPromptForDownload, prefs, NULL); | 27 prompt_for_download_.Init(prefs::kPromptForDownload, prefs, NULL); |
| 31 download_path_.Init(prefs::kDownloadDefaultDirectory, prefs, NULL); | 28 download_path_.Init(prefs::kDownloadDefaultDirectory, prefs, NULL); |
| 32 save_file_type_.Init(prefs::kSaveFileType, prefs, NULL); | 29 save_file_type_.Init(prefs::kSaveFileType, prefs, NULL); |
| 33 | 30 |
| 34 // We store any file extension that should be opened automatically at | 31 // We store any file extension that should be opened automatically at |
| 35 // download completion in this pref. | 32 // download completion in this pref. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 95 } |
| 99 | 96 |
| 100 // static | 97 // static |
| 101 DownloadPrefs* DownloadPrefs::FromDownloadManager( | 98 DownloadPrefs* DownloadPrefs::FromDownloadManager( |
| 102 DownloadManager* download_manager) { | 99 DownloadManager* download_manager) { |
| 103 ChromeDownloadManagerDelegate* delegate = | 100 ChromeDownloadManagerDelegate* delegate = |
| 104 static_cast<ChromeDownloadManagerDelegate*>(download_manager->delegate()); | 101 static_cast<ChromeDownloadManagerDelegate*>(download_manager->delegate()); |
| 105 return delegate->download_prefs(); | 102 return delegate->download_prefs(); |
| 106 } | 103 } |
| 107 | 104 |
| 108 // static | |
| 109 DownloadPrefs* DownloadPrefs::FromBrowserContext( | |
| 110 content::BrowserContext* browser_context) { | |
| 111 Profile* profile = static_cast<Profile*>(browser_context); | |
| 112 DownloadService* download_service = | |
| 113 DownloadServiceFactory::GetForProfile(profile); | |
| 114 return FromDownloadManager(download_service->GetDownloadManager()); | |
| 115 } | |
| 116 | |
| 117 bool DownloadPrefs::PromptForDownload() const { | 105 bool DownloadPrefs::PromptForDownload() const { |
| 118 // If the DownloadDirectory policy is set, then |prompt_for_download_| should | 106 // If the DownloadDirectory policy is set, then |prompt_for_download_| should |
| 119 // always be false. | 107 // always be false. |
| 120 DCHECK(!download_path_.IsManaged() || !prompt_for_download_.GetValue()); | 108 DCHECK(!download_path_.IsManaged() || !prompt_for_download_.GetValue()); |
| 121 return *prompt_for_download_; | 109 return *prompt_for_download_; |
| 122 } | 110 } |
| 123 | 111 |
| 124 bool DownloadPrefs::IsDownloadPathManaged() const { | 112 bool DownloadPrefs::IsDownloadPathManaged() const { |
| 125 return download_path_.IsManaged(); | 113 return download_path_.IsManaged(); |
| 126 } | 114 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 extensions.erase(extensions.size() - 1); | 165 extensions.erase(extensions.size() - 1); |
| 178 | 166 |
| 179 prefs_->SetString(prefs::kDownloadExtensionsToOpen, extensions); | 167 prefs_->SetString(prefs::kDownloadExtensionsToOpen, extensions); |
| 180 } | 168 } |
| 181 | 169 |
| 182 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( | 170 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( |
| 183 const FilePath::StringType& a, | 171 const FilePath::StringType& a, |
| 184 const FilePath::StringType& b) const { | 172 const FilePath::StringType& b) const { |
| 185 return FilePath::CompareLessIgnoreCase(a, b); | 173 return FilePath::CompareLessIgnoreCase(a, b); |
| 186 } | 174 } |
| OLD | NEW |