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

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

Issue 304273004: Add name to services (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Get chrome to build 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/application.h" 5 #include "mojo/public/cpp/application/application.h"
6 6
7 namespace mojo { 7 namespace mojo {
8 8
9 Application::Application() {} 9 Application::Application() {}
10 10
11 Application::Application(ScopedMessagePipeHandle service_provider_handle) 11 Application::Application(ScopedMessagePipeHandle service_provider_handle)
12 : internal::ServiceConnectorBase::Owner(service_provider_handle.Pass()) { 12 : internal::ServiceConnectorBase::Owner(service_provider_handle.Pass()) {
13 } 13 }
14 14
15 Application::Application(MojoHandle service_provider_handle) 15 Application::Application(MojoHandle service_provider_handle)
16 : internal::ServiceConnectorBase::Owner( 16 : internal::ServiceConnectorBase::Owner(
17 mojo::MakeScopedHandle( 17 mojo::MakeScopedHandle(
18 MessagePipeHandle(service_provider_handle)).Pass()) {} 18 MessagePipeHandle(service_provider_handle)).Pass()) {}
19 19
20 Application::~Application() { 20 Application::~Application() {
21 for (ServiceConnectorList::iterator it = service_connectors_.begin(); 21 for (NameToServiceConnectorMap::iterator i =
22 it != service_connectors_.end(); ++it) { 22 name_to_service_connector_.begin();
23 delete *it; 23 i != name_to_service_connector_.end(); ++i) {
24 delete i->second;
24 } 25 }
26 name_to_service_connector_.clear();
25 } 27 }
26 28
27 void Application::Initialize() {} 29 void Application::Initialize() {}
28 30
29 void Application::AddServiceConnector( 31 void Application::AddServiceConnector(
30 internal::ServiceConnectorBase* service_connector) { 32 internal::ServiceConnectorBase* service_connector) {
31 service_connectors_.push_back(service_connector); 33 name_to_service_connector_[service_connector->name()] = service_connector;
32 set_service_connector_owner(service_connector, this); 34 set_service_connector_owner(service_connector, this);
33 } 35 }
34 36
35 void Application::RemoveServiceConnector( 37 void Application::RemoveServiceConnector(
36 internal::ServiceConnectorBase* service_connector) { 38 internal::ServiceConnectorBase* service_connector) {
37 for (ServiceConnectorList::iterator it = service_connectors_.begin(); 39 NameToServiceConnectorMap::iterator it =
38 it != service_connectors_.end(); ++it) { 40 name_to_service_connector_.find(service_connector->name());
39 if (*it == service_connector) { 41 assert(it != name_to_service_connector_.end());
40 service_connectors_.erase(it); 42 delete it->second;
41 delete service_connector; 43 name_to_service_connector_.erase(it);
42 break; 44 if (name_to_service_connector_.empty())
43 }
44 }
45 if (service_connectors_.empty())
46 service_provider_.reset(); 45 service_provider_.reset();
47 } 46 }
48 47
49 void Application::BindServiceProvider( 48 void Application::BindServiceProvider(
50 ScopedMessagePipeHandle service_provider_handle) { 49 ScopedMessagePipeHandle service_provider_handle) {
51 service_provider_.Bind(service_provider_handle.Pass()); 50 service_provider_.Bind(service_provider_handle.Pass());
52 service_provider_.set_client(this); 51 service_provider_.set_client(this);
53 } 52 }
54 53
55 void Application::ConnectToService(const mojo::String& url, 54 void Application::ConnectToService(const mojo::String& url,
55 const mojo::String& name,
56 ScopedMessagePipeHandle client_handle) { 56 ScopedMessagePipeHandle client_handle) {
57 // TODO(davemoore): This method must be overridden by an Application subclass 57 internal::ServiceConnectorBase* service_connector =
58 // to dispatch to the right ServiceConnector. We need to figure out an 58 name_to_service_connector_[name];
59 // approach to registration to make this better. 59 return service_connector->ConnectToService(
60 assert(1 == service_connectors_.size()); 60 url, name, client_handle.Pass());
61 return service_connectors_.front()->ConnectToService(url,
62 client_handle.Pass());
63 } 61 }
64 62
65 } // namespace mojo 63 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/application/connect.h ('k') | mojo/public/cpp/application/lib/service_connector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698