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

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: review comments and sync 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
« no previous file with comments | « chrome/browser/download/download_manager.h ('k') | chrome/browser/download/download_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 DownloadUrlToFile(url, referrer, referrer_charset, DownloadSaveInfo(), 893 DownloadUrlToFile(url, referrer, referrer_charset, DownloadSaveInfo(),
898 tab_contents); 894 tab_contents);
899 } 895 }
900 896
901 void DownloadManager::DownloadUrlToFile(const GURL& url, 897 void DownloadManager::DownloadUrlToFile(const GURL& url,
902 const GURL& referrer, 898 const GURL& referrer,
903 const std::string& referrer_charset, 899 const std::string& referrer_charset,
904 const DownloadSaveInfo& save_info, 900 const DownloadSaveInfo& save_info,
905 TabContents* tab_contents) { 901 TabContents* tab_contents) {
906 DCHECK(tab_contents); 902 DCHECK(tab_contents);
903 // We send a pointer to content::ResourceContext, instead of the usual
904 // reference, so that a copy of the object isn't made.
907 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 905 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
908 NewRunnableFunction(&download_util::DownloadUrl, 906 NewRunnableFunction(&download_util::DownloadUrl,
909 url, 907 url,
910 referrer, 908 referrer,
911 referrer_charset, 909 referrer_charset,
912 save_info, 910 save_info,
913 g_browser_process->resource_dispatcher_host(), 911 g_browser_process->resource_dispatcher_host(),
914 tab_contents->GetRenderProcessHost()->id(), 912 tab_contents->GetRenderProcessHost()->id(),
915 tab_contents->render_view_host()->routing_id(), 913 tab_contents->render_view_host()->routing_id(),
916 request_context_getter_)); 914 &tab_contents->profile()->GetResourceContext()));
917 } 915 }
918 916
919 void DownloadManager::AddObserver(Observer* observer) { 917 void DownloadManager::AddObserver(Observer* observer) {
920 observers_.AddObserver(observer); 918 observers_.AddObserver(observer);
921 observer->ModelChanged(); 919 observer->ModelChanged();
922 } 920 }
923 921
924 void DownloadManager::RemoveObserver(Observer* observer) { 922 void DownloadManager::RemoveObserver(Observer* observer) {
925 observers_.RemoveObserver(observer); 923 observers_.RemoveObserver(observer);
926 } 924 }
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 observed_download_manager_->RemoveObserver(this); 1175 observed_download_manager_->RemoveObserver(this);
1178 } 1176 }
1179 1177
1180 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { 1178 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() {
1181 observing_download_manager_->NotifyModelChanged(); 1179 observing_download_manager_->NotifyModelChanged();
1182 } 1180 }
1183 1181
1184 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { 1182 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() {
1185 observed_download_manager_ = NULL; 1183 observed_download_manager_ = NULL;
1186 } 1184 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_manager.h ('k') | chrome/browser/download/download_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698