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

Unified Diff: content/browser/frame_host/navigation_handle_impl_browsertest.cc

Issue 2635203002: Quit immediately in TestNavigationObserver. (Closed)
Patch Set: Deduplicate code. Created 3 years, 11 months 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: content/browser/frame_host/navigation_handle_impl_browsertest.cc
diff --git a/content/browser/frame_host/navigation_handle_impl_browsertest.cc b/content/browser/frame_host/navigation_handle_impl_browsertest.cc
index ba1c812e470e081ec81e0cf068c26b7b2637463b..6d5613916f02359b7394a47740dccfb9c71ad608 100644
--- a/content/browser/frame_host/navigation_handle_impl_browsertest.cc
+++ b/content/browser/frame_host/navigation_handle_impl_browsertest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/memory/weak_ptr.h"
#include "content/browser/frame_host/navigation_handle_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/web_contents.h"
@@ -206,8 +207,9 @@ class TestNavigationThrottleInstaller : public WebContentsObserver {
will_start_called_(0),
will_redirect_called_(0),
will_process_called_(0),
- navigation_throttle_(nullptr) {}
- ~TestNavigationThrottleInstaller() override{};
+ navigation_throttle_(nullptr),
+ weak_factory_(this) {}
+ ~TestNavigationThrottleInstaller() override {}
TestNavigationThrottle* navigation_throttle() { return navigation_throttle_; }
@@ -244,11 +246,11 @@ class TestNavigationThrottleInstaller : public WebContentsObserver {
std::unique_ptr<NavigationThrottle> throttle(new TestNavigationThrottle(
handle, will_start_result_, will_redirect_result_, will_process_result_,
base::Bind(&TestNavigationThrottleInstaller::DidCallWillStartRequest,
- base::Unretained(this)),
+ weak_factory_.GetWeakPtr()),
base::Bind(&TestNavigationThrottleInstaller::DidCallWillRedirectRequest,
- base::Unretained(this)),
+ weak_factory_.GetWeakPtr()),
base::Bind(&TestNavigationThrottleInstaller::DidCallWillProcessResponse,
- base::Unretained(this))));
+ weak_factory_.GetWeakPtr())));
navigation_throttle_ = static_cast<TestNavigationThrottle*>(throttle.get());
handle->RegisterThrottleForTesting(std::move(throttle));
}
@@ -289,6 +291,8 @@ class TestNavigationThrottleInstaller : public WebContentsObserver {
scoped_refptr<MessageLoopRunner> will_start_loop_runner_;
scoped_refptr<MessageLoopRunner> will_redirect_loop_runner_;
scoped_refptr<MessageLoopRunner> will_process_loop_runner_;
+
+ base::WeakPtrFactory<TestNavigationThrottleInstaller> weak_factory_;
nasko 2017/01/20 22:54:45 Can you add a comment as to why this weak factory
Alexander Semashko 2017/01/23 19:45:39 Done.
};
// Records all navigation start URLs from the WebContents.

Powered by Google App Engine
This is Rietveld 408576698