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

Unified Diff: chrome/browser/plugins/plugin_installer.cc

Issue 230163002: Use DownloadManager to initiate downloads from PluginInstaller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/plugins/plugin_installer.h ('k') | chrome/browser/plugins/plugin_installer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/plugins/plugin_installer.cc
diff --git a/chrome/browser/plugins/plugin_installer.cc b/chrome/browser/plugins/plugin_installer.cc
index e9322a9abc76db0c0ab2ab0514ebc193befffaa8..7c5ae8520435a6b8f6fafa14b188b7bc7b47c199 100644
--- a/chrome/browser/plugins/plugin_installer.cc
+++ b/chrome/browser/plugins/plugin_installer.cc
@@ -8,66 +8,16 @@
#include "base/bind_helpers.h"
#include "base/process/process.h"
#include "base/strings/stringprintf.h"
-#include "chrome/browser/download/download_service.h"
-#include "chrome/browser/download/download_service_factory.h"
#include "chrome/browser/download/download_stats.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/plugins/plugin_installer_observer.h"
-#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/browser_context.h"
-#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_item.h"
-#include "content/public/browser/download_save_info.h"
+#include "content/public/browser/download_manager.h"
#include "content/public/browser/download_url_parameters.h"
-#include "content/public/browser/render_process_host.h"
-#include "content/public/browser/render_view_host.h"
-#include "content/public/browser/resource_context.h"
-#include "content/public/browser/resource_dispatcher_host.h"
#include "content/public/browser/web_contents.h"
-#include "content/public/common/referrer.h"
-#include "net/base/request_priority.h"
-#include "net/url_request/url_request.h"
-#include "net/url_request/url_request_context.h"
-using content::BrowserContext;
-using content::BrowserThread;
using content::DownloadItem;
-using content::ResourceDispatcherHost;
-
-namespace {
-
-void BeginDownload(
- const GURL& url,
- content::ResourceContext* resource_context,
- int render_process_host_id,
- int render_view_host_routing_id,
- const ResourceDispatcherHost::DownloadStartedCallback& callback) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
- scoped_ptr<net::URLRequest> request(
- resource_context->GetRequestContext()->CreateRequest(
- url, net::DEFAULT_PRIORITY, NULL, NULL));
- content::DownloadInterruptReason error = rdh->BeginDownload(
- request.Pass(),
- content::Referrer(),
- false, // is_content_initiated
- resource_context,
- render_process_host_id,
- render_view_host_routing_id,
- true, // prefer_cache
- scoped_ptr<content::DownloadSaveInfo>(new content::DownloadSaveInfo()),
- content::DownloadItem::kInvalidId,
- callback);
-
- if (error != content::DOWNLOAD_INTERRUPT_REASON_NONE) {
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(callback, static_cast<DownloadItem*>(NULL), error));
- }
-}
-
-} // namespace
PluginInstaller::PluginInstaller()
: state_(INSTALLER_STATE_IDLE),
@@ -137,28 +87,33 @@ void PluginInstaller::RemoveWeakObserver(
void PluginInstaller::StartInstalling(const GURL& plugin_url,
content::WebContents* web_contents) {
+ content::DownloadManager* download_manager =
+ content::BrowserContext::GetDownloadManager(
+ web_contents->GetBrowserContext());
+ StartInstallingWithDownloadManager(
+ plugin_url, web_contents, download_manager);
+}
+
+void PluginInstaller::StartInstallingWithDownloadManager(
+ const GURL& plugin_url,
+ content::WebContents* web_contents,
+ content::DownloadManager* download_manager) {
DCHECK_EQ(INSTALLER_STATE_IDLE, state_);
state_ = INSTALLER_STATE_DOWNLOADING;
FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadStarted());
- Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
+ scoped_ptr<content::DownloadUrlParameters> download_parameters(
+ content::DownloadUrlParameters::FromWebContents(web_contents,
+ plugin_url));
+ download_parameters->set_callback(
+ base::Bind(&PluginInstaller::DownloadStarted, base::Unretained(this)));
RecordDownloadSource(DOWNLOAD_INITIATED_BY_PLUGIN_INSTALLER);
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&BeginDownload,
- plugin_url,
- profile->GetResourceContext(),
- web_contents->GetRenderProcessHost()->GetID(),
- web_contents->GetRenderViewHost()->GetRoutingID(),
- base::Bind(&PluginInstaller::DownloadStarted,
- base::Unretained(this))));
+ download_manager->DownloadUrl(download_parameters.Pass());
}
void PluginInstaller::DownloadStarted(
content::DownloadItem* item,
content::DownloadInterruptReason interrupt_reason) {
- if (!item) {
- DCHECK_NE(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason);
+ if (interrupt_reason != content::DOWNLOAD_INTERRUPT_REASON_NONE) {
std::string msg = base::StringPrintf(
"Error %d: %s",
interrupt_reason,
@@ -166,7 +121,6 @@ void PluginInstaller::DownloadStarted(
DownloadError(msg);
return;
}
- DCHECK_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason);
item->SetOpenWhenComplete(true);
item->AddObserver(this);
}
« no previous file with comments | « chrome/browser/plugins/plugin_installer.h ('k') | chrome/browser/plugins/plugin_installer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698