summaryrefslogtreecommitdiffstats
path: root/content/browser/download
diff options
context:
space:
mode:
authorjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-23 07:53:03 +0000
committerjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-23 07:53:03 +0000
commit7477b27103e20e1898b1c2846f2fc3e08d498576 (patch)
treeb990aa062f0eed3a3f991e8dbe9a098579c427af /content/browser/download
parent18190be0f8b14992da55e25ecadebc55b879c780 (diff)
downloadchromium_src-7477b27103e20e1898b1c2846f2fc3e08d498576.zip
chromium_src-7477b27103e20e1898b1c2846f2fc3e08d498576.tar.gz
chromium_src-7477b27103e20e1898b1c2846f2fc3e08d498576.tar.bz2
Switch MHTMLGenerationManager to use a Callback.
Relanding: MHTMLGenerationManager now uses a callback instead of a notification. BUG=None TEST=MHTML generation (via extension API should still work). TBR=jam Review URL: http://codereview.chromium.org/8674002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111328 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/download')
-rw-r--r--content/browser/download/mhtml_generation_browsertest.cc33
-rw-r--r--content/browser/download/mhtml_generation_manager.cc20
-rw-r--r--content/browser/download/mhtml_generation_manager.h17
3 files changed, 39 insertions, 31 deletions
diff --git a/content/browser/download/mhtml_generation_browsertest.cc b/content/browser/download/mhtml_generation_browsertest.cc
index 8e19f19..4b81e35 100644
--- a/content/browser/download/mhtml_generation_browsertest.cc
+++ b/content/browser/download/mhtml_generation_browsertest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
#include "base/file_path.h"
#include "base/scoped_temp_dir.h"
#include "chrome/browser/ui/browser.h"
@@ -10,7 +11,6 @@
#include "chrome/test/base/ui_test_utils.h"
#include "content/browser/download/mhtml_generation_manager.h"
#include "content/browser/tab_contents/tab_contents.h"
-#include "content/public/browser/notification_types.h"
#include "net/test/test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -18,7 +18,13 @@ namespace {
class MHTMLGenerationTest : public InProcessBrowserTest {
public:
- MHTMLGenerationTest() {}
+ MHTMLGenerationTest() : mhtml_generated_(false), file_size_(0) {}
+
+ void MHTMLGenerated(const FilePath& path, int64 size) {
+ mhtml_generated_ = true;
+ file_size_ = size;
+ MessageLoopForUI::current()->Quit();
+ }
protected:
virtual void SetUp() {
@@ -26,7 +32,14 @@ class MHTMLGenerationTest : public InProcessBrowserTest {
InProcessBrowserTest::SetUp();
}
+ bool mhtml_generated() const { return mhtml_generated_; }
+ int64 file_size() const { return file_size_; }
+
ScopedTempDir temp_dir_;
+
+ private:
+ bool mhtml_generated_;
+ int64 file_size_;
};
// Tests that generating a MHTML does create contents.
@@ -46,16 +59,14 @@ IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateMHTML) {
MHTMLGenerationManager* mhtml_generation_manager =
g_browser_process->mhtml_generation_manager();
- content::Source<RenderViewHost> source(tab->render_view_host());
- ui_test_utils::WindowedNotificationObserverWithDetails<
- MHTMLGenerationManager::NotificationDetails> signal(
- content::NOTIFICATION_MHTML_GENERATED, source);
- mhtml_generation_manager->GenerateMHTML(tab, path);
- signal.Wait();
+ mhtml_generation_manager->GenerateMHTML(tab, path,
+ base::Bind(&MHTMLGenerationTest::MHTMLGenerated, this));
+
+ // Block until the MHTML is generated.
+ ui_test_utils::RunMessageLoop();
- MHTMLGenerationManager::NotificationDetails details;
- ASSERT_TRUE(signal.GetDetailsFor(source.map_key(), &details));
- ASSERT_GT(details.file_size, 0);
+ EXPECT_TRUE(mhtml_generated());
+ EXPECT_GT(file_size(), 0);
// Make sure the actual generated file has some contents.
int64 file_size;
diff --git a/content/browser/download/mhtml_generation_manager.cc b/content/browser/download/mhtml_generation_manager.cc
index 7a63009..2251c1f 100644
--- a/content/browser/download/mhtml_generation_manager.cc
+++ b/content/browser/download/mhtml_generation_manager.cc
@@ -22,6 +22,9 @@ MHTMLGenerationManager::Job::Job()
routing_id(-1) {
}
+MHTMLGenerationManager::Job::~Job() {
+}
+
MHTMLGenerationManager::MHTMLGenerationManager() {
}
@@ -29,7 +32,8 @@ MHTMLGenerationManager::~MHTMLGenerationManager() {
}
void MHTMLGenerationManager::GenerateMHTML(TabContents* tab_contents,
- const FilePath& file) {
+ const FilePath& file,
+ const GenerateMHTMLCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
static int id_counter = 0;
@@ -38,6 +42,7 @@ void MHTMLGenerationManager::GenerateMHTML(TabContents* tab_contents,
job.file_path = file;
job.process_id = tab_contents->GetRenderProcessHost()->GetID();
job.routing_id = tab_contents->render_view_host()->routing_id();
+ job.callback = callback;
id_to_job_[job_id] = job;
base::ProcessHandle renderer_process =
@@ -109,18 +114,7 @@ void MHTMLGenerationManager::JobFinished(int job_id, int64 file_size) {
}
Job& job = iter->second;
-
- RenderViewHost* rvh = RenderViewHost::FromID(job.process_id, job.routing_id);
- if (rvh) {
- NotificationDetails details;
- details.file_path = job.file_path;
- details.file_size = file_size;
-
- content::NotificationService::current()->Notify(
- content::NOTIFICATION_MHTML_GENERATED,
- content::Source<RenderViewHost>(rvh),
- content::Details<NotificationDetails>(&details));
- }
+ job.callback.Run(job.file_path, file_size);
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
base::Bind(&MHTMLGenerationManager::CloseFile, this, job.browser_file));
diff --git a/content/browser/download/mhtml_generation_manager.h b/content/browser/download/mhtml_generation_manager.h
index eeb6b04..0190657 100644
--- a/content/browser/download/mhtml_generation_manager.h
+++ b/content/browser/download/mhtml_generation_manager.h
@@ -24,24 +24,24 @@ class CONTENT_EXPORT MHTMLGenerationManager
MHTMLGenerationManager();
~MHTMLGenerationManager();
+ typedef base::Callback<void(const FilePath& /* path to the MHTML file */,
+ int64 /* size of the file */)> GenerateMHTMLCallback;
+
// Instructs the render view to generate a MHTML representation of the current
// page for |tab_contents|.
- void GenerateMHTML(TabContents* tab_contents, const FilePath& file);
+ void GenerateMHTML(TabContents* tab_contents,
+ const FilePath& file,
+ const GenerateMHTMLCallback& callback);
// Notification from the renderer that the MHTML generation finished.
// |mhtml_data_size| contains the size in bytes of the generated MHTML data,
// or -1 in case of failure.
void MHTMLGenerated(int job_id, int64 mhtml_data_size);
- // The details sent along with the MHTML_GENERATED notification.
- struct NotificationDetails {
- FilePath file_path;
- int64 file_size;
- };
-
private:
struct Job{
Job();
+ ~Job();
FilePath file_path;
@@ -53,6 +53,9 @@ class CONTENT_EXPORT MHTMLGenerationManager
// The IDs mapping to a specific tab.
int process_id;
int routing_id;
+
+ // The callback to call once generation is complete.
+ GenerateMHTMLCallback callback;
};
// Called on the file thread to create |file|.