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

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: handle the case where handles arrive before the RenderFrame is ready 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 Bind(handle.Pass());
17 }
18
19 ServiceRegistryImpl::~ServiceRegistryImpl() {
20 while (!pending_connects_.empty()) {
21 mojo::ScopedMessagePipeHandle handle(pending_connects_.front().second);
22 pending_connects_.pop();
23 }
24 }
25
26 void ServiceRegistryImpl::Bind(mojo::ScopedMessagePipeHandle handle) {
27 if (bound_)
28 return;
29
30 mojo::BindToPipe(this, handle.Pass());
31 bound_ = true;
32 while (!pending_connects_.empty()) {
33 client()->GetInterface(
34 mojo::String::From(pending_connects_.front().first),
35 mojo::ScopedMessagePipeHandle(pending_connects_.front().second));
36 pending_connects_.pop();
37 }
38 }
39
40 void ServiceRegistryImpl::OnConnectionError() {
41 // TODO(sammc): Support reporting this to our owner.
42 bound_ = false;
43 }
44
45 void ServiceRegistryImpl::AddService(
46 const std::string& service_name,
47 const base::Callback<void(mojo::ScopedMessagePipeHandle)> service_factory) {
48 service_factories_[service_name] = service_factory;
49 }
50
51 void ServiceRegistryImpl::RemoveService(const std::string& service_name) {
52 service_factories_.erase(service_name);
53 }
54
55 void ServiceRegistryImpl::GetInterface(const base::StringPiece& service_name,
56 mojo::ScopedMessagePipeHandle handle) {
57 if (!bound_) {
58 pending_connects_.push(
59 std::make_pair(service_name.as_string(), handle.release()));
60 return;
61 }
62 client()->GetInterface(mojo::String::From(service_name), handle.Pass());
63 }
64
65 void ServiceRegistryImpl::GetInterface(
66 const mojo::String& name,
67 mojo::ScopedMessagePipeHandle client_handle) {
68 std::map<std::string,
69 base::Callback<void(mojo::ScopedMessagePipeHandle)> >::iterator it =
70 service_factories_.find(name);
71 if (it == service_factories_.end())
72 return;
73
74 it->second.Run(client_handle.Pass());
75 }
76
77 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698