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

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

Issue 8697006: DownloadManager intereface refactoring to allow cleaner DownloadItem unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added CONTENT_EXPORT to delegate. Created 9 years 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/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"
17 #include "chrome/browser/download/download_util.h" 18 #include "chrome/browser/download/download_util.h"
18 #include "chrome/browser/prefs/pref_service.h" 19 #include "chrome/browser/prefs/pref_service.h"
20 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
20 #include "content/browser/download/download_manager.h" 22 #include "content/browser/download/download_manager.h"
21 #include "content/browser/download/save_package.h" 23 #include "content/browser/download/save_package.h"
22 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
25 #include "chrome/browser/download/download_service_factory.h"
23 26
24 using content::BrowserThread; 27 using content::BrowserThread;
25 28
26 DownloadPrefs::DownloadPrefs(PrefService* prefs) : prefs_(prefs) { 29 DownloadPrefs::DownloadPrefs(PrefService* prefs) : prefs_(prefs) {
27 prompt_for_download_.Init(prefs::kPromptForDownload, prefs, NULL); 30 prompt_for_download_.Init(prefs::kPromptForDownload, prefs, NULL);
28 download_path_.Init(prefs::kDownloadDefaultDirectory, prefs, NULL); 31 download_path_.Init(prefs::kDownloadDefaultDirectory, prefs, NULL);
29 save_file_type_.Init(prefs::kSaveFileType, prefs, NULL); 32 save_file_type_.Init(prefs::kSaveFileType, prefs, NULL);
30 33
31 // We store any file extension that should be opened automatically at 34 // We store any file extension that should be opened automatically at
32 // download completion in this pref. 35 // download completion in this pref.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 98 }
96 99
97 // static 100 // static
98 DownloadPrefs* DownloadPrefs::FromDownloadManager( 101 DownloadPrefs* DownloadPrefs::FromDownloadManager(
99 DownloadManager* download_manager) { 102 DownloadManager* download_manager) {
100 ChromeDownloadManagerDelegate* delegate = 103 ChromeDownloadManagerDelegate* delegate =
101 static_cast<ChromeDownloadManagerDelegate*>(download_manager->delegate()); 104 static_cast<ChromeDownloadManagerDelegate*>(download_manager->delegate());
102 return delegate->download_prefs(); 105 return delegate->download_prefs();
103 } 106 }
104 107
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
105 bool DownloadPrefs::PromptForDownload() const { 117 bool DownloadPrefs::PromptForDownload() const {
106 // If the DownloadDirectory policy is set, then |prompt_for_download_| should 118 // If the DownloadDirectory policy is set, then |prompt_for_download_| should
107 // always be false. 119 // always be false.
108 DCHECK(!download_path_.IsManaged() || !prompt_for_download_.GetValue()); 120 DCHECK(!download_path_.IsManaged() || !prompt_for_download_.GetValue());
109 return *prompt_for_download_; 121 return *prompt_for_download_;
110 } 122 }
111 123
112 bool DownloadPrefs::IsDownloadPathManaged() const { 124 bool DownloadPrefs::IsDownloadPathManaged() const {
113 return download_path_.IsManaged(); 125 return download_path_.IsManaged();
114 } 126 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 extensions.erase(extensions.size() - 1); 177 extensions.erase(extensions.size() - 1);
166 178
167 prefs_->SetString(prefs::kDownloadExtensionsToOpen, extensions); 179 prefs_->SetString(prefs::kDownloadExtensionsToOpen, extensions);
168 } 180 }
169 181
170 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( 182 bool DownloadPrefs::AutoOpenCompareFunctor::operator()(
171 const FilePath::StringType& a, 183 const FilePath::StringType& a,
172 const FilePath::StringType& b) const { 184 const FilePath::StringType& b) const {
173 return FilePath::CompareLessIgnoreCase(a, b); 185 return FilePath::CompareLessIgnoreCase(a, b);
174 } 186 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_prefs.h ('k') | chrome/browser/download/download_shelf_context_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698