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

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

Issue 2024363002: Convert MimeRegistry to use mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@message-mojom-magic
Patch Set: Created 4 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "content/common/mojo/service_registry_impl.h" 5 #include "content/common/mojo/service_registry_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "mojo/common/common_type_converters.h" 9 #include "mojo/common/common_type_converters.h"
10 10
(...skipping 24 matching lines...) Expand all
35 CHECK(!remote_provider_); 35 CHECK(!remote_provider_);
36 remote_provider_ = std::move(service_provider); 36 remote_provider_ = std::move(service_provider);
37 while (!pending_connects_.empty()) { 37 while (!pending_connects_.empty()) {
38 remote_provider_->GetInterface( 38 remote_provider_->GetInterface(
39 mojo::String::From(pending_connects_.front().first), 39 mojo::String::From(pending_connects_.front().first),
40 mojo::ScopedMessagePipeHandle(pending_connects_.front().second)); 40 mojo::ScopedMessagePipeHandle(pending_connects_.front().second));
41 pending_connects_.pop(); 41 pending_connects_.pop();
42 } 42 }
43 } 43 }
44 44
45 void ServiceRegistryImpl::AddService(const std::string& service_name, 45 void ServiceRegistryImpl::AddService(
46 const ServiceFactory& service_factory) { 46 const std::string& service_name,
47 service_factories_[service_name] = service_factory; 47 const ServiceFactory& service_factory,
48 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) {
49 service_factories_[service_name] =
50 std::make_pair(service_factory, task_runner);
48 } 51 }
49 52
50 void ServiceRegistryImpl::RemoveService(const std::string& service_name) { 53 void ServiceRegistryImpl::RemoveService(const std::string& service_name) {
51 service_factories_.erase(service_name); 54 service_factories_.erase(service_name);
52 } 55 }
53 56
54 void ServiceRegistryImpl::ConnectToRemoteService( 57 void ServiceRegistryImpl::ConnectToRemoteService(
55 base::StringPiece service_name, 58 base::StringPiece service_name,
56 mojo::ScopedMessagePipeHandle handle) { 59 mojo::ScopedMessagePipeHandle handle) {
57 auto override_it = service_overrides_.find(service_name.as_string()); 60 auto override_it = service_overrides_.find(service_name.as_string());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 return; 99 return;
97 } 100 }
98 101
99 // It's possible and effectively unavoidable that under certain conditions 102 // It's possible and effectively unavoidable that under certain conditions
100 // an invalid handle may be received. Don't invoke the factory in that case. 103 // an invalid handle may be received. Don't invoke the factory in that case.
101 if (!client_handle.is_valid()) { 104 if (!client_handle.is_valid()) {
102 DVLOG(2) << "Invalid pipe handle for " << name << " interface request."; 105 DVLOG(2) << "Invalid pipe handle for " << name << " interface request.";
103 return; 106 return;
104 } 107 }
105 108
106 it->second.Run(std::move(client_handle)); 109 if (it->second.second) {
110 it->second.second->PostTask(
111 FROM_HERE,
112 base::Bind(&ServiceRegistryImpl::RunServiceFactoryOnTaskRunner,
113 it->second.first, base::Passed(&client_handle)));
114 return;
115 }
116 it->second.first.Run(std::move(client_handle));
117 }
118
119 // static
120 void ServiceRegistryImpl::RunServiceFactoryOnTaskRunner(
121 const ServiceRegistryImpl::ServiceFactory& factory,
122 mojo::ScopedMessagePipeHandle handle) {
123 factory.Run(std::move(handle));
nasko 2016/06/02 21:31:41 More for my own education - where does Mojo guaran
Sam McNally 2016/06/02 23:49:39 https://code.google.com/p/chromium/codesearch/#chr
107 } 124 }
108 125
109 void ServiceRegistryImpl::OnConnectionError() { 126 void ServiceRegistryImpl::OnConnectionError() {
110 binding_.Close(); 127 binding_.Close();
111 } 128 }
112 129
113 } // namespace content 130 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698