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

Side by Side Diff: mojo/public/cpp/application/lib/service_registry.cc

Issue 337533002: Introduce internal::ServiceRegistry to prepare for ServiceProvider split. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge problems 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 | Annotate | Revision Log
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 "mojo/public/cpp/application/lib/service_registry.h"
6
5 #include "mojo/public/cpp/application/application.h" 7 #include "mojo/public/cpp/application/application.h"
8 #include "mojo/public/cpp/application/lib/service_connector.h"
6 9
7 namespace mojo { 10 namespace mojo {
11 namespace internal {
8 12
9 Application::Application() {} 13 ServiceRegistry::ServiceRegistry(Application* application)
10 14 : application_(application) {
11 Application::Application(ScopedMessagePipeHandle service_provider_handle)
12 : internal::ServiceConnectorBase::Owner(service_provider_handle.Pass()) {
13 } 15 }
14 16
15 Application::Application(MojoHandle service_provider_handle) 17 ServiceRegistry::ServiceRegistry(
16 : internal::ServiceConnectorBase::Owner( 18 Application* application,
17 mojo::MakeScopedHandle( 19 ScopedMessagePipeHandle service_provider_handle)
18 MessagePipeHandle(service_provider_handle)).Pass()) {} 20 : application_(application) {
21 service_provider_.Bind(service_provider_handle.Pass());
22 service_provider_.set_client(this);
23 }
19 24
20 Application::~Application() { 25 ServiceRegistry::~ServiceRegistry() {
21 for (NameToServiceConnectorMap::iterator i = 26 for (NameToServiceConnectorMap::iterator i =
22 name_to_service_connector_.begin(); 27 name_to_service_connector_.begin();
23 i != name_to_service_connector_.end(); ++i) { 28 i != name_to_service_connector_.end(); ++i) {
24 delete i->second; 29 delete i->second;
25 } 30 }
26 name_to_service_connector_.clear(); 31 name_to_service_connector_.clear();
27 } 32 }
28 33
29 void Application::Initialize() {} 34 void ServiceRegistry::AddServiceConnector(
30 35 ServiceConnectorBase* service_connector) {
31 void Application::AddServiceConnector(
32 internal::ServiceConnectorBase* service_connector) {
33 name_to_service_connector_[service_connector->name()] = service_connector; 36 name_to_service_connector_[service_connector->name()] = service_connector;
34 set_service_connector_owner(service_connector, this); 37 service_connector->set_registry(this);
35 } 38 }
36 39
37 void Application::RemoveServiceConnector( 40 void ServiceRegistry::RemoveServiceConnector(
38 internal::ServiceConnectorBase* service_connector) { 41 ServiceConnectorBase* service_connector) {
39 NameToServiceConnectorMap::iterator it = 42 NameToServiceConnectorMap::iterator it =
40 name_to_service_connector_.find(service_connector->name()); 43 name_to_service_connector_.find(service_connector->name());
41 assert(it != name_to_service_connector_.end()); 44 assert(it != name_to_service_connector_.end());
42 delete it->second; 45 delete it->second;
43 name_to_service_connector_.erase(it); 46 name_to_service_connector_.erase(it);
44 if (name_to_service_connector_.empty()) 47 if (name_to_service_connector_.empty())
45 service_provider_.reset(); 48 service_provider_.reset();
46 } 49 }
47 50
48 void Application::BindServiceProvider( 51 void ServiceRegistry::BindServiceProvider(
49 ScopedMessagePipeHandle service_provider_handle) { 52 ScopedMessagePipeHandle service_provider_handle) {
50 service_provider_.Bind(service_provider_handle.Pass()); 53 service_provider_.Bind(service_provider_handle.Pass());
51 service_provider_.set_client(this); 54 service_provider_.set_client(this);
52 } 55 }
53 56
54 void Application::ConnectToService(const mojo::String& service_url, 57 void ServiceRegistry::ConnectToService(const mojo::String& service_url,
55 const mojo::String& service_name, 58 const mojo::String& service_name,
56 ScopedMessagePipeHandle client_handle, 59 ScopedMessagePipeHandle client_handle,
57 const mojo::String& requestor_url) { 60 const mojo::String& requestor_url) {
61 if (!application_->IsConnectionValid(service_name, requestor_url)) {
darin (slow to review) 2014/06/12 16:11:51 I see... I think this method should be renamed. It
DaveMoore 2014/06/12 16:28:14 Done.
62 client_handle.reset();
63 return;
64 }
65
58 internal::ServiceConnectorBase* service_connector = 66 internal::ServiceConnectorBase* service_connector =
59 name_to_service_connector_[service_name]; 67 name_to_service_connector_[service_name];
60 assert(service_connector); 68 assert(service_connector);
61 // requestor_url is ignored because the service_connector stores the url 69 // requestor_url is ignored because the service_connector stores the url
62 // of the requestor safely. 70 // of the requestor safely.
63 return service_connector->ConnectToService( 71 return service_connector->ConnectToService(
64 service_url, service_name, client_handle.Pass()); 72 service_url, service_name, client_handle.Pass());
65 } 73 }
66 74
75 } // namespace internal
67 } // namespace mojo 76 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698