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

Side by Side Diff: content/common/mojo/service_registry_impl.cc

Issue 285333003: Support exposing Mojo services between render frames, render threads, and their respective hosts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 6 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/common/mojo/service_registry_impl.h"
6
7 #include "mojo/common/common_type_converters.h"
8
9 namespace content {
10
11 ServiceRegistryImpl::ServiceRegistryImpl() : bound_(false) {
12 }
13
14 ServiceRegistryImpl::ServiceRegistryImpl(mojo::ScopedMessagePipeHandle handle)
15 : bound_(false) {
16 BindRemoteServiceProvider(handle.Pass());
17 }
18
19 ServiceRegistryImpl::~ServiceRegistryImpl() {
20 while (!pending_connects_.empty()) {
21 mojo::ScopedMessagePipeHandle handle(pending_connects_.front().second);
darin (slow to review) 2014/06/21 04:33:35 You could also use mojo::CloseRaw here. That might
Sam McNally 2014/06/24 04:00:29 Done.
22 pending_connects_.pop();
23 }
24 }
25
26 void ServiceRegistryImpl::BindRemoteServiceProvider(
27 mojo::ScopedMessagePipeHandle handle) {
28 if (bound_)
29 return;
30
31 mojo::BindToPipe(this, handle.Pass());
32 bound_ = true;
33 while (!pending_connects_.empty()) {
34 client()->GetInterface(
35 mojo::String::From(pending_connects_.front().first),
36 mojo::ScopedMessagePipeHandle(pending_connects_.front().second));
37 pending_connects_.pop();
38 }
39 }
40
41 void ServiceRegistryImpl::OnConnectionError() {
42 // TODO(sammc): Support reporting this to our owner.
43 bound_ = false;
44 }
45
46 void ServiceRegistryImpl::AddService(
47 const std::string& service_name,
48 const base::Callback<void(mojo::ScopedMessagePipeHandle)> service_factory) {
49 service_factories_[service_name] = service_factory;
50 }
51
52 void ServiceRegistryImpl::RemoveService(const std::string& service_name) {
53 service_factories_.erase(service_name);
54 }
55
56 void ServiceRegistryImpl::GetRemoteInterface(
57 const base::StringPiece& service_name,
58 mojo::ScopedMessagePipeHandle handle) {
59 if (!bound_) {
60 pending_connects_.push(
61 std::make_pair(service_name.as_string(), handle.release()));
62 return;
63 }
64 client()->GetInterface(mojo::String::From(service_name), handle.Pass());
65 }
66
67 void ServiceRegistryImpl::GetInterface(
68 const mojo::String& name,
69 mojo::ScopedMessagePipeHandle client_handle) {
70 std::map<std::string,
71 base::Callback<void(mojo::ScopedMessagePipeHandle)> >::iterator it =
72 service_factories_.find(name);
73 if (it == service_factories_.end())
74 return;
75
76 it->second.Run(client_handle.Pass());
77 }
78
79 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698