Skip to content

Commit

Permalink
Revert "Headless: don't run unload hooks upon web contents close."
Browse files Browse the repository at this point in the history
This reverts commit 0d53513.

Reason for revert: Flaky tests, see bug

Bug: 854143

Original change's description:
> Headless: don't run unload hooks upon web contents close.
> 
> Change-Id: I6e391fadbbf47aa6427a16495bdca3c88d456b05
> Reviewed-on: https://chromium-review.googlesource.com/1105041
> Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
> Commit-Queue: Pavel Feldman <pfeldman@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#568213}

TBR=dgozman@chromium.org,pfeldman@chromium.org,eseckler@chromium.org

Change-Id: I252909f78e6d33b98819f6510f780997327a6901
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/1106077
Reviewed-by: Marc Treib <treib@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568417}
  • Loading branch information
Marc Treib authored and Commit Bot committed Jun 19, 2018
1 parent 96352eb commit 7e6092a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
22 changes: 21 additions & 1 deletion headless/lib/browser/headless_web_contents_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class HeadlessWebContentsImpl::Delegate : public content::WebContentsDelegate {
auto* const headless_contents =
HeadlessWebContentsImpl::From(browser(), source);
DCHECK(headless_contents);
headless_contents->Close();
headless_contents->DelegateRequestsClose();
}

void AddNewContents(content::WebContents* source,
Expand Down Expand Up @@ -379,9 +379,29 @@ bool HeadlessWebContentsImpl::OpenURL(const GURL& url) {

void HeadlessWebContentsImpl::Close() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);

if (quit_closure_)
return;

if (!render_process_exited_) {
web_contents_->ClosePage();
base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
quit_closure_ = run_loop.QuitClosure();
run_loop.Run();
}

browser_context()->DestroyWebContents(this);
}

void HeadlessWebContentsImpl::DelegateRequestsClose() {
if (quit_closure_) {
quit_closure_.Run();
quit_closure_ = base::Closure();
} else {
browser_context()->DestroyWebContents(this);
}
}

std::string HeadlessWebContentsImpl::GetDevToolsAgentHostId() {
return agent_host_->GetId();
}
Expand Down
4 changes: 4 additions & 0 deletions headless/lib/browser/headless_web_contents_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class HEADLESS_EXPORT HeadlessWebContentsImpl

void Close() override;

void DelegateRequestsClose();

std::string GetDevToolsAgentHostId();

HeadlessBrowserImpl* browser() const;
Expand Down Expand Up @@ -176,6 +178,8 @@ class HEADLESS_EXPORT HeadlessWebContentsImpl

base::ObserverList<HeadlessWebContents::Observer> observers_;

base::Closure quit_closure_;

base::WeakPtrFactory<HeadlessWebContentsImpl> weak_ptr_factory_;

DISALLOW_COPY_AND_ASSIGN(HeadlessWebContentsImpl);
Expand Down

0 comments on commit 7e6092a

Please sign in to comment.