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

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

Issue 8674002: Switch MHTMLGenerationManager to use a Callback. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
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
diff --git a/chrome/browser/extensions/extension_save_page_api.cc b/chrome/browser/extensions/extension_save_page_api.cc
index e9c03869c10d88bc31506aa3bfd9a5d70b7f9127..6a8bde65aa79de6619f89e8231c4f904e5b82584 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) {
« 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