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

Side by Side Diff: services/shell/public/cpp/lib/service_context.cc

Issue 2215133002: Change signature of OnConnect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup
Patch Set: . Created 4 years, 4 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 | « services/shell/public/cpp/lib/service.cc ('k') | services/shell/public/cpp/service.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 "services/shell/public/cpp/service_context.h" 5 #include "services/shell/public/cpp/service_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "mojo/public/cpp/bindings/interface_ptr.h" 10 #include "mojo/public/cpp/bindings/interface_ptr.h"
11 #include "mojo/public/cpp/bindings/interface_request.h" 11 #include "mojo/public/cpp/bindings/interface_request.h"
12 #include "services/shell/public/cpp/capabilities.h" 12 #include "services/shell/public/cpp/capabilities.h"
13 #include "services/shell/public/cpp/lib/connection_impl.h" 13 #include "services/shell/public/cpp/interface_registry.h"
14 #include "services/shell/public/cpp/lib/connector_impl.h" 14 #include "services/shell/public/cpp/lib/connector_impl.h"
15 #include "services/shell/public/cpp/service.h" 15 #include "services/shell/public/cpp/service.h"
16 16
17 namespace shell { 17 namespace shell {
18 18
19 //////////////////////////////////////////////////////////////////////////////// 19 ////////////////////////////////////////////////////////////////////////////////
20 // ServiceContext, public: 20 // ServiceContext, public:
21 21
22 ServiceContext::ServiceContext(shell::Service* service, 22 ServiceContext::ServiceContext(shell::Service* service,
23 mojom::ServiceRequest request, 23 mojom::ServiceRequest request,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 binding_.set_connection_error_handler( 59 binding_.set_connection_error_handler(
60 base::Bind(&ServiceContext::OnConnectionError, base::Unretained(this))); 60 base::Bind(&ServiceContext::OnConnectionError, base::Unretained(this)));
61 61
62 service_->OnStart(identity_); 62 service_->OnStart(identity_);
63 } 63 }
64 64
65 void ServiceContext::OnConnect( 65 void ServiceContext::OnConnect(
66 mojom::IdentityPtr source, 66 mojom::IdentityPtr source,
67 mojom::InterfaceProviderRequest interfaces, 67 mojom::InterfaceProviderRequest interfaces,
68 mojom::CapabilityRequestPtr allowed_capabilities) { 68 mojom::CapabilityRequestPtr allowed_capabilities) {
69 std::unique_ptr<internal::ConnectionImpl> connection( 69 shell::Identity remote_identity = source.To<Identity>();
70 new internal::ConnectionImpl(source.To<Identity>(), 70 std::unique_ptr<InterfaceRegistry> registry(
71 allowed_capabilities.To<CapabilityRequest>(), 71 new InterfaceRegistry(remote_identity,
72 Connection::State::CONNECTED)); 72 allowed_capabilities.To<CapabilityRequest>()));
73 registry->Bind(std::move(interfaces));
73 74
74 std::unique_ptr<InterfaceRegistry> exposed_interfaces( 75 if (!service_->OnConnect(remote_identity, registry.get()))
75 new InterfaceRegistry(connection.get()));
76 exposed_interfaces->Bind(std::move(interfaces));
77 connection->SetExposedInterfaces(std::move(exposed_interfaces));
78
79 if (!service_->OnConnect(connection.get()))
80 return; 76 return;
81 77
82 // TODO(beng): it appears we never prune this list. We should, when the 78 // TODO(beng): it appears we never prune this list. We should, when the
83 // connection's remote service provider pipe breaks. 79 // registry's remote interface provider pipe breaks.
84 incoming_connections_.push_back(std::move(connection)); 80 incoming_connections_.push_back(std::move(registry));
85 } 81 }
86 82
87 //////////////////////////////////////////////////////////////////////////////// 83 ////////////////////////////////////////////////////////////////////////////////
88 // ServiceContext, private: 84 // ServiceContext, private:
89 85
90 void ServiceContext::OnConnectionError() { 86 void ServiceContext::OnConnectionError() {
91 // Note that the Service doesn't technically have to quit now, it may live 87 // Note that the Service doesn't technically have to quit now, it may live
92 // on to service existing connections. All existing Connectors however are 88 // on to service existing connections. All existing Connectors however are
93 // invalid. 89 // invalid.
94 should_run_connection_lost_closure_ = service_->OnStop(); 90 should_run_connection_lost_closure_ = service_->OnStop();
95 if (should_run_connection_lost_closure_ && 91 if (should_run_connection_lost_closure_ &&
96 !connection_lost_closure_.is_null()) 92 !connection_lost_closure_.is_null())
97 connection_lost_closure_.Run(); 93 connection_lost_closure_.Run();
98 // We don't reset the connector as clients may have taken a raw pointer to it. 94 // We don't reset the connector as clients may have taken a raw pointer to it.
99 // Connect() will return nullptr if they try to connect to anything. 95 // Connect() will return nullptr if they try to connect to anything.
100 } 96 }
101 97
102 } // namespace shell 98 } // namespace shell
OLDNEW
« no previous file with comments | « services/shell/public/cpp/lib/service.cc ('k') | services/shell/public/cpp/service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698