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

Unified Diff: chrome/browser/plugin_download_helper.cc

Issue 8851007: WIP / Do not commit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/plugin_download_helper.h ('k') | chrome/browser/plugin_installer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/plugin_download_helper.cc
diff --git a/chrome/browser/plugin_download_helper.cc b/chrome/browser/plugin_download_helper.cc
index 0621a6a6be7a19cadd03a1898b28b2f5219867f5..c08e863b513526baa98c0a3e3e8cdc426c4e01c6 100644
--- a/chrome/browser/plugin_download_helper.cc
+++ b/chrome/browser/plugin_download_helper.cc
@@ -4,80 +4,74 @@
#include "chrome/browser/plugin_download_helper.h"
-#include <windows.h>
-
+#include "base/bind.h"
#include "base/file_util.h"
+#include "base/message_loop_proxy.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/url_fetcher.h"
-#include "net/base/io_buffer.h"
+#include "net/base/net_errors.h"
+#include "net/url_request/url_request_status.h"
+
+using content::BrowserThread;
-PluginDownloadUrlHelper::PluginDownloadUrlHelper(
- const std::string& download_url,
- gfx::NativeWindow caller_window,
- PluginDownloadUrlHelper::DownloadDelegate* delegate)
- : download_file_fetcher_(NULL),
- download_file_caller_window_(caller_window),
- download_url_(download_url),
- delegate_(delegate) {
+PluginDownloadUrlHelper::PluginDownloadUrlHelper() {
}
PluginDownloadUrlHelper::~PluginDownloadUrlHelper() {
}
void PluginDownloadUrlHelper::InitiateDownload(
+ const GURL& download_url,
net::URLRequestContextGetter* request_context,
- base::MessageLoopProxy* file_thread_proxy) {
+ const DownloadFinishedCallback& callback) {
+ download_url_ = download_url;
+ callback_ = callback;
download_file_fetcher_.reset(content::URLFetcher::Create(
- GURL(download_url_), content::URLFetcher::GET, this));
+ download_url_, content::URLFetcher::GET, this));
download_file_fetcher_->SetRequestContext(request_context);
- download_file_fetcher_->SaveResponseToTemporaryFile(file_thread_proxy);
+ download_file_fetcher_->SaveResponseToTemporaryFile(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
download_file_fetcher_->Start();
}
void PluginDownloadUrlHelper::OnURLFetchComplete(
const content::URLFetcher* source) {
- bool success = source->GetStatus().is_success();
- FilePath response_file;
+ net::URLRequestStatus status = source->GetStatus();
+ if (status.is_success()) {
+ bool success = source->GetResponseAsFilePath(true, &downloaded_file_);
+ DCHECK(success);
+ BrowserThread::PostTaskAndReply(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&PluginDownloadUrlHelper::RenameDownloadedFile,
+ base::Unretained(this)),
+ base::Bind(&PluginDownloadUrlHelper::RunCallback,
+ base::Unretained(this)));
+ } else {
+ NOTREACHED() << "Failed to download the plugin installer: "
+ << net::ErrorToString(status.error());
+ RunCallback();
+ }
+}
- if (success) {
- if (source->GetResponseAsFilePath(true, &response_file)) {
- FilePath new_download_file_path =
- response_file.DirName().AppendASCII(
- download_file_fetcher_->GetURL().ExtractFileName());
+void PluginDownloadUrlHelper::RenameDownloadedFile() {
+ FilePath new_download_file_path =
+ downloaded_file_.DirName().AppendASCII(
+ download_file_fetcher_->GetURL().ExtractFileName());
- file_util::Delete(new_download_file_path, false);
+ file_util::Delete(new_download_file_path, false);
- if (!file_util::ReplaceFileW(response_file,
- new_download_file_path)) {
- DLOG(ERROR) << "Failed to rename file:"
- << response_file.value()
- << " to file:"
- << new_download_file_path.value();
- } else {
- response_file = new_download_file_path;
- }
- } else {
- NOTREACHED() << "Failed to download the plugin installer.";
- success = false;
- }
- }
-
- if (delegate_) {
- delegate_->OnDownloadCompleted(response_file, success);
+ if (file_util::ReplaceFile(downloaded_file_,
+ new_download_file_path)) {
+ downloaded_file_ = new_download_file_path;
} else {
- std::wstring path = response_file.value();
- COPYDATASTRUCT download_file_data = {0};
- download_file_data.cbData =
- static_cast<unsigned long>((path.length() + 1) * sizeof(wchar_t));
- download_file_data.lpData = const_cast<wchar_t *>(path.c_str());
- download_file_data.dwData = success;
-
- if (::IsWindow(download_file_caller_window_)) {
- ::SendMessage(download_file_caller_window_, WM_COPYDATA, NULL,
- reinterpret_cast<LPARAM>(&download_file_data));
- }
+ DPLOG(ERROR) << "Failed to rename file: "
+ << downloaded_file_.value()
+ << " to file: "
+ << new_download_file_path.value();
}
- // Don't access any members after this.
- delete this;
}
+void PluginDownloadUrlHelper::RunCallback() {
+ callback_.Run(downloaded_file_);
+ delete this;
+}
« no previous file with comments | « chrome/browser/plugin_download_helper.h ('k') | chrome/browser/plugin_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698