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

Unified Diff: mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc

Issue 2487803002: Mojo C++ Bindings: Allow callbacks to own their InterfacePtr (Closed)
Patch Set: . Created 4 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
« no previous file with comments | « mojo/public/cpp/bindings/lib/router.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
index c47d383e042eccac337c7b46e5c1d48876d6d05a..1ff02707fffb151d16c3e118dd67041db4c1c35e 100644
--- a/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
@@ -790,6 +790,25 @@ TEST_F(InterfacePtrTest, InterfaceRequestResetWithReason) {
run_loop.Run();
}
+TEST_F(InterfacePtrTest, CallbackOwnsInterfacePtr) {
+ sample::PingTestPtr ptr;
+ sample::PingTestRequest request = GetProxy(&ptr);
+
+ base::RunLoop run_loop;
+
+ // Make a call with the proxy's lifetime bound to the response callback.
+ sample::PingTest* raw_proxy = ptr.get();
+ ptr.set_connection_error_handler(run_loop.QuitClosure());
+ raw_proxy->Ping(
+ base::Bind([](sample::PingTestPtr ptr) {}, base::Passed(&ptr)));
+
+ // Trigger an error on |ptr|. This will ultimately lead to the proxy's
+ // response callbacks being destroyed, which will in turn lead to the proxy
+ // being destroyed. This should not crash.
+ request.PassMessagePipe();
+ run_loop.Run();
+}
+
} // namespace
} // namespace test
} // namespace mojo
« no previous file with comments | « mojo/public/cpp/bindings/lib/router.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698