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

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

Issue 1882423004: Move shell service to toplevel shell namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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
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/shell_connection.h"
6
5 #include "base/bind.h" 7 #include "base/bind.h"
6 #include "base/logging.h" 8 #include "base/logging.h"
7 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
8 #include "mojo/public/cpp/bindings/interface_ptr.h" 10 #include "mojo/public/cpp/bindings/interface_ptr.h"
9 #include "mojo/public/cpp/bindings/interface_request.h" 11 #include "mojo/public/cpp/bindings/interface_request.h"
10 #include "services/shell/public/cpp/capabilities.h" 12 #include "services/shell/public/cpp/capabilities.h"
11 #include "services/shell/public/cpp/connector.h" 13 #include "services/shell/public/cpp/connector.h"
12 #include "services/shell/public/cpp/lib/connection_impl.h" 14 #include "services/shell/public/cpp/lib/connection_impl.h"
13 #include "services/shell/public/cpp/lib/connector_impl.h" 15 #include "services/shell/public/cpp/lib/connector_impl.h"
14 #include "services/shell/public/cpp/shell_client.h" 16 #include "services/shell/public/cpp/shell_client.h"
15 #include "services/shell/public/cpp/shell_connection.h"
16 17
17 namespace mojo { 18 namespace shell {
18 19
19 //////////////////////////////////////////////////////////////////////////////// 20 ////////////////////////////////////////////////////////////////////////////////
20 // ShellConnection, public: 21 // ShellConnection, public:
21 22
22 ShellConnection::ShellConnection(mojo::ShellClient* client, 23 ShellConnection::ShellConnection(shell::ShellClient* client,
23 shell::mojom::ShellClientRequest request) 24 mojom::ShellClientRequest request)
24 : client_(client), binding_(this) { 25 : client_(client), binding_(this) {
25 shell::mojom::ConnectorPtr connector; 26 mojom::ConnectorPtr connector;
26 pending_connector_request_ = GetProxy(&connector); 27 pending_connector_request_ = GetProxy(&connector);
27 connector_.reset(new ConnectorImpl(std::move(connector))); 28 connector_.reset(new ConnectorImpl(std::move(connector)));
28 29
29 DCHECK(request.is_pending()); 30 DCHECK(request.is_pending());
30 binding_.Bind(std::move(request)); 31 binding_.Bind(std::move(request));
31 } 32 }
32 33
33 ShellConnection::~ShellConnection() {} 34 ShellConnection::~ShellConnection() {}
34 35
35 void ShellConnection::set_initialize_handler(const base::Closure& callback) { 36 void ShellConnection::set_initialize_handler(const base::Closure& callback) {
36 initialize_handler_ = callback; 37 initialize_handler_ = callback;
37 } 38 }
38 39
39 void ShellConnection::SetAppTestConnectorForTesting( 40 void ShellConnection::SetAppTestConnectorForTesting(
40 shell::mojom::ConnectorPtr connector) { 41 mojom::ConnectorPtr connector) {
41 pending_connector_request_ = nullptr; 42 pending_connector_request_ = nullptr;
42 connector_.reset(new ConnectorImpl(std::move(connector))); 43 connector_.reset(new ConnectorImpl(std::move(connector)));
43 } 44 }
44 45
45 //////////////////////////////////////////////////////////////////////////////// 46 ////////////////////////////////////////////////////////////////////////////////
46 // ShellConnection, shell::mojom::ShellClient implementation: 47 // ShellConnection, mojom::ShellClient implementation:
47 48
48 void ShellConnection::Initialize(shell::mojom::IdentityPtr identity, 49 void ShellConnection::Initialize(mojom::IdentityPtr identity,
49 uint32_t id, 50 uint32_t id,
50 const InitializeCallback& callback) { 51 const InitializeCallback& callback) {
51 if (!initialize_handler_.is_null()) 52 if (!initialize_handler_.is_null())
52 initialize_handler_.Run(); 53 initialize_handler_.Run();
53 54
54 callback.Run(std::move(pending_connector_request_)); 55 callback.Run(std::move(pending_connector_request_));
55 56
56 DCHECK(binding_.is_bound()); 57 DCHECK(binding_.is_bound());
57 binding_.set_connection_error_handler([this] { OnConnectionError(); }); 58 binding_.set_connection_error_handler([this] { OnConnectionError(); });
58 59
59 client_->Initialize(connector_.get(), identity.To<Identity>(), id); 60 client_->Initialize(connector_.get(), identity.To<Identity>(), id);
60 } 61 }
61 62
62 void ShellConnection::AcceptConnection( 63 void ShellConnection::AcceptConnection(
63 shell::mojom::IdentityPtr source, 64 mojom::IdentityPtr source,
64 uint32_t source_id, 65 uint32_t source_id,
65 shell::mojom::InterfaceProviderRequest local_interfaces, 66 mojom::InterfaceProviderRequest local_interfaces,
66 shell::mojom::InterfaceProviderPtr remote_interfaces, 67 mojom::InterfaceProviderPtr remote_interfaces,
67 shell::mojom::CapabilityRequestPtr allowed_capabilities, 68 mojom::CapabilityRequestPtr allowed_capabilities,
68 const String& name) { 69 const mojo::String& name) {
69 scoped_ptr<Connection> registry(new internal::ConnectionImpl( 70 std::unique_ptr<Connection> registry(new internal::ConnectionImpl(
70 name, source.To<Identity>(), source_id, std::move(remote_interfaces), 71 name, source.To<Identity>(), source_id, std::move(remote_interfaces),
71 std::move(local_interfaces), 72 std::move(local_interfaces), allowed_capabilities.To<CapabilityRequest>(),
72 allowed_capabilities.To<CapabilityRequest>(),
73 Connection::State::CONNECTED)); 73 Connection::State::CONNECTED));
74 if (!client_->AcceptConnection(registry.get())) 74 if (!client_->AcceptConnection(registry.get()))
75 return; 75 return;
76 76
77 // TODO(beng): it appears we never prune this list. We should, when the 77 // TODO(beng): it appears we never prune this list. We should, when the
78 // connection's remote service provider pipe breaks. 78 // connection's remote service provider pipe breaks.
79 incoming_connections_.push_back(std::move(registry)); 79 incoming_connections_.push_back(std::move(registry));
80 } 80 }
81 81
82 //////////////////////////////////////////////////////////////////////////////// 82 ////////////////////////////////////////////////////////////////////////////////
83 // ShellConnection, private: 83 // ShellConnection, private:
84 84
85 void ShellConnection::OnConnectionError() { 85 void ShellConnection::OnConnectionError() {
86 // 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
87 // on to service existing connections. All existing Connectors however are 87 // on to service existing connections. All existing Connectors however are
88 // invalid. 88 // invalid.
89 if (client_->ShellConnectionLost() && !connection_lost_closure_.is_null()) 89 if (client_->ShellConnectionLost() && !connection_lost_closure_.is_null())
90 connection_lost_closure_.Run(); 90 connection_lost_closure_.Run();
91 // We don't reset the connector as clients may have taken a raw pointer to it. 91 // We don't reset the connector as clients may have taken a raw pointer to it.
92 // Connect() will return nullptr if they try to connect to anything. 92 // Connect() will return nullptr if they try to connect to anything.
93 } 93 }
94 94
95 } // namespace mojo 95 } // namespace shell
OLDNEW
« no previous file with comments | « services/shell/public/cpp/lib/shell_client.cc ('k') | services/shell/public/cpp/lib/shell_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698