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

Side by Side Diff: mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc

Issue 2515873003: Mojo C++ Bindings: Introduce mojo::SupportsStrongBinding
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
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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 EXPECT_EQ(4u, ptr.version()); 473 EXPECT_EQ(4u, ptr.version());
474 base::RunLoop run_loop3; 474 base::RunLoop run_loop3;
475 ptr.set_connection_error_handler(run_loop3.QuitClosure()); 475 ptr.set_connection_error_handler(run_loop3.QuitClosure());
476 ptr->SetInteger(789, sample::Enum::VALUE); 476 ptr->SetInteger(789, sample::Enum::VALUE);
477 run_loop3.Run(); 477 run_loop3.Run();
478 EXPECT_TRUE(ptr.encountered_error()); 478 EXPECT_TRUE(ptr.encountered_error());
479 // The call to SetInteger() after RequireVersion(4u) is ignored. 479 // The call to SetInteger() after RequireVersion(4u) is ignored.
480 EXPECT_EQ(456, impl.integer()); 480 EXPECT_EQ(456, impl.integer());
481 } 481 }
482 482
483 class StrongMathCalculatorImpl : public math::Calculator { 483 class StrongMathCalculatorImpl
484 : public SupportsStrongBinding<math::Calculator> {
484 public: 485 public:
485 StrongMathCalculatorImpl(bool* destroyed) : destroyed_(destroyed) {} 486 StrongMathCalculatorImpl(bool* destroyed) : destroyed_(destroyed) {}
486 ~StrongMathCalculatorImpl() override { *destroyed_ = true; } 487 ~StrongMathCalculatorImpl() override { *destroyed_ = true; }
487 488
488 // math::Calculator implementation. 489 // math::Calculator implementation.
489 void Clear(const CalcCallback& callback) override { callback.Run(total_); } 490 void Clear(const CalcCallback& callback) override { callback.Run(total_); }
490 491
491 void Add(double value, const CalcCallback& callback) override { 492 void Add(double value, const CalcCallback& callback) override {
492 total_ += value; 493 total_ += value;
493 callback.Run(total_); 494 callback.Run(total_);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 // Destroying calculator_ui should close the pipe and generate an error on 607 // Destroying calculator_ui should close the pipe and generate an error on
607 // the other 608 // the other
608 // end which will destroy the instance since it is strongly bound. 609 // end which will destroy the instance since it is strongly bound.
609 } 610 }
610 611
611 run_loop.Run(); 612 run_loop.Run();
612 EXPECT_TRUE(error_received); 613 EXPECT_TRUE(error_received);
613 EXPECT_FALSE(destroyed); 614 EXPECT_FALSE(destroyed);
614 } 615 }
615 616
616 class CImpl : public C { 617 class CImpl : public SupportsStrongBinding<C> {
617 public: 618 public:
618 CImpl(bool* d_called, const base::Closure& closure) 619 CImpl(bool* d_called, const base::Closure& closure)
619 : d_called_(d_called), closure_(closure) {} 620 : d_called_(d_called), closure_(closure) {}
620 ~CImpl() override {} 621 ~CImpl() override {}
621 622
622 private: 623 private:
623 void D() override { 624 void D() override {
624 *d_called_ = true; 625 *d_called_ = true;
625 closure_.Run(); 626 closure_.Run();
626 } 627 }
627 628
628 bool* d_called_; 629 bool* d_called_;
629 base::Closure closure_; 630 base::Closure closure_;
630 }; 631 };
631 632
632 class BImpl : public B { 633 class BImpl : public SupportsStrongBinding<B> {
633 public: 634 public:
634 BImpl(bool* d_called, const base::Closure& closure) 635 BImpl(bool* d_called, const base::Closure& closure)
635 : d_called_(d_called), closure_(closure) {} 636 : d_called_(d_called), closure_(closure) {}
636 ~BImpl() override {} 637 ~BImpl() override {}
637 638
638 private: 639 private:
639 void GetC(InterfaceRequest<C> c) override { 640 void GetC(InterfaceRequest<C> c) override {
640 MakeStrongBinding(base::MakeUnique<CImpl>(d_called_, closure_), 641 MakeStrongBinding(base::MakeUnique<CImpl>(d_called_, closure_),
641 std::move(c)); 642 std::move(c));
642 } 643 }
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 thread_safe_ptr); 848 thread_safe_ptr);
848 other_thread.message_loop()->task_runner()->PostTask(FROM_HERE, run_method); 849 other_thread.message_loop()->task_runner()->PostTask(FROM_HERE, run_method);
849 850
850 // Block until the method callback is called on the background thread. 851 // Block until the method callback is called on the background thread.
851 run_loop.Run(); 852 run_loop.Run();
852 } 853 }
853 854
854 } // namespace 855 } // namespace
855 } // namespace test 856 } // namespace test
856 } // namespace mojo 857 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698