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

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

Issue 1538823002: Convert Pass()→std::move() in mojo/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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/runner/tracer.cc ('k') | mojo/shell/application_manager.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 <utility>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/stl_util.h" 10 #include "base/stl_util.h"
9 #include "mojo/application/public/interfaces/content_handler.mojom.h" 11 #include "mojo/application/public/interfaces/content_handler.mojom.h"
10 #include "mojo/common/common_type_converters.h" 12 #include "mojo/common/common_type_converters.h"
11 #include "mojo/common/url_type_converters.h" 13 #include "mojo/common/url_type_converters.h"
12 #include "mojo/shell/application_manager.h" 14 #include "mojo/shell/application_manager.h"
13 15
14 namespace mojo { 16 namespace mojo {
15 namespace shell { 17 namespace shell {
16 18
17 ApplicationInstance::ApplicationInstance( 19 ApplicationInstance::ApplicationInstance(
18 ApplicationPtr application, 20 ApplicationPtr application,
19 ApplicationManager* manager, 21 ApplicationManager* manager,
20 const Identity& identity, 22 const Identity& identity,
21 uint32_t requesting_content_handler_id, 23 uint32_t requesting_content_handler_id,
22 const base::Closure& on_application_end) 24 const base::Closure& on_application_end)
23 : manager_(manager), 25 : manager_(manager),
24 identity_(identity), 26 identity_(identity),
25 allow_any_application_(identity.filter().size() == 1 && 27 allow_any_application_(identity.filter().size() == 1 &&
26 identity.filter().count("*") == 1), 28 identity.filter().count("*") == 1),
27 requesting_content_handler_id_(requesting_content_handler_id), 29 requesting_content_handler_id_(requesting_content_handler_id),
28 on_application_end_(on_application_end), 30 on_application_end_(on_application_end),
29 application_(application.Pass()), 31 application_(std::move(application)),
30 binding_(this), 32 binding_(this),
31 queue_requests_(false), 33 queue_requests_(false),
32 native_runner_(nullptr), 34 native_runner_(nullptr),
33 pid_(base::kNullProcessId) { 35 pid_(base::kNullProcessId) {}
34 }
35 36
36 ApplicationInstance::~ApplicationInstance() { 37 ApplicationInstance::~ApplicationInstance() {
37 for (auto request : queued_client_requests_) 38 for (auto request : queued_client_requests_)
38 request->connect_callback().Run(kInvalidContentHandlerID); 39 request->connect_callback().Run(kInvalidContentHandlerID);
39 STLDeleteElements(&queued_client_requests_); 40 STLDeleteElements(&queued_client_requests_);
40 } 41 }
41 42
42 void ApplicationInstance::InitializeApplication() { 43 void ApplicationInstance::InitializeApplication() {
43 ShellPtr shell; 44 ShellPtr shell;
44 binding_.Bind(GetProxy(&shell)); 45 binding_.Bind(GetProxy(&shell));
45 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); 46 binding_.set_connection_error_handler([this]() { OnConnectionError(); });
46 application_->Initialize(shell.Pass(), identity_.url().spec()); 47 application_->Initialize(std::move(shell), identity_.url().spec());
47 } 48 }
48 49
49 void ApplicationInstance::ConnectToClient( 50 void ApplicationInstance::ConnectToClient(
50 scoped_ptr<ConnectToApplicationParams> params) { 51 scoped_ptr<ConnectToApplicationParams> params) {
51 if (queue_requests_) { 52 if (queue_requests_) {
52 queued_client_requests_.push_back(params.release()); 53 queued_client_requests_.push_back(params.release());
53 return; 54 return;
54 } 55 }
55 56
56 CallAcceptConnection(params.Pass()); 57 CallAcceptConnection(std::move(params));
57 } 58 }
58 59
59 void ApplicationInstance::SetNativeRunner(NativeRunner* native_runner) { 60 void ApplicationInstance::SetNativeRunner(NativeRunner* native_runner) {
60 native_runner_ = native_runner; 61 native_runner_ = native_runner;
61 pid_ = native_runner_->GetApplicationPID(); 62 pid_ = native_runner_->GetApplicationPID();
62 } 63 }
63 64
64 base::ProcessId ApplicationInstance::GetProcessId() const { 65 base::ProcessId ApplicationInstance::GetProcessId() const {
65 return pid_; 66 return pid_;
66 } 67 }
(...skipping 16 matching lines...) Expand all
83 identity_.filter().find(url.spec()) != identity_.filter().end()) { 84 identity_.filter().find(url.spec()) != identity_.filter().end()) {
84 CapabilityFilter capability_filter = GetPermissiveCapabilityFilter(); 85 CapabilityFilter capability_filter = GetPermissiveCapabilityFilter();
85 if (!filter.is_null()) 86 if (!filter.is_null())
86 capability_filter = filter->filter.To<CapabilityFilter>(); 87 capability_filter = filter->filter.To<CapabilityFilter>();
87 88
88 scoped_ptr<ConnectToApplicationParams> params( 89 scoped_ptr<ConnectToApplicationParams> params(
89 new ConnectToApplicationParams); 90 new ConnectToApplicationParams);
90 params->SetSource(this); 91 params->SetSource(this);
91 GURL app_url(app_request->url); 92 GURL app_url(app_request->url);
92 params->SetTargetURLRequest( 93 params->SetTargetURLRequest(
93 app_request.Pass(), 94 std::move(app_request),
94 Identity(app_url, std::string(), capability_filter)); 95 Identity(app_url, std::string(), capability_filter));
95 params->set_services(services.Pass()); 96 params->set_services(std::move(services));
96 params->set_exposed_services(exposed_services.Pass()); 97 params->set_exposed_services(std::move(exposed_services));
97 params->set_connect_callback(callback); 98 params->set_connect_callback(callback);
98 manager_->ConnectToApplication(params.Pass()); 99 manager_->ConnectToApplication(std::move(params));
99 } else { 100 } else {
100 LOG(WARNING) << "CapabilityFilter prevented connection from: " << 101 LOG(WARNING) << "CapabilityFilter prevented connection from: " <<
101 identity_.url() << " to: " << url.spec(); 102 identity_.url() << " to: " << url.spec();
102 callback.Run(kInvalidContentHandlerID); 103 callback.Run(kInvalidContentHandlerID);
103 } 104 }
104 } 105 }
105 106
106 void ApplicationInstance::QuitApplication() { 107 void ApplicationInstance::QuitApplication() {
107 queue_requests_ = true; 108 queue_requests_ = true;
108 application_->OnQuitRequested( 109 application_->OnQuitRequested(
109 base::Bind(&ApplicationInstance::OnQuitRequestedResult, 110 base::Bind(&ApplicationInstance::OnQuitRequestedResult,
110 base::Unretained(this))); 111 base::Unretained(this)));
111 } 112 }
112 113
113 void ApplicationInstance::CallAcceptConnection( 114 void ApplicationInstance::CallAcceptConnection(
114 scoped_ptr<ConnectToApplicationParams> params) { 115 scoped_ptr<ConnectToApplicationParams> params) {
115 params->connect_callback().Run(requesting_content_handler_id_); 116 params->connect_callback().Run(requesting_content_handler_id_);
116 AllowedInterfaces interfaces; 117 AllowedInterfaces interfaces;
117 interfaces.insert("*"); 118 interfaces.insert("*");
118 if (!params->source().is_null()) 119 if (!params->source().is_null())
119 interfaces = GetAllowedInterfaces(params->source().filter(), identity_); 120 interfaces = GetAllowedInterfaces(params->source().filter(), identity_);
120 121
121 application_->AcceptConnection( 122 application_->AcceptConnection(
122 params->source().url().spec(), params->TakeServices(), 123 params->source().url().spec(), params->TakeServices(),
123 params->TakeExposedServices(), Array<String>::From(interfaces).Pass(), 124 params->TakeExposedServices(), Array<String>::From(interfaces),
124 params->target().url().spec()); 125 params->target().url().spec());
125 } 126 }
126 127
127 void ApplicationInstance::OnConnectionError() { 128 void ApplicationInstance::OnConnectionError() {
128 std::vector<ConnectToApplicationParams*> queued_client_requests; 129 std::vector<ConnectToApplicationParams*> queued_client_requests;
129 queued_client_requests_.swap(queued_client_requests); 130 queued_client_requests_.swap(queued_client_requests);
130 auto manager = manager_; 131 auto manager = manager_;
131 manager_->OnApplicationInstanceError(this); 132 manager_->OnApplicationInstanceError(this);
132 //|this| is deleted. 133 //|this| is deleted.
133 134
(...skipping 14 matching lines...) Expand all
148 // 6) connect_request_2 is queued (and eventually gets here), but its 149 // 6) connect_request_2 is queued (and eventually gets here), but its
149 // original_request field was already lost to NetworkFetcher at step (2). 150 // original_request field was already lost to NetworkFetcher at step (2).
150 // 151 //
151 // TODO(yzshen): It seems we should register a pending application instance 152 // TODO(yzshen): It seems we should register a pending application instance
152 // before starting the fetch. So at step (2) the application manager knows 153 // before starting the fetch. So at step (2) the application manager knows
153 // that it can wait for the first fetch to complete instead of doing a 154 // that it can wait for the first fetch to complete instead of doing a
154 // second one directly. 155 // second one directly.
155 if (!request->target_url_request()) { 156 if (!request->target_url_request()) {
156 URLRequestPtr url_request = mojo::URLRequest::New(); 157 URLRequestPtr url_request = mojo::URLRequest::New();
157 url_request->url = request->target().url().spec(); 158 url_request->url = request->target().url().spec();
158 request->SetTargetURLRequest(url_request.Pass(), request->target()); 159 request->SetTargetURLRequest(std::move(url_request), request->target());
159 } 160 }
160 manager->ConnectToApplication(make_scoped_ptr(request)); 161 manager->ConnectToApplication(make_scoped_ptr(request));
161 } 162 }
162 } 163 }
163 164
164 void ApplicationInstance::OnQuitRequestedResult(bool can_quit) { 165 void ApplicationInstance::OnQuitRequestedResult(bool can_quit) {
165 if (can_quit) 166 if (can_quit)
166 return; 167 return;
167 168
168 queue_requests_ = false; 169 queue_requests_ = false;
169 for (auto request : queued_client_requests_) 170 for (auto request : queued_client_requests_)
170 CallAcceptConnection(make_scoped_ptr(request)); 171 CallAcceptConnection(make_scoped_ptr(request));
171 172
172 queued_client_requests_.clear(); 173 queued_client_requests_.clear();
173 } 174 }
174 175
175 } // namespace shell 176 } // namespace shell
176 } // namespace mojo 177 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/runner/tracer.cc ('k') | mojo/shell/application_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698