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

Side by Side Diff: mojo/shell/application_instance.cc

Issue 1736663003: Eliminate Quit() from Shell, and roll Shell & Connector together. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@14cf
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
« no previous file with comments | « mojo/shell/application_instance.h ('k') | mojo/shell/public/cpp/connector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "mojo/shell/application_instance.h" 5 #include "mojo/shell/application_instance.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 11 matching lines...) Expand all
22 ApplicationInstance::ApplicationInstance( 22 ApplicationInstance::ApplicationInstance(
23 mojom::ShellClientPtr shell_client, 23 mojom::ShellClientPtr shell_client,
24 ApplicationManager* manager, 24 ApplicationManager* manager,
25 const Identity& identity) 25 const Identity& identity)
26 : manager_(manager), 26 : manager_(manager),
27 id_(GenerateUniqueID()), 27 id_(GenerateUniqueID()),
28 identity_(identity), 28 identity_(identity),
29 allow_any_application_(identity.filter().size() == 1 && 29 allow_any_application_(identity.filter().size() == 1 &&
30 identity.filter().count("*") == 1), 30 identity.filter().count("*") == 1),
31 shell_client_(std::move(shell_client)), 31 shell_client_(std::move(shell_client)),
32 binding_(this),
33 pid_receiver_binding_(this), 32 pid_receiver_binding_(this),
34 queue_requests_(false),
35 native_runner_(nullptr), 33 native_runner_(nullptr),
36 pid_(base::kNullProcessId) { 34 pid_(base::kNullProcessId) {
37 DCHECK_NE(kInvalidApplicationID, id_); 35 DCHECK_NE(kInvalidApplicationID, id_);
38 } 36 }
39 37
40 ApplicationInstance::~ApplicationInstance() { 38 ApplicationInstance::~ApplicationInstance() {}
41 for (auto request : queued_client_requests_)
42 request->connect_callback().Run(kInvalidApplicationID);
43 STLDeleteElements(&queued_client_requests_);
44 }
45 39
46 void ApplicationInstance::InitializeApplication() { 40 void ApplicationInstance::InitializeApplication() {
47 shell_client_->Initialize(binding_.CreateInterfacePtrAndBind(), 41 shell_client_->Initialize(connectors_.CreateInterfacePtrAndBind(this),
48 identity_.url().spec(), id_, identity_.user_id()); 42 identity_.url().spec(), id_, identity_.user_id());
49 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); 43 connectors_.set_connection_error_handler(
44 base::Bind(&ApplicationManager::OnApplicationInstanceError,
45 base::Unretained(manager_), base::Unretained(this)));
50 } 46 }
51 47
52 void ApplicationInstance::ConnectToClient(scoped_ptr<ConnectParams> params) { 48 void ApplicationInstance::ConnectToClient(scoped_ptr<ConnectParams> params) {
53 if (queue_requests_) { 49 params->connect_callback().Run(id_);
54 queued_client_requests_.push_back(params.release()); 50 AllowedInterfaces interfaces;
55 return; 51 interfaces.insert("*");
56 } 52 if (!params->source().is_null())
53 interfaces = GetAllowedInterfaces(params->source().filter(), identity_);
57 54
58 CallAcceptConnection(std::move(params)); 55 ApplicationInstance* source =
56 manager_->GetApplicationInstance(params->source());
57 uint32_t source_id = source ? source->id() : kInvalidApplicationID;
58 shell_client_->AcceptConnection(
59 params->source().url().spec(), params->source().user_id(), source_id,
60 params->TakeRemoteInterfaces(), params->TakeLocalInterfaces(),
61 Array<String>::From(interfaces), params->target().url().spec());
59 } 62 }
60 63
61 void ApplicationInstance::SetNativeRunner(NativeRunner* native_runner) { 64 void ApplicationInstance::SetNativeRunner(NativeRunner* native_runner) {
62 native_runner_ = native_runner; 65 native_runner_ = native_runner;
63 } 66 }
64 67
65 void ApplicationInstance::BindPIDReceiver( 68 void ApplicationInstance::BindPIDReceiver(
66 InterfaceRequest<mojom::PIDReceiver> pid_receiver) { 69 InterfaceRequest<mojom::PIDReceiver> pid_receiver) {
67 pid_receiver_binding_.Bind(std::move(pid_receiver)); 70 pid_receiver_binding_.Bind(std::move(pid_receiver));
68 } 71 }
69 72
70 // Shell implementation:
71 void ApplicationInstance::GetConnector(mojom::ConnectorRequest request) {
72 connectors_.AddBinding(this, std::move(request));
73 }
74
75 void ApplicationInstance::QuitApplication() {
76 queue_requests_ = true;
77 shell_client_->OnQuitRequested(
78 base::Bind(&ApplicationInstance::OnQuitRequestedResult,
79 base::Unretained(this)));
80 }
81
82 // Connector implementation: 73 // Connector implementation:
83 void ApplicationInstance::Connect( 74 void ApplicationInstance::Connect(
84 const String& app_url, 75 const String& app_url,
85 uint32_t user_id, 76 uint32_t user_id,
86 shell::mojom::InterfaceProviderRequest remote_interfaces, 77 shell::mojom::InterfaceProviderRequest remote_interfaces,
87 shell::mojom::InterfaceProviderPtr local_interfaces, 78 shell::mojom::InterfaceProviderPtr local_interfaces,
88 const ConnectCallback& callback) { 79 const ConnectCallback& callback) {
89 GURL url = app_url.To<GURL>(); 80 GURL url = app_url.To<GURL>();
90 if (!url.is_valid()) { 81 if (!url.is_valid()) {
91 LOG(ERROR) << "Error: invalid URL: " << app_url; 82 LOG(ERROR) << "Error: invalid URL: " << app_url;
(...skipping 25 matching lines...) Expand all
117 manager_->ApplicationPIDAvailable(id_, pid); 108 manager_->ApplicationPIDAvailable(id_, pid);
118 } 109 }
119 110
120 uint32_t ApplicationInstance::GenerateUniqueID() const { 111 uint32_t ApplicationInstance::GenerateUniqueID() const {
121 static uint32_t id = kInvalidApplicationID; 112 static uint32_t id = kInvalidApplicationID;
122 ++id; 113 ++id;
123 CHECK_NE(kInvalidApplicationID, id); 114 CHECK_NE(kInvalidApplicationID, id);
124 return id; 115 return id;
125 } 116 }
126 117
127 void ApplicationInstance::CallAcceptConnection(
128 scoped_ptr<ConnectParams> params) {
129 params->connect_callback().Run(id_);
130 AllowedInterfaces interfaces;
131 interfaces.insert("*");
132 if (!params->source().is_null())
133 interfaces = GetAllowedInterfaces(params->source().filter(), identity_);
134
135 ApplicationInstance* source =
136 manager_->GetApplicationInstance(params->source());
137 uint32_t source_id = source ? source->id() : kInvalidApplicationID;
138 shell_client_->AcceptConnection(
139 params->source().url().spec(), params->source().user_id(), source_id,
140 params->TakeRemoteInterfaces(), params->TakeLocalInterfaces(),
141 Array<String>::From(interfaces), params->target().url().spec());
142 }
143
144 void ApplicationInstance::OnConnectionError() {
145 std::vector<ConnectParams*> queued_client_requests;
146 queued_client_requests_.swap(queued_client_requests);
147 auto manager = manager_;
148 manager_->OnApplicationInstanceError(this);
149 //|this| is deleted.
150
151 // If any queued requests came to shell during time it was shutting down,
152 // start them now.
153 for (auto request : queued_client_requests)
154 manager->Connect(make_scoped_ptr(request));
155 }
156
157 void ApplicationInstance::OnQuitRequestedResult(bool can_quit) {
158 if (can_quit)
159 return;
160
161 queue_requests_ = false;
162 for (auto request : queued_client_requests_)
163 CallAcceptConnection(make_scoped_ptr(request));
164
165 queued_client_requests_.clear();
166 }
167
168 } // namespace shell 118 } // namespace shell
169 } // namespace mojo 119 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_instance.h ('k') | mojo/shell/public/cpp/connector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698