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

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

Issue 1793793002: Remove ShellConnection::WaitForInitialize (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 "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/shell/public/cpp/capabilities.h" 10 #include "mojo/shell/public/cpp/capabilities.h"
10 #include "mojo/shell/public/cpp/connector.h" 11 #include "mojo/shell/public/cpp/connector.h"
11 #include "mojo/shell/public/cpp/lib/connection_impl.h" 12 #include "mojo/shell/public/cpp/lib/connection_impl.h"
12 #include "mojo/shell/public/cpp/lib/connector_impl.h" 13 #include "mojo/shell/public/cpp/lib/connector_impl.h"
13 #include "mojo/shell/public/cpp/shell_client.h" 14 #include "mojo/shell/public/cpp/shell_client.h"
14 #include "mojo/shell/public/cpp/shell_connection.h" 15 #include "mojo/shell/public/cpp/shell_connection.h"
15 16
16 namespace mojo { 17 namespace mojo {
17 18
18 //////////////////////////////////////////////////////////////////////////////// 19 ////////////////////////////////////////////////////////////////////////////////
19 // ShellConnection, public: 20 // ShellConnection, public:
20 21
21 ShellConnection::ShellConnection( 22 ShellConnection::ShellConnection(mojo::ShellClient* client)
22 mojo::ShellClient* client, 23 : ShellConnection(client, nullptr) {}
23 InterfaceRequest<shell::mojom::ShellClient> request) 24
24 : client_(client), 25 ShellConnection::ShellConnection(mojo::ShellClient* client,
25 binding_(this, std::move(request)), 26 shell::mojom::ShellClientRequest request)
26 weak_factory_(this) {} 27 : client_(client), binding_(this) {
28 shell::mojom::ConnectorPtr connector;
29 pending_connector_request_ = GetProxy(&connector);
30 connector_.reset(new ConnectorImpl(std::move(connector)));
31
32 if (request.is_pending())
33 BindToRequest(std::move(request));
34 }
27 35
28 ShellConnection::~ShellConnection() {} 36 ShellConnection::~ShellConnection() {}
29 37
30 void ShellConnection::WaitForInitialize() { 38 void ShellConnection::BindToRequest(shell::mojom::ShellClientRequest request) {
31 DCHECK(!connector_); 39 DCHECK(!binding_.is_bound());
32 binding_.WaitForIncomingMethodCall(); 40 binding_.Bind(std::move(request));
41 }
42
43 void ShellConnection::SetAppTestConnectorForTesting(
44 shell::mojom::ConnectorPtr connector) {
45 pending_connector_request_ = nullptr;
46 connector_.reset(new ConnectorImpl(std::move(connector)));
33 } 47 }
34 48
35 //////////////////////////////////////////////////////////////////////////////// 49 ////////////////////////////////////////////////////////////////////////////////
36 // ShellConnection, shell::mojom::ShellClient implementation: 50 // ShellConnection, shell::mojom::ShellClient implementation:
37 51
38 void ShellConnection::Initialize(shell::mojom::ConnectorPtr connector, 52 void ShellConnection::Initialize(shell::mojom::IdentityPtr identity,
39 shell::mojom::IdentityPtr identity, 53 uint32_t id,
40 uint32_t id) { 54 const InitializeCallback& callback) {
41 connector_.reset(new ConnectorImpl(std::move(connector))); 55 callback.Run(std::move(pending_connector_request_));
42 binding_.set_connection_error_handler( 56
43 base::Bind(&ShellConnection::OnConnectionError, 57 DCHECK(binding_.is_bound());
44 weak_factory_.GetWeakPtr())); 58 binding_.set_connection_error_handler([this] { OnConnectionError(); });
59
45 client_->Initialize(connector_.get(), identity.To<Identity>(), id); 60 client_->Initialize(connector_.get(), identity.To<Identity>(), id);
46 } 61 }
47 62
48 void ShellConnection::AcceptConnection( 63 void ShellConnection::AcceptConnection(
49 shell::mojom::IdentityPtr source, 64 shell::mojom::IdentityPtr source,
50 uint32_t source_id, 65 uint32_t source_id,
51 shell::mojom::InterfaceProviderRequest local_interfaces, 66 shell::mojom::InterfaceProviderRequest local_interfaces,
52 shell::mojom::InterfaceProviderPtr remote_interfaces, 67 shell::mojom::InterfaceProviderPtr remote_interfaces,
53 shell::mojom::CapabilityRequestPtr allowed_capabilities, 68 shell::mojom::CapabilityRequestPtr allowed_capabilities,
54 const String& name) { 69 const String& name) {
(...skipping 16 matching lines...) Expand all
71 void ShellConnection::OnConnectionError() { 86 void ShellConnection::OnConnectionError() {
72 // Note that the ShellClient doesn't technically have to quit now, it may live 87 // Note that the ShellClient doesn't technically have to quit now, it may live
73 // on to service existing connections. All existing Connectors however are 88 // on to service existing connections. All existing Connectors however are
74 // invalid. 89 // invalid.
75 client_->ShellConnectionLost(); 90 client_->ShellConnectionLost();
76 // 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.
77 // Connect() will return nullptr if they try to connect to anything. 92 // Connect() will return nullptr if they try to connect to anything.
78 } 93 }
79 94
80 } // namespace mojo 95 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/lib/application_test_base.cc ('k') | mojo/shell/public/cpp/lib/shell_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698