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

Side by Side Diff: ipc/mojo/ipc_mojo_bootstrap.cc

Issue 2080083002: Revert of Deletes mojo::Callback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « extensions/browser/mojo/stash_backend.cc ('k') | media/capture/video/scoped_result_callback.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/mojo/ipc_mojo_bootstrap.h" 5 #include "ipc/mojo/ipc_mojo_bootstrap.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/callback.h"
11 #include "base/logging.h" 10 #include "base/logging.h"
12 #include "base/macros.h" 11 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
14 #include "base/process/process_handle.h" 13 #include "base/process/process_handle.h"
15 #include "build/build_config.h" 14 #include "build/build_config.h"
16 #include "ipc/ipc_message_utils.h" 15 #include "ipc/ipc_message_utils.h"
17 #include "ipc/ipc_platform_file.h" 16 #include "ipc/ipc_platform_file.h"
18 #include "mojo/public/cpp/bindings/binding.h" 17 #include "mojo/public/cpp/bindings/binding.h"
19 18
20 namespace IPC { 19 namespace IPC {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 67 }
69 68
70 void MojoServerBootstrap::OnInitDone(int32_t peer_pid) { 69 void MojoServerBootstrap::OnInitDone(int32_t peer_pid) {
71 if (state() != STATE_WAITING_ACK) { 70 if (state() != STATE_WAITING_ACK) {
72 set_state(STATE_ERROR); 71 set_state(STATE_ERROR);
73 LOG(ERROR) << "Got inconsistent message from client."; 72 LOG(ERROR) << "Got inconsistent message from client.";
74 return; 73 return;
75 } 74 }
76 75
77 set_state(STATE_READY); 76 set_state(STATE_READY);
78 bootstrap_.set_connection_error_handler(base::Closure()); 77 bootstrap_.set_connection_error_handler(mojo::Closure());
79 delegate()->OnPipesAvailable(std::move(send_channel_), 78 delegate()->OnPipesAvailable(std::move(send_channel_),
80 std::move(receive_channel_request_), peer_pid); 79 std::move(receive_channel_request_), peer_pid);
81 } 80 }
82 81
83 // MojoBootstrap for client processes. You should create the instance 82 // MojoBootstrap for client processes. You should create the instance
84 // using MojoBootstrap::Create(). 83 // using MojoBootstrap::Create().
85 class MojoClientBootstrap : public MojoBootstrap, public mojom::Bootstrap { 84 class MojoClientBootstrap : public MojoBootstrap, public mojom::Bootstrap {
86 public: 85 public:
87 MojoClientBootstrap(); 86 MojoClientBootstrap();
88 87
89 private: 88 private:
90 // MojoBootstrap implementation. 89 // MojoBootstrap implementation.
91 void Connect() override; 90 void Connect() override;
92 91
93 // mojom::Bootstrap implementation. 92 // mojom::Bootstrap implementation.
94 void Init(mojom::ChannelAssociatedRequest receive_channel, 93 void Init(mojom::ChannelAssociatedRequest receive_channel,
95 mojom::ChannelAssociatedPtrInfo send_channel, 94 mojom::ChannelAssociatedPtrInfo send_channel,
96 int32_t peer_pid, 95 int32_t peer_pid,
97 const InitCallback& callback) override; 96 const mojo::Callback<void(int32_t)>& callback) override;
98 97
99 mojo::Binding<mojom::Bootstrap> binding_; 98 mojo::Binding<mojom::Bootstrap> binding_;
100 99
101 DISALLOW_COPY_AND_ASSIGN(MojoClientBootstrap); 100 DISALLOW_COPY_AND_ASSIGN(MojoClientBootstrap);
102 }; 101 };
103 102
104 MojoClientBootstrap::MojoClientBootstrap() : binding_(this) {} 103 MojoClientBootstrap::MojoClientBootstrap() : binding_(this) {}
105 104
106 void MojoClientBootstrap::Connect() { 105 void MojoClientBootstrap::Connect() {
107 binding_.Bind(TakeHandle()); 106 binding_.Bind(TakeHandle());
108 binding_.set_connection_error_handler( 107 binding_.set_connection_error_handler(
109 base::Bind(&MojoClientBootstrap::Fail, base::Unretained(this))); 108 base::Bind(&MojoClientBootstrap::Fail, base::Unretained(this)));
110 } 109 }
111 110
112 void MojoClientBootstrap::Init(mojom::ChannelAssociatedRequest receive_channel, 111 void MojoClientBootstrap::Init(mojom::ChannelAssociatedRequest receive_channel,
113 mojom::ChannelAssociatedPtrInfo send_channel, 112 mojom::ChannelAssociatedPtrInfo send_channel,
114 int32_t peer_pid, 113 int32_t peer_pid,
115 const InitCallback& callback) { 114 const mojo::Callback<void(int32_t)>& callback) {
116 callback.Run(GetSelfPID()); 115 callback.Run(GetSelfPID());
117 set_state(STATE_READY); 116 set_state(STATE_READY);
118 binding_.set_connection_error_handler(base::Closure()); 117 binding_.set_connection_error_handler(mojo::Closure());
119 delegate()->OnPipesAvailable(std::move(send_channel), 118 delegate()->OnPipesAvailable(std::move(send_channel),
120 std::move(receive_channel), peer_pid); 119 std::move(receive_channel), peer_pid);
121 } 120 }
122 121
123 } // namespace 122 } // namespace
124 123
125 // MojoBootstrap 124 // MojoBootstrap
126 125
127 // static 126 // static
128 std::unique_ptr<MojoBootstrap> MojoBootstrap::Create( 127 std::unique_ptr<MojoBootstrap> MojoBootstrap::Create(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 164
166 bool MojoBootstrap::HasFailed() const { 165 bool MojoBootstrap::HasFailed() const {
167 return state() == STATE_ERROR; 166 return state() == STATE_ERROR;
168 } 167 }
169 168
170 mojo::ScopedMessagePipeHandle MojoBootstrap::TakeHandle() { 169 mojo::ScopedMessagePipeHandle MojoBootstrap::TakeHandle() {
171 return std::move(handle_); 170 return std::move(handle_);
172 } 171 }
173 172
174 } // namespace IPC 173 } // namespace IPC
OLDNEW
« no previous file with comments | « extensions/browser/mojo/stash_backend.cc ('k') | media/capture/video/scoped_result_callback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698