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

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

Issue 1675153002: ApplicationImpl->ShellConnection, mojom::Application->mojom::ShellClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ci2
Patch Set: . Created 4 years, 10 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/application_loader.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
11 #include "base/atomic_sequence_num.h" 11 #include "base/atomic_sequence_num.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "mojo/common/common_type_converters.h" 14 #include "mojo/common/common_type_converters.h"
15 #include "mojo/common/url_type_converters.h" 15 #include "mojo/common/url_type_converters.h"
16 #include "mojo/shell/application_manager.h" 16 #include "mojo/shell/application_manager.h"
17 #include "mojo/shell/public/interfaces/content_handler.mojom.h" 17 #include "mojo/shell/public/interfaces/content_handler.mojom.h"
18 18
19 namespace mojo { 19 namespace mojo {
20 namespace shell { 20 namespace shell {
21 21
22 ApplicationInstance::ApplicationInstance( 22 ApplicationInstance::ApplicationInstance(
23 mojom::ApplicationPtr application, 23 mojom::ShellClientPtr shell_client,
24 ApplicationManager* manager, 24 ApplicationManager* manager,
25 const Identity& identity, 25 const Identity& identity,
26 uint32_t requesting_content_handler_id, 26 uint32_t requesting_content_handler_id,
27 const base::Closure& on_application_end) 27 const base::Closure& on_application_end)
28 : manager_(manager), 28 : manager_(manager),
29 id_(GenerateUniqueID()), 29 id_(GenerateUniqueID()),
30 identity_(identity), 30 identity_(identity),
31 allow_any_application_(identity.filter().size() == 1 && 31 allow_any_application_(identity.filter().size() == 1 &&
32 identity.filter().count("*") == 1), 32 identity.filter().count("*") == 1),
33 requesting_content_handler_id_(requesting_content_handler_id), 33 requesting_content_handler_id_(requesting_content_handler_id),
34 on_application_end_(on_application_end), 34 on_application_end_(on_application_end),
35 application_(std::move(application)), 35 shell_client_(std::move(shell_client)),
36 binding_(this), 36 binding_(this),
37 pid_receiver_binding_(this), 37 pid_receiver_binding_(this),
38 queue_requests_(false), 38 queue_requests_(false),
39 native_runner_(nullptr), 39 native_runner_(nullptr),
40 pid_(base::kNullProcessId) { 40 pid_(base::kNullProcessId) {
41 DCHECK_NE(Shell::kInvalidApplicationID, id_); 41 DCHECK_NE(Shell::kInvalidApplicationID, id_);
42 } 42 }
43 43
44 ApplicationInstance::~ApplicationInstance() { 44 ApplicationInstance::~ApplicationInstance() {
45 for (auto request : queued_client_requests_) { 45 for (auto request : queued_client_requests_) {
46 request->connect_callback().Run(kInvalidApplicationID, 46 request->connect_callback().Run(kInvalidApplicationID,
47 kInvalidApplicationID); 47 kInvalidApplicationID);
48 } 48 }
49 STLDeleteElements(&queued_client_requests_); 49 STLDeleteElements(&queued_client_requests_);
50 } 50 }
51 51
52 void ApplicationInstance::InitializeApplication() { 52 void ApplicationInstance::InitializeApplication() {
53 application_->Initialize(binding_.CreateInterfacePtrAndBind(), 53 shell_client_->Initialize(binding_.CreateInterfacePtrAndBind(),
54 identity_.url().spec(), id_); 54 identity_.url().spec(), id_);
55 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); 55 binding_.set_connection_error_handler([this]() { OnConnectionError(); });
56 } 56 }
57 57
58 void ApplicationInstance::ConnectToClient( 58 void ApplicationInstance::ConnectToClient(
59 scoped_ptr<ConnectToApplicationParams> params) { 59 scoped_ptr<ConnectToApplicationParams> params) {
60 if (queue_requests_) { 60 if (queue_requests_) {
61 queued_client_requests_.push_back(params.release()); 61 queued_client_requests_.push_back(params.release());
62 return; 62 return;
63 } 63 }
64 64
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 manager_->ConnectToApplication(std::move(params)); 107 manager_->ConnectToApplication(std::move(params));
108 } else { 108 } else {
109 LOG(WARNING) << "CapabilityFilter prevented connection from: " << 109 LOG(WARNING) << "CapabilityFilter prevented connection from: " <<
110 identity_.url() << " to: " << url.spec(); 110 identity_.url() << " to: " << url.spec();
111 callback.Run(kInvalidApplicationID, kInvalidApplicationID); 111 callback.Run(kInvalidApplicationID, kInvalidApplicationID);
112 } 112 }
113 } 113 }
114 114
115 void ApplicationInstance::QuitApplication() { 115 void ApplicationInstance::QuitApplication() {
116 queue_requests_ = true; 116 queue_requests_ = true;
117 application_->OnQuitRequested( 117 shell_client_->OnQuitRequested(
118 base::Bind(&ApplicationInstance::OnQuitRequestedResult, 118 base::Bind(&ApplicationInstance::OnQuitRequestedResult,
119 base::Unretained(this))); 119 base::Unretained(this)));
120 } 120 }
121 121
122 void ApplicationInstance::SetPID(uint32_t pid) { 122 void ApplicationInstance::SetPID(uint32_t pid) {
123 // This will call us back to update pid_. 123 // This will call us back to update pid_.
124 manager_->ApplicationPIDAvailable(id_, pid); 124 manager_->ApplicationPIDAvailable(id_, pid);
125 } 125 }
126 126
127 uint32_t ApplicationInstance::GenerateUniqueID() const { 127 uint32_t ApplicationInstance::GenerateUniqueID() const {
128 static uint32_t id = Shell::kInvalidApplicationID; 128 static uint32_t id = Shell::kInvalidApplicationID;
129 ++id; 129 ++id;
130 CHECK_NE(Shell::kInvalidApplicationID, id); 130 CHECK_NE(Shell::kInvalidApplicationID, id);
131 return id; 131 return id;
132 } 132 }
133 133
134 void ApplicationInstance::CallAcceptConnection( 134 void ApplicationInstance::CallAcceptConnection(
135 scoped_ptr<ConnectToApplicationParams> params) { 135 scoped_ptr<ConnectToApplicationParams> params) {
136 params->connect_callback().Run(id_, requesting_content_handler_id_); 136 params->connect_callback().Run(id_, requesting_content_handler_id_);
137 AllowedInterfaces interfaces; 137 AllowedInterfaces interfaces;
138 interfaces.insert("*"); 138 interfaces.insert("*");
139 if (!params->source().is_null()) 139 if (!params->source().is_null())
140 interfaces = GetAllowedInterfaces(params->source().filter(), identity_); 140 interfaces = GetAllowedInterfaces(params->source().filter(), identity_);
141 141
142 ApplicationInstance* source = 142 ApplicationInstance* source =
143 manager_->GetApplicationInstance(params->source()); 143 manager_->GetApplicationInstance(params->source());
144 uint32_t source_id = source ? source->id() : Shell::kInvalidApplicationID; 144 uint32_t source_id = source ? source->id() : Shell::kInvalidApplicationID;
145 application_->AcceptConnection( 145 shell_client_->AcceptConnection(
146 params->source().url().spec(), source_id, params->TakeServices(), 146 params->source().url().spec(), source_id, params->TakeServices(),
147 params->TakeExposedServices(), Array<String>::From(interfaces), 147 params->TakeExposedServices(), Array<String>::From(interfaces),
148 params->target().url().spec()); 148 params->target().url().spec());
149 } 149 }
150 150
151 void ApplicationInstance::OnConnectionError() { 151 void ApplicationInstance::OnConnectionError() {
152 std::vector<ConnectToApplicationParams*> queued_client_requests; 152 std::vector<ConnectToApplicationParams*> queued_client_requests;
153 queued_client_requests_.swap(queued_client_requests); 153 queued_client_requests_.swap(queued_client_requests);
154 auto manager = manager_; 154 auto manager = manager_;
155 manager_->OnApplicationInstanceError(this); 155 manager_->OnApplicationInstanceError(this);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 191
192 queue_requests_ = false; 192 queue_requests_ = false;
193 for (auto request : queued_client_requests_) 193 for (auto request : queued_client_requests_)
194 CallAcceptConnection(make_scoped_ptr(request)); 194 CallAcceptConnection(make_scoped_ptr(request));
195 195
196 queued_client_requests_.clear(); 196 queued_client_requests_.clear();
197 } 197 }
198 198
199 } // namespace shell 199 } // namespace shell
200 } // namespace mojo 200 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_instance.h ('k') | mojo/shell/application_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698