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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "mojo/public/cpp/bindings/interface_ptr.h" | 8 #include "mojo/public/cpp/bindings/interface_ptr.h" |
9 #include "mojo/public/cpp/bindings/interface_request.h" | 9 #include "mojo/public/cpp/bindings/interface_request.h" |
10 #include "mojo/shell/public/cpp/capabilities.h" | 10 #include "mojo/shell/public/cpp/capabilities.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 shell::mojom::ConnectorPtr connector; | 25 shell::mojom::ConnectorPtr connector; |
26 pending_connector_request_ = GetProxy(&connector); | 26 pending_connector_request_ = GetProxy(&connector); |
27 connector_.reset(new ConnectorImpl(std::move(connector))); | 27 connector_.reset(new ConnectorImpl(std::move(connector))); |
28 | 28 |
29 DCHECK(request.is_pending()); | 29 DCHECK(request.is_pending()); |
30 binding_.Bind(std::move(request)); | 30 binding_.Bind(std::move(request)); |
31 } | 31 } |
32 | 32 |
33 ShellConnection::~ShellConnection() {} | 33 ShellConnection::~ShellConnection() {} |
34 | 34 |
| 35 void ShellConnection::set_initialize_handler(const base::Closure& callback) { |
| 36 initialize_handler_ = callback; |
| 37 } |
| 38 |
35 void ShellConnection::SetAppTestConnectorForTesting( | 39 void ShellConnection::SetAppTestConnectorForTesting( |
36 shell::mojom::ConnectorPtr connector) { | 40 shell::mojom::ConnectorPtr connector) { |
37 pending_connector_request_ = nullptr; | 41 pending_connector_request_ = nullptr; |
38 connector_.reset(new ConnectorImpl(std::move(connector))); | 42 connector_.reset(new ConnectorImpl(std::move(connector))); |
39 } | 43 } |
40 | 44 |
41 //////////////////////////////////////////////////////////////////////////////// | 45 //////////////////////////////////////////////////////////////////////////////// |
42 // ShellConnection, shell::mojom::ShellClient implementation: | 46 // ShellConnection, shell::mojom::ShellClient implementation: |
43 | 47 |
44 void ShellConnection::Initialize(shell::mojom::IdentityPtr identity, | 48 void ShellConnection::Initialize(shell::mojom::IdentityPtr identity, |
45 uint32_t id, | 49 uint32_t id, |
46 const InitializeCallback& callback) { | 50 const InitializeCallback& callback) { |
| 51 if (!initialize_handler_.is_null()) |
| 52 initialize_handler_.Run(); |
| 53 |
47 callback.Run(std::move(pending_connector_request_)); | 54 callback.Run(std::move(pending_connector_request_)); |
48 | 55 |
49 DCHECK(binding_.is_bound()); | 56 DCHECK(binding_.is_bound()); |
50 binding_.set_connection_error_handler([this] { OnConnectionError(); }); | 57 binding_.set_connection_error_handler([this] { OnConnectionError(); }); |
51 | 58 |
52 client_->Initialize(connector_.get(), identity.To<Identity>(), id); | 59 client_->Initialize(connector_.get(), identity.To<Identity>(), id); |
53 } | 60 } |
54 | 61 |
55 void ShellConnection::AcceptConnection( | 62 void ShellConnection::AcceptConnection( |
56 shell::mojom::IdentityPtr source, | 63 shell::mojom::IdentityPtr source, |
(...skipping 21 matching lines...) Expand all Loading... |
78 void ShellConnection::OnConnectionError() { | 85 void ShellConnection::OnConnectionError() { |
79 // Note that the ShellClient doesn't technically have to quit now, it may live | 86 // Note that the ShellClient doesn't technically have to quit now, it may live |
80 // on to service existing connections. All existing Connectors however are | 87 // on to service existing connections. All existing Connectors however are |
81 // invalid. | 88 // invalid. |
82 client_->ShellConnectionLost(); | 89 client_->ShellConnectionLost(); |
83 // 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. |
84 // Connect() will return nullptr if they try to connect to anything. | 91 // Connect() will return nullptr if they try to connect to anything. |
85 } | 92 } |
86 | 93 |
87 } // namespace mojo | 94 } // namespace mojo |
OLD | NEW |