| OLD | NEW |
| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 ServiceContext::ServiceContext(shell::Service* service, | 22 ServiceContext::ServiceContext(shell::Service* service, |
| 23 mojom::ServiceRequest request, | 23 mojom::ServiceRequest request, |
| 24 std::unique_ptr<Connector> connector, | 24 std::unique_ptr<Connector> connector, |
| 25 mojom::ConnectorRequest connector_request) | 25 mojom::ConnectorRequest connector_request) |
| 26 : pending_connector_request_(std::move(connector_request)), | 26 : pending_connector_request_(std::move(connector_request)), |
| 27 service_(service), | 27 service_(service), |
| 28 binding_(this, std::move(request)), | 28 binding_(this, std::move(request)), |
| 29 connector_(std::move(connector)) { | 29 connector_(std::move(connector)) { |
| 30 DCHECK(binding_.is_bound()); | 30 DCHECK(binding_.is_bound()); |
| 31 binding_.set_connection_error_handler( |
| 32 base::Bind(&ServiceContext::OnConnectionError, base::Unretained(this))); |
| 31 if (!connector_) { | 33 if (!connector_) { |
| 32 connector_ = Connector::Create(&pending_connector_request_); | 34 connector_ = Connector::Create(&pending_connector_request_); |
| 33 } else { | 35 } else { |
| 34 DCHECK(pending_connector_request_.is_pending()); | 36 DCHECK(pending_connector_request_.is_pending()); |
| 35 } | 37 } |
| 36 } | 38 } |
| 37 | 39 |
| 38 ServiceContext::~ServiceContext() {} | 40 ServiceContext::~ServiceContext() {} |
| 39 | 41 |
| 40 void ServiceContext::SetConnectionLostClosure(const base::Closure& closure) { | 42 void ServiceContext::SetConnectionLostClosure(const base::Closure& closure) { |
| 41 connection_lost_closure_ = closure; | 43 connection_lost_closure_ = closure; |
| 42 if (should_run_connection_lost_closure_ && | 44 if (should_run_connection_lost_closure_ && |
| 43 !connection_lost_closure_.is_null()) | 45 !connection_lost_closure_.is_null()) |
| 44 connection_lost_closure_.Run(); | 46 connection_lost_closure_.Run(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 //////////////////////////////////////////////////////////////////////////////// | 49 //////////////////////////////////////////////////////////////////////////////// |
| 48 // ServiceContext, mojom::Service implementation: | 50 // ServiceContext, mojom::Service implementation: |
| 49 | 51 |
| 50 void ServiceContext::OnStart(const shell::Identity& identity, | 52 void ServiceContext::OnStart(const shell::Identity& identity, |
| 51 const OnStartCallback& callback) { | 53 const OnStartCallback& callback) { |
| 52 identity_ = identity; | 54 identity_ = identity; |
| 53 if (!initialize_handler_.is_null()) | 55 if (!initialize_handler_.is_null()) |
| 54 initialize_handler_.Run(); | 56 initialize_handler_.Run(); |
| 55 | 57 |
| 56 callback.Run(std::move(pending_connector_request_)); | 58 callback.Run(std::move(pending_connector_request_)); |
| 57 | 59 |
| 58 DCHECK(binding_.is_bound()); | |
| 59 binding_.set_connection_error_handler( | |
| 60 base::Bind(&ServiceContext::OnConnectionError, base::Unretained(this))); | |
| 61 | |
| 62 service_->OnStart(identity_); | 60 service_->OnStart(identity_); |
| 63 } | 61 } |
| 64 | 62 |
| 65 void ServiceContext::OnConnect( | 63 void ServiceContext::OnConnect( |
| 66 const Identity& source, | 64 const Identity& source, |
| 67 mojom::InterfaceProviderRequest interfaces, | 65 mojom::InterfaceProviderRequest interfaces, |
| 68 const CapabilityRequest& allowed_capabilities) { | 66 const CapabilityRequest& allowed_capabilities) { |
| 69 std::unique_ptr<InterfaceRegistry> registry( | 67 std::unique_ptr<InterfaceRegistry> registry( |
| 70 new InterfaceRegistry(source, allowed_capabilities)); | 68 new InterfaceRegistry(source, allowed_capabilities)); |
| 71 registry->Bind(std::move(interfaces)); | 69 registry->Bind(std::move(interfaces)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 87 // invalid. | 85 // invalid. |
| 88 should_run_connection_lost_closure_ = service_->OnStop(); | 86 should_run_connection_lost_closure_ = service_->OnStop(); |
| 89 if (should_run_connection_lost_closure_ && | 87 if (should_run_connection_lost_closure_ && |
| 90 !connection_lost_closure_.is_null()) | 88 !connection_lost_closure_.is_null()) |
| 91 connection_lost_closure_.Run(); | 89 connection_lost_closure_.Run(); |
| 92 // We don't reset the connector as clients may have taken a raw pointer to it. | 90 // We don't reset the connector as clients may have taken a raw pointer to it. |
| 93 // Connect() will return nullptr if they try to connect to anything. | 91 // Connect() will return nullptr if they try to connect to anything. |
| 94 } | 92 } |
| 95 | 93 |
| 96 } // namespace shell | 94 } // namespace shell |
| OLD | NEW |