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

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: Improved isolation of MockDownloadManager. 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 ChromeDownloadManagerDelegate* delegate =
ahendrickson 2011/11/29 21:40:15 This part should call FromDownloadManager().
Randy Smith (Not in Mondays) 2011/11/30 22:44:05 Ok, but long term I want to get DownloadManager ou
115 static_cast<ChromeDownloadManagerDelegate*>(
116 download_service->GetDownloadManager()->delegate());
117 return delegate->download_prefs();
118 }
119
105 bool DownloadPrefs::PromptForDownload() const { 120 bool DownloadPrefs::PromptForDownload() const {
106 // If the DownloadDirectory policy is set, then |prompt_for_download_| should 121 // If the DownloadDirectory policy is set, then |prompt_for_download_| should
107 // always be false. 122 // always be false.
108 DCHECK(!download_path_.IsManaged() || !prompt_for_download_.GetValue()); 123 DCHECK(!download_path_.IsManaged() || !prompt_for_download_.GetValue());
109 return *prompt_for_download_; 124 return *prompt_for_download_;
110 } 125 }
111 126
112 bool DownloadPrefs::IsDownloadPathManaged() const { 127 bool DownloadPrefs::IsDownloadPathManaged() const {
113 return download_path_.IsManaged(); 128 return download_path_.IsManaged();
114 } 129 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 extensions.erase(extensions.size() - 1); 180 extensions.erase(extensions.size() - 1);
166 181
167 prefs_->SetString(prefs::kDownloadExtensionsToOpen, extensions); 182 prefs_->SetString(prefs::kDownloadExtensionsToOpen, extensions);
168 } 183 }
169 184
170 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( 185 bool DownloadPrefs::AutoOpenCompareFunctor::operator()(
171 const FilePath::StringType& a, 186 const FilePath::StringType& a,
172 const FilePath::StringType& b) const { 187 const FilePath::StringType& b) const {
173 return FilePath::CompareLessIgnoreCase(a, b); 188 return FilePath::CompareLessIgnoreCase(a, b);
174 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698