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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « mojo/public/cpp/bindings/lib/router.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 EXPECT_EQ("greetings", description); 783 EXPECT_EQ("greetings", description);
784 quit_closure.Run(); 784 quit_closure.Run();
785 }, 785 },
786 run_loop.QuitClosure())); 786 run_loop.QuitClosure()));
787 787
788 request.ResetWithReason(88u, "greetings"); 788 request.ResetWithReason(88u, "greetings");
789 789
790 run_loop.Run(); 790 run_loop.Run();
791 } 791 }
792 792
793 TEST_F(InterfacePtrTest, CallbackOwnsInterfacePtr) {
794 sample::PingTestPtr ptr;
795 sample::PingTestRequest request = GetProxy(&ptr);
796
797 base::RunLoop run_loop;
798
799 // Make a call with the proxy's lifetime bound to the response callback.
800 sample::PingTest* raw_proxy = ptr.get();
801 ptr.set_connection_error_handler(run_loop.QuitClosure());
802 raw_proxy->Ping(
803 base::Bind([](sample::PingTestPtr ptr) {}, base::Passed(&ptr)));
804
805 // Trigger an error on |ptr|. This will ultimately lead to the proxy's
806 // response callbacks being destroyed, which will in turn lead to the proxy
807 // being destroyed. This should not crash.
808 request.PassMessagePipe();
809 run_loop.Run();
810 }
811
793 } // namespace 812 } // namespace
794 } // namespace test 813 } // namespace test
795 } // namespace mojo 814 } // namespace mojo
OLDNEW
« 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