summaryrefslogtreecommitdiffstats
path: root/chrome
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 /chrome
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 'chrome')
-rw-r--r--chrome/browser/extensions/extension_save_page_api.cc40
-rw-r--r--chrome/browser/extensions/extension_save_page_api.h15
2 files changed, 17 insertions, 38 deletions
diff --git a/chrome/browser/extensions/extension_save_page_api.cc b/chrome/browser/extensions/extension_save_page_api.cc
index e9c0386..6a8bde6 100644
--- a/chrome/browser/extensions/extension_save_page_api.cc
+++ b/chrome/browser/extensions/extension_save_page_api.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/extensions/extension_save_page_api.h"
+#include "base/bind.h"
#include "base/file_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_tab_util.h"
@@ -105,46 +106,27 @@ void SavePageAsMHTMLFunction::TemporaryFileCreated(bool success) {
return;
}
- registrar_.Add(
- this, content::NOTIFICATION_MHTML_GENERATED,
- content::Source<RenderViewHost>(tab_contents->render_view_host()));
- // TODO(jcivelli): we should listen for navigation in the tab, tab closed,
- // renderer died.
+ MHTMLGenerationManager::GenerateMHTMLCallback callback =
+ base::Bind(&SavePageAsMHTMLFunction::MHTMLGenerated, this);
+
g_browser_process->mhtml_generation_manager()->GenerateMHTML(
- tab_contents, mhtml_path_);
+ tab_contents, mhtml_path_, callback);
}
-void SavePageAsMHTMLFunction::Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK(type == content::NOTIFICATION_MHTML_GENERATED);
-
- const MHTMLGenerationManager::NotificationDetails* save_details =
- content::Details<MHTMLGenerationManager::NotificationDetails>(details).
- ptr();
-
- if (mhtml_path_ != save_details->file_path) {
- // This could happen if there are concurrent MHTML generations going on for
- // the same tab.
- LOG(WARNING) << "Received a notification that MHTML was generated but for a"
- " different file.";
- return;
- }
-
- registrar_.RemoveAll();
-
- if (save_details->file_size <= 0) {
+void SavePageAsMHTMLFunction::MHTMLGenerated(const FilePath& file_path,
+ int64 mhtml_file_size) {
+ DCHECK(mhtml_path_ == file_path);
+ if (mhtml_file_size <= 0) {
ReturnFailure(kMHTMLGenerationFailedError);
return;
}
- if (save_details->file_size > std::numeric_limits<int>::max()) {
+ if (mhtml_file_size > std::numeric_limits<int>::max()) {
ReturnFailure(kFileTooBigError);
return;
}
- ReturnSuccess(save_details->file_size);
+ ReturnSuccess(mhtml_file_size);
}
void SavePageAsMHTMLFunction::ReturnFailure(const std::string& error) {
diff --git a/chrome/browser/extensions/extension_save_page_api.h b/chrome/browser/extensions/extension_save_page_api.h
index 106cd5a..fc7ce9a 100644
--- a/chrome/browser/extensions/extension_save_page_api.h
+++ b/chrome/browser/extensions/extension_save_page_api.h
@@ -10,12 +10,11 @@
#include "base/memory/ref_counted.h"
#include "chrome/browser/extensions/extension_function.h"
#include "content/browser/tab_contents/tab_contents_observer.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
#include "webkit/blob/deletable_file_reference.h"
-class SavePageAsMHTMLFunction : public AsyncExtensionFunction,
- public content::NotificationObserver {
+class FilePath;
+
+class SavePageAsMHTMLFunction : public AsyncExtensionFunction {
public:
SavePageAsMHTMLFunction();
@@ -31,9 +30,6 @@ class SavePageAsMHTMLFunction : public AsyncExtensionFunction,
private:
virtual ~SavePageAsMHTMLFunction();
virtual bool RunImpl() OVERRIDE;
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
virtual bool OnMessageReceivedFromRenderView(
const IPC::Message& message) OVERRIDE;
@@ -45,6 +41,9 @@ class SavePageAsMHTMLFunction : public AsyncExtensionFunction,
void ReturnFailure(const std::string& error);
void ReturnSuccess(int64 file_size);
+ // Callback called once the MHTML generation is done.
+ void MHTMLGenerated(const FilePath& file_path, int64 mhtml_file_size);
+
// Returns the TabContents we are associated with, NULL if it's been closed.
TabContents* GetTabContents();
@@ -56,8 +55,6 @@ class SavePageAsMHTMLFunction : public AsyncExtensionFunction,
// The file containing the MHTML.
scoped_refptr<webkit_blob::DeletableFileReference> mhtml_file_;
- content::NotificationRegistrar registrar_;
-
DECLARE_EXTENSION_FUNCTION_NAME("experimental.savePage.saveAsMHTML")
};