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

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

Issue 6995013: More progress towards removing content settings code from the content layer. We can't use Cookie... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix net_unittests Created 9 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) 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_manager.h" 5 #include "chrome/browser/download/download_manager.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/rand_util.h" 12 #include "base/rand_util.h"
13 #include "base/stl_util-inl.h" 13 #include "base/stl_util-inl.h"
14 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
15 #include "base/sys_string_conversions.h" 15 #include "base/sys_string_conversions.h"
16 #include "base/task.h" 16 #include "base/task.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/download/download_extensions.h" 20 #include "chrome/browser/download/download_extensions.h"
21 #include "chrome/browser/download/download_file_manager.h" 21 #include "chrome/browser/download/download_file_manager.h"
22 #include "chrome/browser/download/download_history.h" 22 #include "chrome/browser/download/download_history.h"
23 #include "chrome/browser/download/download_item.h" 23 #include "chrome/browser/download/download_item.h"
24 #include "chrome/browser/download/download_prefs.h" 24 #include "chrome/browser/download/download_prefs.h"
25 #include "chrome/browser/download/download_safe_browsing_client.h" 25 #include "chrome/browser/download/download_safe_browsing_client.h"
26 #include "chrome/browser/download/download_status_updater.h" 26 #include "chrome/browser/download/download_status_updater.h"
27 #include "chrome/browser/download/download_util.h" 27 #include "chrome/browser/download/download_util.h"
28 #include "chrome/browser/extensions/extension_service.h" 28 #include "chrome/browser/extensions/extension_service.h"
29 #include "chrome/browser/history/download_create_info.h" 29 #include "chrome/browser/history/download_create_info.h"
30 #include "chrome/browser/net/chrome_url_request_context.h"
31 #include "chrome/browser/platform_util.h" 30 #include "chrome/browser/platform_util.h"
32 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
33 #include "chrome/browser/tab_contents/tab_util.h" 32 #include "chrome/browser/tab_contents/tab_util.h"
34 #include "chrome/browser/ui/browser.h" 33 #include "chrome/browser/ui/browser.h"
35 #include "chrome/browser/ui/browser_list.h" 34 #include "chrome/browser/ui/browser_list.h"
36 #include "chrome/common/chrome_paths.h" 35 #include "chrome/common/chrome_paths.h"
37 #include "content/browser/browser_thread.h" 36 #include "content/browser/browser_thread.h"
38 #include "content/browser/renderer_host/render_process_host.h" 37 #include "content/browser/renderer_host/render_process_host.h"
39 #include "content/browser/renderer_host/render_view_host.h" 38 #include "content/browser/renderer_host/render_view_host.h"
40 #include "content/browser/renderer_host/resource_dispatcher_host.h" 39 #include "content/browser/renderer_host/resource_dispatcher_host.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 file_manager_ = NULL; 122 file_manager_ = NULL;
124 123
125 // Make sure the save as dialog doesn't notify us back if we're gone before 124 // Make sure the save as dialog doesn't notify us back if we're gone before
126 // it returns. 125 // it returns.
127 if (select_file_dialog_.get()) 126 if (select_file_dialog_.get())
128 select_file_dialog_->ListenerDestroyed(); 127 select_file_dialog_->ListenerDestroyed();
129 128
130 download_history_.reset(); 129 download_history_.reset();
131 download_prefs_.reset(); 130 download_prefs_.reset();
132 131
133 request_context_getter_ = NULL;
134
135 shutdown_needed_ = false; 132 shutdown_needed_ = false;
136 } 133 }
137 134
138 void DownloadManager::GetTemporaryDownloads( 135 void DownloadManager::GetTemporaryDownloads(
139 const FilePath& dir_path, std::vector<DownloadItem*>* result) { 136 const FilePath& dir_path, std::vector<DownloadItem*>* result) {
140 DCHECK(result); 137 DCHECK(result);
141 138
142 for (DownloadMap::iterator it = history_downloads_.begin(); 139 for (DownloadMap::iterator it = history_downloads_.begin();
143 it != history_downloads_.end(); ++it) { 140 it != history_downloads_.end(); ++it) {
144 if (it->second->is_temporary() && 141 if (it->second->is_temporary() &&
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 original_profile->GetDownloadManager()->SearchDownloads(query, result); 214 original_profile->GetDownloadManager()->SearchDownloads(query, result);
218 } 215 }
219 216
220 // Query the history service for information about all persisted downloads. 217 // Query the history service for information about all persisted downloads.
221 bool DownloadManager::Init(Profile* profile) { 218 bool DownloadManager::Init(Profile* profile) {
222 DCHECK(profile); 219 DCHECK(profile);
223 DCHECK(!shutdown_needed_) << "DownloadManager already initialized."; 220 DCHECK(!shutdown_needed_) << "DownloadManager already initialized.";
224 shutdown_needed_ = true; 221 shutdown_needed_ = true;
225 222
226 profile_ = profile; 223 profile_ = profile;
227 request_context_getter_ = profile_->GetRequestContext();
228 download_history_.reset(new DownloadHistory(profile)); 224 download_history_.reset(new DownloadHistory(profile));
229 download_history_->Load( 225 download_history_->Load(
230 NewCallback(this, &DownloadManager::OnQueryDownloadEntriesComplete)); 226 NewCallback(this, &DownloadManager::OnQueryDownloadEntriesComplete));
231 227
232 download_prefs_.reset(new DownloadPrefs(profile_->GetPrefs())); 228 download_prefs_.reset(new DownloadPrefs(profile_->GetPrefs()));
233 229
234 // In test mode, there may be no ResourceDispatcherHost. In this case it's 230 // In test mode, there may be no ResourceDispatcherHost. In this case it's
235 // safe to avoid setting |file_manager_| because we only call a small set of 231 // safe to avoid setting |file_manager_| because we only call a small set of
236 // functions, none of which need it. 232 // functions, none of which need it.
237 ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host(); 233 ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host();
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 DownloadUrlToFile(url, referrer, referrer_charset, DownloadSaveInfo(), 891 DownloadUrlToFile(url, referrer, referrer_charset, DownloadSaveInfo(),
896 tab_contents); 892 tab_contents);
897 } 893 }
898 894
899 void DownloadManager::DownloadUrlToFile(const GURL& url, 895 void DownloadManager::DownloadUrlToFile(const GURL& url,
900 const GURL& referrer, 896 const GURL& referrer,
901 const std::string& referrer_charset, 897 const std::string& referrer_charset,
902 const DownloadSaveInfo& save_info, 898 const DownloadSaveInfo& save_info,
903 TabContents* tab_contents) { 899 TabContents* tab_contents) {
904 DCHECK(tab_contents); 900 DCHECK(tab_contents);
901 // We send a pointer to content::ResourceContext, instead of the usual
902 // reference, so that a copy of the object isn't made.
905 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 903 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
906 NewRunnableFunction(&download_util::DownloadUrl, 904 NewRunnableFunction(&download_util::DownloadUrl,
907 url, 905 url,
908 referrer, 906 referrer,
909 referrer_charset, 907 referrer_charset,
910 save_info, 908 save_info,
911 g_browser_process->resource_dispatcher_host(), 909 g_browser_process->resource_dispatcher_host(),
912 tab_contents->GetRenderProcessHost()->id(), 910 tab_contents->GetRenderProcessHost()->id(),
913 tab_contents->render_view_host()->routing_id(), 911 tab_contents->render_view_host()->routing_id(),
914 request_context_getter_)); 912 &tab_contents->profile()->GetResourceContext()));
915 } 913 }
916 914
917 void DownloadManager::AddObserver(Observer* observer) { 915 void DownloadManager::AddObserver(Observer* observer) {
918 observers_.AddObserver(observer); 916 observers_.AddObserver(observer);
919 observer->ModelChanged(); 917 observer->ModelChanged();
920 } 918 }
921 919
922 void DownloadManager::RemoveObserver(Observer* observer) { 920 void DownloadManager::RemoveObserver(Observer* observer) {
923 observers_.RemoveObserver(observer); 921 observers_.RemoveObserver(observer);
924 } 922 }
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 observed_download_manager_->RemoveObserver(this); 1173 observed_download_manager_->RemoveObserver(this);
1176 } 1174 }
1177 1175
1178 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { 1176 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() {
1179 observing_download_manager_->NotifyModelChanged(); 1177 observing_download_manager_->NotifyModelChanged();
1180 } 1178 }
1181 1179
1182 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { 1180 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() {
1183 observed_download_manager_ = NULL; 1181 observed_download_manager_ = NULL;
1184 } 1182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698