| OLD | NEW |
| 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/lib/multiplex_router.h" | 5 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "mojo/public/cpp/bindings/associated_group.h" |
| 10 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h" | 11 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h" |
| 11 | 12 |
| 12 namespace mojo { | 13 namespace mojo { |
| 13 namespace internal { | 14 namespace internal { |
| 14 | 15 |
| 15 // InterfaceEndpoint stores the information of an interface endpoint registered | 16 // InterfaceEndpoint stores the information of an interface endpoint registered |
| 16 // with the router. Always accessed under the router's lock. | 17 // with the router. Always accessed under the router's lock. |
| 17 // No one other than the router's |endpoints_| and |tasks_| should hold refs to | 18 // No one other than the router's |endpoints_| and |tasks_| should hold refs to |
| 18 // this object. | 19 // this object. |
| 19 class MultiplexRouter::InterfaceEndpoint | 20 class MultiplexRouter::InterfaceEndpoint |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 278 |
| 278 void MultiplexRouter::RaiseError() { | 279 void MultiplexRouter::RaiseError() { |
| 279 if (task_runner_->BelongsToCurrentThread()) { | 280 if (task_runner_->BelongsToCurrentThread()) { |
| 280 connector_.RaiseError(); | 281 connector_.RaiseError(); |
| 281 } else { | 282 } else { |
| 282 task_runner_->PostTask(FROM_HERE, | 283 task_runner_->PostTask(FROM_HERE, |
| 283 base::Bind(&MultiplexRouter::RaiseError, this)); | 284 base::Bind(&MultiplexRouter::RaiseError, this)); |
| 284 } | 285 } |
| 285 } | 286 } |
| 286 | 287 |
| 288 scoped_ptr<AssociatedGroup> MultiplexRouter::CreateAssociatedGroup() { |
| 289 scoped_ptr<AssociatedGroup> group(new AssociatedGroup); |
| 290 group->router_ = this; |
| 291 return group.Pass(); |
| 292 } |
| 293 |
| 294 // static |
| 295 MultiplexRouter* MultiplexRouter::GetRouter(AssociatedGroup* associated_group) { |
| 296 return associated_group->router_.get(); |
| 297 } |
| 298 |
| 287 ScopedMessagePipeHandle MultiplexRouter::PassMessagePipe() { | 299 ScopedMessagePipeHandle MultiplexRouter::PassMessagePipe() { |
| 288 DCHECK(thread_checker_.CalledOnValidThread()); | 300 DCHECK(thread_checker_.CalledOnValidThread()); |
| 289 { | 301 { |
| 290 base::AutoLock locker(lock_); | 302 base::AutoLock locker(lock_); |
| 291 DCHECK(endpoints_.empty() || (endpoints_.size() == 1 && | 303 DCHECK(endpoints_.empty() || (endpoints_.size() == 1 && |
| 292 ContainsKey(endpoints_, kMasterInterfaceId))); | 304 ContainsKey(endpoints_, kMasterInterfaceId))); |
| 293 } | 305 } |
| 294 return connector_.PassMessagePipe(); | 306 return connector_.PassMessagePipe(); |
| 295 } | 307 } |
| 296 | 308 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 } | 522 } |
| 511 | 523 |
| 512 void MultiplexRouter::RaiseErrorInNonTestingMode() { | 524 void MultiplexRouter::RaiseErrorInNonTestingMode() { |
| 513 lock_.AssertAcquired(); | 525 lock_.AssertAcquired(); |
| 514 if (!testing_mode_) | 526 if (!testing_mode_) |
| 515 RaiseError(); | 527 RaiseError(); |
| 516 } | 528 } |
| 517 | 529 |
| 518 } // namespace internal | 530 } // namespace internal |
| 519 } // namespace mojo | 531 } // namespace mojo |
| OLD | NEW |