OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ipc/ipc_mojo_bootstrap.h" | 5 #include "ipc/ipc_mojo_bootstrap.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 | 878 |
879 std::map<uint32_t, scoped_refptr<Endpoint>> endpoints_; | 879 std::map<uint32_t, scoped_refptr<Endpoint>> endpoints_; |
880 | 880 |
881 DISALLOW_COPY_AND_ASSIGN(ChannelAssociatedGroupController); | 881 DISALLOW_COPY_AND_ASSIGN(ChannelAssociatedGroupController); |
882 }; | 882 }; |
883 | 883 |
884 class MojoBootstrapImpl : public MojoBootstrap { | 884 class MojoBootstrapImpl : public MojoBootstrap { |
885 public: | 885 public: |
886 MojoBootstrapImpl( | 886 MojoBootstrapImpl( |
887 mojo::ScopedMessagePipeHandle handle, | 887 mojo::ScopedMessagePipeHandle handle, |
888 Delegate* delegate, | |
889 const scoped_refptr<ChannelAssociatedGroupController> controller) | 888 const scoped_refptr<ChannelAssociatedGroupController> controller) |
890 : controller_(controller), | 889 : controller_(controller), handle_(std::move(handle)) { |
891 handle_(std::move(handle)), | |
892 delegate_(delegate) { | |
893 associated_group_ = controller_->CreateAssociatedGroup(); | 890 associated_group_ = controller_->CreateAssociatedGroup(); |
894 } | 891 } |
895 | 892 |
896 ~MojoBootstrapImpl() override { | 893 ~MojoBootstrapImpl() override { |
897 controller_->ShutDown(); | 894 controller_->ShutDown(); |
898 } | 895 } |
899 | 896 |
900 private: | 897 private: |
901 // MojoBootstrap: | 898 void Connect(mojom::ChannelAssociatedPtr* sender, |
902 void Connect() override { | 899 mojom::ChannelAssociatedRequest* receiver) override { |
903 controller_->Bind(std::move(handle_)); | 900 controller_->Bind(std::move(handle_)); |
904 | 901 controller_->CreateChannelEndpoints(sender, receiver); |
905 IPC::mojom::ChannelAssociatedPtr sender; | |
906 IPC::mojom::ChannelAssociatedRequest receiver; | |
907 controller_->CreateChannelEndpoints(&sender, &receiver); | |
908 | |
909 delegate_->OnPipesAvailable(std::move(sender), std::move(receiver)); | |
910 } | 902 } |
911 | 903 |
912 void Pause() override { | 904 void Pause() override { |
913 controller_->Pause(); | 905 controller_->Pause(); |
914 } | 906 } |
915 | 907 |
916 void Unpause() override { | 908 void Unpause() override { |
917 controller_->Unpause(); | 909 controller_->Unpause(); |
918 } | 910 } |
919 | 911 |
920 void Flush() override { | 912 void Flush() override { |
921 controller_->FlushOutgoingMessages(); | 913 controller_->FlushOutgoingMessages(); |
922 } | 914 } |
923 | 915 |
924 mojo::AssociatedGroup* GetAssociatedGroup() override { | 916 mojo::AssociatedGroup* GetAssociatedGroup() override { |
925 return associated_group_.get(); | 917 return associated_group_.get(); |
926 } | 918 } |
927 | 919 |
928 scoped_refptr<ChannelAssociatedGroupController> controller_; | 920 scoped_refptr<ChannelAssociatedGroupController> controller_; |
929 | 921 |
930 mojo::ScopedMessagePipeHandle handle_; | 922 mojo::ScopedMessagePipeHandle handle_; |
931 Delegate* delegate_; | |
932 std::unique_ptr<mojo::AssociatedGroup> associated_group_; | 923 std::unique_ptr<mojo::AssociatedGroup> associated_group_; |
933 | 924 |
934 DISALLOW_COPY_AND_ASSIGN(MojoBootstrapImpl); | 925 DISALLOW_COPY_AND_ASSIGN(MojoBootstrapImpl); |
935 }; | 926 }; |
936 | 927 |
937 } // namespace | 928 } // namespace |
938 | 929 |
939 // static | 930 // static |
940 std::unique_ptr<MojoBootstrap> MojoBootstrap::Create( | 931 std::unique_ptr<MojoBootstrap> MojoBootstrap::Create( |
941 mojo::ScopedMessagePipeHandle handle, | 932 mojo::ScopedMessagePipeHandle handle, |
942 Channel::Mode mode, | 933 Channel::Mode mode, |
943 Delegate* delegate, | |
944 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) { | 934 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) { |
945 return base::MakeUnique<MojoBootstrapImpl>( | 935 return base::MakeUnique<MojoBootstrapImpl>( |
946 std::move(handle), delegate, | 936 std::move(handle), new ChannelAssociatedGroupController( |
947 new ChannelAssociatedGroupController(mode == Channel::MODE_SERVER, | 937 mode == Channel::MODE_SERVER, ipc_task_runner)); |
948 ipc_task_runner)); | |
949 } | 938 } |
950 | 939 |
951 } // namespace IPC | 940 } // namespace IPC |
OLD | NEW |