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

Side by Side Diff: mojo/public/cpp/bindings/lib/interface_endpoint_client.cc

Issue 2358693002: Mojo C++ bindings: make InterfaceEndpointClient observe message loop destruction. (Closed)
Patch Set: . Created 4 years, 3 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 | « mojo/public/cpp/bindings/interface_endpoint_client.h ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "mojo/public/cpp/bindings/interface_endpoint_client.h" 5 #include "mojo/public/cpp/bindings/interface_endpoint_client.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 // TODO(yzshen): the way to use validator (or message filter in general) 153 // TODO(yzshen): the way to use validator (or message filter in general)
154 // directly is a little awkward. 154 // directly is a little awkward.
155 if (payload_validator) 155 if (payload_validator)
156 filters_.Append(std::move(payload_validator)); 156 filters_.Append(std::move(payload_validator));
157 157
158 controller_ = handle_.group_controller()->AttachEndpointClient( 158 controller_ = handle_.group_controller()->AttachEndpointClient(
159 handle_, this, task_runner_); 159 handle_, this, task_runner_);
160 if (expect_sync_requests) 160 if (expect_sync_requests)
161 controller_->AllowWokenUpBySyncWatchOnSameThread(); 161 controller_->AllowWokenUpBySyncWatchOnSameThread();
162
163 base::MessageLoop::current()->AddDestructionObserver(this);
162 } 164 }
163 165
164 InterfaceEndpointClient::~InterfaceEndpointClient() { 166 InterfaceEndpointClient::~InterfaceEndpointClient() {
165 DCHECK(thread_checker_.CalledOnValidThread()); 167 DCHECK(thread_checker_.CalledOnValidThread());
166 168
169 StopObservingIfNecessary();
170
167 if (handle_.is_valid()) 171 if (handle_.is_valid())
168 handle_.group_controller()->DetachEndpointClient(handle_); 172 handle_.group_controller()->DetachEndpointClient(handle_);
169 } 173 }
170 174
171 AssociatedGroup* InterfaceEndpointClient::associated_group() { 175 AssociatedGroup* InterfaceEndpointClient::associated_group() {
172 if (!associated_group_) 176 if (!associated_group_)
173 associated_group_ = handle_.group_controller()->CreateAssociatedGroup(); 177 associated_group_ = handle_.group_controller()->CreateAssociatedGroup();
174 return associated_group_.get(); 178 return associated_group_.get();
175 } 179 }
176 180
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 async_responders_.erase(it); 333 async_responders_.erase(it);
330 return responder->Accept(message); 334 return responder->Accept(message);
331 } else { 335 } else {
332 if (mojo::internal::ControlMessageHandler::IsControlMessage(message)) 336 if (mojo::internal::ControlMessageHandler::IsControlMessage(message))
333 return control_message_handler_.Accept(message); 337 return control_message_handler_.Accept(message);
334 338
335 return incoming_receiver_->Accept(message); 339 return incoming_receiver_->Accept(message);
336 } 340 }
337 } 341 }
338 342
343 void InterfaceEndpointClient::StopObservingIfNecessary() {
344 if (!observing_message_loop_destruction_)
345 return;
346
347 observing_message_loop_destruction_ = false;
348 base::MessageLoop::current()->RemoveDestructionObserver(this);
349 }
350
351 void InterfaceEndpointClient::WillDestroyCurrentMessageLoop() {
352 StopObservingIfNecessary();
353 NotifyError();
354 }
355
339 } // namespace mojo 356 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/interface_endpoint_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698