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

Unified Diff: chrome/browser/extensions/extension_save_page_api.cc

Issue 8672001: Revert 111252 - Switch MHTMLGenerationManager to use a Callback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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
Index: chrome/browser/extensions/extension_save_page_api.cc
===================================================================
--- chrome/browser/extensions/extension_save_page_api.cc (revision 111255)
+++ chrome/browser/extensions/extension_save_page_api.cc (working copy)
@@ -4,7 +4,6 @@
#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"
@@ -106,27 +105,46 @@
return;
}
- MHTMLGenerationManager::GenerateMHTMLCallback callback =
- base::Bind(&SavePageAsMHTMLFunction::MHTMLGenerated, this);
-
+ 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.
g_browser_process->mhtml_generation_manager()->GenerateMHTML(
- tab_contents, mhtml_path_, callback);
+ tab_contents, mhtml_path_);
}
-void SavePageAsMHTMLFunction::MHTMLGenerated(const FilePath& file_path,
- int64 mhtml_file_size) {
- DCHECK(mhtml_path_ == file_path);
- if (mhtml_file_size <= 0) {
+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) {
ReturnFailure(kMHTMLGenerationFailedError);
return;
}
- if (mhtml_file_size > std::numeric_limits<int>::max()) {
+ if (save_details->file_size > std::numeric_limits<int>::max()) {
ReturnFailure(kFileTooBigError);
return;
}
- ReturnSuccess(mhtml_file_size);
+ ReturnSuccess(save_details->file_size);
}
void SavePageAsMHTMLFunction::ReturnFailure(const std::string& error) {
« no previous file with comments | « chrome/browser/extensions/extension_save_page_api.h ('k') | content/browser/download/mhtml_generation_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698