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

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

Issue 1806843005: Promote {Add,Clear}ServiceOverrideForTesting to ServiceRegistry public interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nit. Created 4 years, 9 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
« no previous file with comments | « content/common/mojo/service_registry_impl.h ('k') | content/public/common/service_registry.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 21 matching lines...) Expand all
32 CHECK(!remote_provider_); 32 CHECK(!remote_provider_);
33 remote_provider_ = std::move(service_provider); 33 remote_provider_ = std::move(service_provider);
34 while (!pending_connects_.empty()) { 34 while (!pending_connects_.empty()) {
35 remote_provider_->GetInterface( 35 remote_provider_->GetInterface(
36 mojo::String::From(pending_connects_.front().first), 36 mojo::String::From(pending_connects_.front().first),
37 mojo::ScopedMessagePipeHandle(pending_connects_.front().second)); 37 mojo::ScopedMessagePipeHandle(pending_connects_.front().second));
38 pending_connects_.pop(); 38 pending_connects_.pop();
39 } 39 }
40 } 40 }
41 41
42 void ServiceRegistryImpl::AddServiceOverrideForTesting(
43 const std::string& service_name,
44 const ServiceFactory& factory) {
45 service_overrides_[service_name] = factory;
46 }
47
48 void ServiceRegistryImpl::ClearServiceOverridesForTesting() {
49 service_overrides_.clear();
50 }
51
52 void ServiceRegistryImpl::AddService(const std::string& service_name, 42 void ServiceRegistryImpl::AddService(const std::string& service_name,
53 const ServiceFactory service_factory) { 43 const ServiceFactory service_factory) {
54 service_factories_[service_name] = service_factory; 44 service_factories_[service_name] = service_factory;
55 } 45 }
56 46
57 void ServiceRegistryImpl::RemoveService(const std::string& service_name) { 47 void ServiceRegistryImpl::RemoveService(const std::string& service_name) {
58 service_factories_.erase(service_name); 48 service_factories_.erase(service_name);
59 } 49 }
60 50
61 void ServiceRegistryImpl::ConnectToRemoteService( 51 void ServiceRegistryImpl::ConnectToRemoteService(
62 const base::StringPiece& service_name, 52 const base::StringPiece& service_name,
63 mojo::ScopedMessagePipeHandle handle) { 53 mojo::ScopedMessagePipeHandle handle) {
64 auto override_it = service_overrides_.find(service_name.as_string()); 54 auto override_it = service_overrides_.find(service_name.as_string());
65 if (override_it != service_overrides_.end()) { 55 if (override_it != service_overrides_.end()) {
66 override_it->second.Run(std::move(handle)); 56 override_it->second.Run(std::move(handle));
67 return; 57 return;
68 } 58 }
69 59
70 if (!remote_provider_) { 60 if (!remote_provider_) {
71 pending_connects_.push( 61 pending_connects_.push(
72 std::make_pair(service_name.as_string(), handle.release())); 62 std::make_pair(service_name.as_string(), handle.release()));
73 return; 63 return;
74 } 64 }
75 remote_provider_->GetInterface( 65 remote_provider_->GetInterface(
76 mojo::String::From(service_name.as_string()), std::move(handle)); 66 mojo::String::From(service_name.as_string()), std::move(handle));
77 } 67 }
78 68
69 void ServiceRegistryImpl::AddServiceOverrideForTesting(
70 const std::string& service_name,
71 const ServiceFactory& factory) {
72 service_overrides_[service_name] = factory;
73 }
74
75 void ServiceRegistryImpl::ClearServiceOverridesForTesting() {
76 service_overrides_.clear();
77 }
78
79 bool ServiceRegistryImpl::IsBound() const { 79 bool ServiceRegistryImpl::IsBound() const {
80 return binding_.is_bound(); 80 return binding_.is_bound();
81 } 81 }
82 82
83 base::WeakPtr<ServiceRegistry> ServiceRegistryImpl::GetWeakPtr() { 83 base::WeakPtr<ServiceRegistry> ServiceRegistryImpl::GetWeakPtr() {
84 return weak_factory_.GetWeakPtr(); 84 return weak_factory_.GetWeakPtr();
85 } 85 }
86 86
87 void ServiceRegistryImpl::GetInterface( 87 void ServiceRegistryImpl::GetInterface(
88 const mojo::String& name, 88 const mojo::String& name,
(...skipping 10 matching lines...) Expand all
99 } 99 }
100 100
101 it->second.Run(std::move(client_handle)); 101 it->second.Run(std::move(client_handle));
102 } 102 }
103 103
104 void ServiceRegistryImpl::OnConnectionError() { 104 void ServiceRegistryImpl::OnConnectionError() {
105 binding_.Close(); 105 binding_.Close();
106 } 106 }
107 107
108 } // namespace content 108 } // namespace content
OLDNEW
« no previous file with comments | « content/common/mojo/service_registry_impl.h ('k') | content/public/common/service_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698