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

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

Issue 2633053002: Remove the MessageLoop::DestructionObserver from mojo bindings. (Closed)
Patch Set: rebase Created 3 years, 10 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
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);
164 } 162 }
165 163
166 InterfaceEndpointClient::~InterfaceEndpointClient() { 164 InterfaceEndpointClient::~InterfaceEndpointClient() {
167 DCHECK(thread_checker_.CalledOnValidThread()); 165 DCHECK(thread_checker_.CalledOnValidThread());
168 166
169 StopObservingIfNecessary();
170
171 if (handle_.is_valid()) 167 if (handle_.is_valid())
172 handle_.group_controller()->DetachEndpointClient(handle_); 168 handle_.group_controller()->DetachEndpointClient(handle_);
173 } 169 }
174 170
175 AssociatedGroup* InterfaceEndpointClient::associated_group() { 171 AssociatedGroup* InterfaceEndpointClient::associated_group() {
176 if (!associated_group_) 172 if (!associated_group_)
177 associated_group_ = handle_.group_controller()->CreateAssociatedGroup(); 173 associated_group_ = handle_.group_controller()->CreateAssociatedGroup();
178 return associated_group_.get(); 174 return associated_group_.get();
179 } 175 }
180 176
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 async_responders_.erase(it); 340 async_responders_.erase(it);
345 return responder->Accept(message); 341 return responder->Accept(message);
346 } else { 342 } else {
347 if (mojo::internal::ControlMessageHandler::IsControlMessage(message)) 343 if (mojo::internal::ControlMessageHandler::IsControlMessage(message))
348 return control_message_handler_.Accept(message); 344 return control_message_handler_.Accept(message);
349 345
350 return incoming_receiver_->Accept(message); 346 return incoming_receiver_->Accept(message);
351 } 347 }
352 } 348 }
353 349
354 void InterfaceEndpointClient::StopObservingIfNecessary() {
355 if (!observing_message_loop_destruction_)
356 return;
357
358 observing_message_loop_destruction_ = false;
359 base::MessageLoop::current()->RemoveDestructionObserver(this);
360 }
361
362 void InterfaceEndpointClient::WillDestroyCurrentMessageLoop() {
363 StopObservingIfNecessary();
364 NotifyError(base::nullopt);
365 }
366
367 } // namespace mojo 350 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/interface_endpoint_client.h ('k') | mojo/public/cpp/bindings/strong_associated_binding.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698