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

Side by Side Diff: content/browser/download/download_manager_impl.cc

Issue 9150016: Move creation and ownership of ResourceDispatcherHost and PluginService to content. This gives a ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix chromeos ui_tests Created 8 years, 11 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/download/download_manager_impl.h" 5 #include "content/browser/download/download_manager_impl.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 resource_dispatcher_host->BeginDownload( 79 resource_dispatcher_host->BeginDownload(
80 request, save_info, true, 80 request, save_info, true,
81 DownloadResourceHandler::OnStartedCallback(), 81 DownloadResourceHandler::OnStartedCallback(),
82 render_params.render_process_id_, 82 render_params.render_process_id_,
83 render_params.render_view_id_, 83 render_params.render_view_id_,
84 *context); 84 *context);
85 } 85 }
86 86
87 } // namespace 87 } // namespace
88 88
89 namespace content {
90
91 // static
92 DownloadManager* DownloadManager::Create(
93 content::DownloadManagerDelegate* delegate,
94 DownloadIdFactory* id_factory,
95 DownloadStatusUpdater* status_updater) {
96 return new DownloadManagerImpl(delegate, id_factory, status_updater);
97 }
98
99 } // namespace content
100
89 DownloadManagerImpl::DownloadManagerImpl( 101 DownloadManagerImpl::DownloadManagerImpl(
90 content::DownloadManagerDelegate* delegate, 102 content::DownloadManagerDelegate* delegate,
91 DownloadIdFactory* id_factory, 103 DownloadIdFactory* id_factory,
92 DownloadStatusUpdater* status_updater) 104 DownloadStatusUpdater* status_updater)
93 : shutdown_needed_(false), 105 : shutdown_needed_(false),
94 browser_context_(NULL), 106 browser_context_(NULL),
95 file_manager_(NULL), 107 file_manager_(NULL),
96 status_updater_((status_updater != NULL) 108 status_updater_((status_updater != NULL)
97 ? status_updater->AsWeakPtr() 109 ? status_updater->AsWeakPtr()
98 : base::WeakPtr<DownloadStatusUpdater>()), 110 : base::WeakPtr<DownloadStatusUpdater>()),
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 bool DownloadManagerImpl::Init(content::BrowserContext* browser_context) { 255 bool DownloadManagerImpl::Init(content::BrowserContext* browser_context) {
244 DCHECK(browser_context); 256 DCHECK(browser_context);
245 DCHECK(!shutdown_needed_) << "DownloadManager already initialized."; 257 DCHECK(!shutdown_needed_) << "DownloadManager already initialized.";
246 shutdown_needed_ = true; 258 shutdown_needed_ = true;
247 259
248 browser_context_ = browser_context; 260 browser_context_ = browser_context;
249 261
250 // In test mode, there may be no ResourceDispatcherHost. In this case it's 262 // In test mode, there may be no ResourceDispatcherHost. In this case it's
251 // safe to avoid setting |file_manager_| because we only call a small set of 263 // safe to avoid setting |file_manager_| because we only call a small set of
252 // functions, none of which need it. 264 // functions, none of which need it.
253 ResourceDispatcherHost* rdh = 265 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
254 content::GetContentClient()->browser()->GetResourceDispatcherHost();
255 if (rdh) { 266 if (rdh) {
256 file_manager_ = rdh->download_file_manager(); 267 file_manager_ = rdh->download_file_manager();
257 DCHECK(file_manager_); 268 DCHECK(file_manager_);
258 } 269 }
259 270
260 return true; 271 return true;
261 } 272 }
262 273
263 // We have received a message from DownloadFileManager about a new download. 274 // We have received a message from DownloadFileManager about a new download.
264 void DownloadManagerImpl::StartDownload(int32 download_id) { 275 void DownloadManagerImpl::StartDownload(int32 download_id) {
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 DownloadUrlToFile(url, referrer, referrer_charset, DownloadSaveInfo(), 785 DownloadUrlToFile(url, referrer, referrer_charset, DownloadSaveInfo(),
775 web_contents); 786 web_contents);
776 } 787 }
777 788
778 void DownloadManagerImpl::DownloadUrlToFile(const GURL& url, 789 void DownloadManagerImpl::DownloadUrlToFile(const GURL& url,
779 const GURL& referrer, 790 const GURL& referrer,
780 const std::string& referrer_charset, 791 const std::string& referrer_charset,
781 const DownloadSaveInfo& save_info, 792 const DownloadSaveInfo& save_info,
782 WebContents* web_contents) { 793 WebContents* web_contents) {
783 ResourceDispatcherHost* resource_dispatcher_host = 794 ResourceDispatcherHost* resource_dispatcher_host =
784 content::GetContentClient()->browser()->GetResourceDispatcherHost(); 795 ResourceDispatcherHost::Get();
785 796
786 // We send a pointer to content::ResourceContext, instead of the usual 797 // We send a pointer to content::ResourceContext, instead of the usual
787 // reference, so that a copy of the object isn't made. 798 // reference, so that a copy of the object isn't made.
788 // base::Bind can't handle 7 args, so we use URLParams and RenderParams. 799 // base::Bind can't handle 7 args, so we use URLParams and RenderParams.
789 BrowserThread::PostTask( 800 BrowserThread::PostTask(
790 BrowserThread::IO, FROM_HERE, 801 BrowserThread::IO, FROM_HERE,
791 base::Bind(&BeginDownload, 802 base::Bind(&BeginDownload,
792 URLParams(url, referrer), save_info, resource_dispatcher_host, 803 URLParams(url, referrer), save_info, resource_dispatcher_host,
793 RenderParams(web_contents->GetRenderProcessHost()->GetID(), 804 RenderParams(web_contents->GetRenderProcessHost()->GetID(),
794 web_contents->GetRenderViewHost()->routing_id()), 805 web_contents->GetRenderViewHost()->routing_id()),
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 it != history_downloads_.end(); ++it) { 1157 it != history_downloads_.end(); ++it) {
1147 if (it->second->IsComplete() && !it->second->GetOpened()) 1158 if (it->second->IsComplete() && !it->second->GetOpened())
1148 ++num_unopened; 1159 ++num_unopened;
1149 } 1160 }
1150 download_stats::RecordOpensOutstanding(num_unopened); 1161 download_stats::RecordOpensOutstanding(num_unopened);
1151 } 1162 }
1152 1163
1153 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { 1164 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) {
1154 file_manager_ = file_manager; 1165 file_manager_ = file_manager;
1155 } 1166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698