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/shell_connection.h" | 5 #include "services/shell/public/cpp/shell_connection.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/connector.h" | 13 #include "services/shell/public/cpp/connector.h" |
14 #include "services/shell/public/cpp/lib/connection_impl.h" | 14 #include "services/shell/public/cpp/lib/connection_impl.h" |
15 #include "services/shell/public/cpp/lib/connector_impl.h" | 15 #include "services/shell/public/cpp/lib/connector_impl.h" |
16 #include "services/shell/public/cpp/shell_client.h" | 16 #include "services/shell/public/cpp/shell_client.h" |
17 | 17 |
18 namespace shell { | 18 namespace shell { |
19 | 19 |
20 //////////////////////////////////////////////////////////////////////////////// | 20 //////////////////////////////////////////////////////////////////////////////// |
21 // ShellConnection, public: | 21 // ShellConnection, public: |
22 | 22 |
23 ShellConnection::ShellConnection(shell::ShellClient* client, | 23 ShellConnection::ShellConnection(shell::ShellClient* client, |
24 mojom::ShellClientRequest request) | 24 mojom::ShellClientRequest request) |
25 : client_(client), binding_(this) { | 25 : client_(client), |
26 binding_(this), | |
27 should_run_connection_lost_closure_(false) { | |
Ben Goodger (Google)
2016/04/27 22:29:20
init in the header
sadrul
2016/04/27 22:45:10
Done.
| |
26 mojom::ConnectorPtr connector; | 28 mojom::ConnectorPtr connector; |
27 pending_connector_request_ = GetProxy(&connector); | 29 pending_connector_request_ = GetProxy(&connector); |
28 connector_.reset(new ConnectorImpl(std::move(connector))); | 30 connector_.reset(new ConnectorImpl(std::move(connector))); |
29 | 31 |
30 DCHECK(request.is_pending()); | 32 DCHECK(request.is_pending()); |
31 binding_.Bind(std::move(request)); | 33 binding_.Bind(std::move(request)); |
32 } | 34 } |
33 | 35 |
34 ShellConnection::~ShellConnection() {} | 36 ShellConnection::~ShellConnection() {} |
35 | 37 |
36 void ShellConnection::set_initialize_handler(const base::Closure& callback) { | 38 void ShellConnection::set_initialize_handler(const base::Closure& callback) { |
37 initialize_handler_ = callback; | 39 initialize_handler_ = callback; |
38 } | 40 } |
39 | 41 |
40 void ShellConnection::SetAppTestConnectorForTesting( | 42 void ShellConnection::SetAppTestConnectorForTesting( |
41 mojom::ConnectorPtr connector) { | 43 mojom::ConnectorPtr connector) { |
42 pending_connector_request_ = nullptr; | 44 pending_connector_request_ = nullptr; |
43 connector_.reset(new ConnectorImpl(std::move(connector))); | 45 connector_.reset(new ConnectorImpl(std::move(connector))); |
44 } | 46 } |
45 | 47 |
48 void ShellConnection::SetConnectionLostClosure(const base::Closure& closure) { | |
49 connection_lost_closure_ = closure; | |
50 if (should_run_connection_lost_closure_ && | |
51 !connection_lost_closure_.is_null()) | |
52 connection_lost_closure_.Run(); | |
53 } | |
54 | |
46 //////////////////////////////////////////////////////////////////////////////// | 55 //////////////////////////////////////////////////////////////////////////////// |
47 // ShellConnection, mojom::ShellClient implementation: | 56 // ShellConnection, mojom::ShellClient implementation: |
48 | 57 |
49 void ShellConnection::Initialize(mojom::IdentityPtr identity, | 58 void ShellConnection::Initialize(mojom::IdentityPtr identity, |
50 uint32_t id, | 59 uint32_t id, |
51 const InitializeCallback& callback) { | 60 const InitializeCallback& callback) { |
52 identity_ = identity.To<Identity>(); | 61 identity_ = identity.To<Identity>(); |
53 if (!initialize_handler_.is_null()) | 62 if (!initialize_handler_.is_null()) |
54 initialize_handler_.Run(); | 63 initialize_handler_.Run(); |
55 | 64 |
(...skipping 24 matching lines...) Expand all Loading... | |
80 incoming_connections_.push_back(std::move(registry)); | 89 incoming_connections_.push_back(std::move(registry)); |
81 } | 90 } |
82 | 91 |
83 //////////////////////////////////////////////////////////////////////////////// | 92 //////////////////////////////////////////////////////////////////////////////// |
84 // ShellConnection, private: | 93 // ShellConnection, private: |
85 | 94 |
86 void ShellConnection::OnConnectionError() { | 95 void ShellConnection::OnConnectionError() { |
87 // Note that the ShellClient doesn't technically have to quit now, it may live | 96 // Note that the ShellClient doesn't technically have to quit now, it may live |
88 // on to service existing connections. All existing Connectors however are | 97 // on to service existing connections. All existing Connectors however are |
89 // invalid. | 98 // invalid. |
90 if (client_->ShellConnectionLost() && !connection_lost_closure_.is_null()) | 99 should_run_connection_lost_closure_ = client_->ShellConnectionLost(); |
100 if (should_run_connection_lost_closure_ && | |
101 !connection_lost_closure_.is_null()) | |
91 connection_lost_closure_.Run(); | 102 connection_lost_closure_.Run(); |
92 // We don't reset the connector as clients may have taken a raw pointer to it. | 103 // 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. | 104 // Connect() will return nullptr if they try to connect to anything. |
94 } | 105 } |
95 | 106 |
96 } // namespace shell | 107 } // namespace shell |
OLD | NEW |