Commit 7712e62e authored by rbpotter's avatar rbpotter Committed by Commit bot

Remove print preview RFH before closing incognito mode

Unlike for prints from the system dialog, when printing from print
preview the RenderFrameHost is retained by print preview dialog
controller and the preview WebContentses are kept alive by the
controller and the background printing manager. This causes a CHECK
failure in ProfileDestroyer if a print job is still spooling when an
incognito window is closed. Since NOTIFICATION_PROFILE_DESTROYED is
deprecated and using a KeyedServiceShutdownNotifierFactory does not
notify in time, remove these RFHs in browser shutdown directly.

Note that this will have the effect of terminating any print jobs
that have not been completely rendered, so if the incognito window
is closed before a print job is finished, the document will not be
printed completely.

BUG=579155

Review-Url: https://codereview.chromium.org/2746903005
Cr-Commit-Position: refs/heads/master@{#457524}
parent c9650610
......@@ -19,6 +19,7 @@
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
using content::BrowserContext;
using content::BrowserThread;
using content::WebContents;
......@@ -97,6 +98,21 @@ void BackgroundPrintingManager::Observe(
DeletePreviewContents(content::Source<WebContents>(source).ptr());
}
void BackgroundPrintingManager::DeletePreviewContentsForBrowserContext(
BrowserContext* browser_context) {
std::vector<WebContents*> preview_contents_to_delete;
for (const auto& iter : printing_contents_map_) {
WebContents* preview_contents = iter.first;
if (preview_contents->GetBrowserContext() == browser_context) {
preview_contents_to_delete.push_back(preview_contents);
}
}
for (size_t i = 0; i < preview_contents_to_delete.size(); i++) {
DeletePreviewContents(preview_contents_to_delete[i]);
}
}
void BackgroundPrintingManager::DeletePreviewContents(
WebContents* preview_contents) {
auto i = printing_contents_map_.find(preview_contents);
......
......@@ -17,6 +17,7 @@
namespace content {
class WebContents;
class BrowserContext;
}
namespace printing {
......@@ -44,6 +45,10 @@ class BackgroundPrintingManager : public base::NonThreadSafe,
// Let others see the list of background printing contents.
std::set<content::WebContents*> CurrentContentSet();
// Delete all preview contents that are associated with |browser_context|.
void DeletePreviewContentsForBrowserContext(
content::BrowserContext* browser_context);
private:
// content::NotificationObserver overrides:
void Observe(int type,
......
......@@ -68,6 +68,7 @@
#include "chrome/browser/pepper_broker_infobar_delegate.h"
#include "chrome/browser/permissions/permission_request_manager.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/printing/background_printing_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_destroyer.h"
#include "chrome/browser/profiles/profile_metrics.h"
......@@ -536,6 +537,14 @@ Browser::~Browser() {
profiles::RemoveBrowsingDataForProfile(profile_->GetPath());
#endif
} else {
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
// The Printing Background Manager holds onto preview dialog WebContents
// whose corresponding print jobs have not yet fully spooled. Make sure
// these get destroyed before tearing down the incognito profile so that
// their render frame hosts can exit in time - see crbug.com/579155
g_browser_process->background_printing_manager()
->DeletePreviewContentsForBrowserContext(profile_);
#endif
// An incognito profile is no longer needed, this indirectly frees
// its cache and cookies once it gets destroyed at the appropriate time.
ProfileDestroyer::DestroyProfileWhenAppropriate(profile_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment