summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-10 00:44:08 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-10 00:44:08 +0000
commit315f55d1c2585d0d9820719ee9653b8119f82ab8 (patch)
tree02da89b2aac8eada800a44693ef0adcbff16d618 /chrome
parent4b4116d2aca7ea0b1756044b8e26fe01e59ddf5a (diff)
downloadchromium_src-315f55d1c2585d0d9820719ee9653b8119f82ab8.zip
chromium_src-315f55d1c2585d0d9820719ee9653b8119f82ab8.tar.gz
chromium_src-315f55d1c2585d0d9820719ee9653b8119f82ab8.tar.bz2
Don't pass WebContents* between threads, since it can go away in the meantime. Instead pass the render process and render view IDs, which we can get a WebContents from later if it's valid.
Also get rid of the proxy class. Now you can do bind::Unretained. Before bind, there was another macro for the NewRunnableMethod which I don't remember off the top of my head (it was used in plugin_service.h). Review URL: http://codereview.chromium.org/9124009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116975 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/ui/webui/chromeos/imageburner/imageburner_utils.cc62
-rw-r--r--chrome/browser/ui/webui/chromeos/imageburner/imageburner_utils.h24
2 files changed, 31 insertions, 55 deletions
diff --git a/chrome/browser/ui/webui/chromeos/imageburner/imageburner_utils.cc b/chrome/browser/ui/webui/chromeos/imageburner/imageburner_utils.cc
index f5493b9..fddd3c8 100644
--- a/chrome/browser/ui/webui/chromeos/imageburner/imageburner_utils.cc
+++ b/chrome/browser/ui/webui/chromeos/imageburner/imageburner_utils.cc
@@ -8,9 +8,12 @@
#include "base/path_service.h"
#include "base/string_util.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/common/chrome_paths.h"
#include "content/browser/download/download_types.h"
+#include "content/browser/renderer_host/render_view_host.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
using content::BrowserThread;
@@ -353,41 +356,6 @@ void BurnManager::ConfigFileFetchedOnUIThread(bool fetched,
////////////////////////////////////////////////////////////////////////////////
//
-// DownloaderTaskProxy
-//
-////////////////////////////////////////////////////////////////////////////////
-
-class DownloaderTaskProxy
- : public base::RefCountedThreadSafe<DownloaderTaskProxy> {
- public:
- explicit DownloaderTaskProxy() {}
-
- void CreateFileStream(const GURL& url,
- const FilePath& target_path,
- WebContents* web_contents) {
- BurnManager::GetInstance()->downloader()->
- CreateFileStreamOnFileThread(url, target_path, web_contents);
- }
-
- void OnFileStreamCreated(const GURL& url,
- const FilePath& file_path,
- WebContents* web_contents,
- net::FileStream* created_file_stream) {
- BurnManager::GetInstance()->downloader()->
- OnFileStreamCreatedOnUIThread(url, file_path, web_contents,
- created_file_stream);
- }
-
- private:
- ~DownloaderTaskProxy() {}
-
- friend class base::RefCountedThreadSafe<DownloaderTaskProxy>;
-
- DISALLOW_COPY_AND_ASSIGN(DownloaderTaskProxy);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-//
// Downloader
//
////////////////////////////////////////////////////////////////////////////////
@@ -400,17 +368,17 @@ void Downloader::DownloadFile(const GURL& url,
const FilePath& file_path, WebContents* web_contents) {
// First we have to create file stream we will download file to.
// That has to be done on File thread.
- scoped_refptr<DownloaderTaskProxy> task = new DownloaderTaskProxy();
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
- base::Bind(&DownloaderTaskProxy::CreateFileStream, task.get(), url,
- file_path, web_contents));
+ base::Bind(&Downloader::CreateFileStreamOnFileThread,
+ base::Unretained(this), url, file_path,
+ web_contents->GetRenderProcessHost()->GetID(),
+ web_contents->GetRenderViewHost()->routing_id()));
}
void Downloader::CreateFileStreamOnFileThread(
- const GURL& url, const FilePath& file_path,
- WebContents* web_contents) {
-
+ const GURL& url, const FilePath& file_path, int render_process_id,
+ int render_view_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
DCHECK(!file_path.empty());
@@ -421,18 +389,22 @@ void Downloader::CreateFileStreamOnFileThread(
base::PLATFORM_FILE_WRITE))
file_stream.reset(NULL);
- scoped_refptr<DownloaderTaskProxy> task = new DownloaderTaskProxy();
// Call callback method on UI thread.
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(&DownloaderTaskProxy::OnFileStreamCreated, task.get(),
- url, file_path, web_contents, file_stream.release()));
+ base::Bind(&Downloader::OnFileStreamCreatedOnUIThread,
+ base::Unretained(this), url, file_path, render_process_id,
+ render_view_id, file_stream.release()));
}
void Downloader::OnFileStreamCreatedOnUIThread(const GURL& url,
- const FilePath& file_path, WebContents* web_contents,
+ const FilePath& file_path, int render_process_id, int render_view_id,
net::FileStream* created_file_stream) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ WebContents* web_contents =
+ tab_util::GetWebContentsByID(render_process_id, render_view_id);
+ if (!web_contents)
+ return;
if (created_file_stream) {
DownloadManager* download_manager =
diff --git a/chrome/browser/ui/webui/chromeos/imageburner/imageburner_utils.h b/chrome/browser/ui/webui/chromeos/imageburner/imageburner_utils.h
index f5050ec..a79a90c 100644
--- a/chrome/browser/ui/webui/chromeos/imageburner/imageburner_utils.h
+++ b/chrome/browser/ui/webui/chromeos/imageburner/imageburner_utils.h
@@ -51,16 +51,6 @@ class Downloader {
void DownloadFile(const GURL& url, const FilePath& target_file,
content::WebContents* web_contents);
- // Creates file stream for a download.
- // Must be called from FILE thread.
- void CreateFileStreamOnFileThread(const GURL& url, const FilePath& file_path,
- content::WebContents* web_contents);
-
- // Gets called after file stream is created and starts download.
- void OnFileStreamCreatedOnUIThread(const GURL& url,
- const FilePath& file_path, content::WebContents* web_contents,
- net::FileStream* created_file_stream);
-
// Adds an item to list of listeners that wait for confirmation that download
// has started.
void AddListener(Listener* listener, const GURL& url);
@@ -69,6 +59,20 @@ class Downloader {
// Let listeners know if download started successfully.
void DownloadStarted(bool success, const GURL& url);
+ // Creates file stream for a download.
+ // Must be called from FILE thread.
+ void CreateFileStreamOnFileThread(const GURL& url,
+ const FilePath& file_path,
+ int render_process_id,
+ int render_view_id);
+
+ // Gets called after file stream is created and starts download.
+ void OnFileStreamCreatedOnUIThread(const GURL& url,
+ const FilePath& file_path,
+ int render_process_id,
+ int render_view_id,
+ net::FileStream* created_file_stream);
+
private:
typedef std::multimap<GURL, base::WeakPtr<Listener> > ListenerMap;
ListenerMap listeners_;