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

Side by Side Diff: services/shell/shell.cc

Issue 1877753003: Move mojo\shell to services\shell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@62scan
Patch Set: . 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
« no previous file with comments | « services/shell/shell.h ('k') | services/shell/standalone/BUILD.gn » ('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 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 "mojo/shell/shell.h" 5 #include "services/shell/shell.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/guid.h" 13 #include "base/guid.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/process/process.h" 16 #include "base/process/process.h"
17 #include "base/process/process_handle.h" 17 #include "base/process/process_handle.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/trace_event/trace_event.h" 20 #include "base/trace_event/trace_event.h"
21 #include "mojo/common/url_type_converters.h" 21 #include "mojo/common/url_type_converters.h"
22 #include "mojo/public/cpp/bindings/binding.h" 22 #include "mojo/public/cpp/bindings/binding.h"
23 #include "mojo/public/cpp/bindings/binding_set.h" 23 #include "mojo/public/cpp/bindings/binding_set.h"
24 #include "mojo/shell/connect_util.h"
25 #include "mojo/shell/public/cpp/connector.h"
26 #include "mojo/shell/public/cpp/names.h"
27 #include "mojo/shell/public/cpp/shell_connection.h"
28 #include "mojo/shell/public/interfaces/connector.mojom.h"
29 #include "mojo/shell/public/interfaces/shell.mojom.h"
30 #include "mojo/shell/public/interfaces/shell_client.mojom.h"
31 #include "mojo/util/filename_util.h" 24 #include "mojo/util/filename_util.h"
25 #include "services/shell/connect_util.h"
26 #include "services/shell/public/cpp/connector.h"
27 #include "services/shell/public/cpp/names.h"
28 #include "services/shell/public/cpp/shell_connection.h"
29 #include "services/shell/public/interfaces/connector.mojom.h"
30 #include "services/shell/public/interfaces/shell.mojom.h"
31 #include "services/shell/public/interfaces/shell_client.mojom.h"
32 #include "url/gurl.h" 32 #include "url/gurl.h"
33 33
34 namespace mojo { 34 namespace mojo {
35 namespace shell { 35 namespace shell {
36 namespace { 36 namespace {
37 const char kCatalogName[] = "mojo:catalog"; 37 const char kCatalogName[] = "mojo:catalog";
38 const char kShellName[] = "mojo:shell"; 38 const char kShellName[] = "mojo:shell";
39 const char kCapabilityClass_UserID[] = "user_id"; 39 const char kCapabilityClass_UserID[] = "user_id";
40 const char kCapabilityClass_ClientProcess[] = "client_process"; 40 const char kCapabilityClass_ClientProcess[] = "client_process";
41 const char kCapabilityClass_InstanceName[] = "instance_name"; 41 const char kCapabilityClass_InstanceName[] = "instance_name";
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 102 }
103 103
104 // Encapsulates a connection to an instance of an application, tracked by the 104 // Encapsulates a connection to an instance of an application, tracked by the
105 // shell's Shell. 105 // shell's Shell.
106 class Shell::Instance : public mojom::Connector, 106 class Shell::Instance : public mojom::Connector,
107 public mojom::PIDReceiver, 107 public mojom::PIDReceiver,
108 public ShellClient, 108 public ShellClient,
109 public InterfaceFactory<mojom::Shell>, 109 public InterfaceFactory<mojom::Shell>,
110 public mojom::Shell { 110 public mojom::Shell {
111 public: 111 public:
112 Instance(mojo::shell::Shell* shell, 112 Instance(shell::Shell* shell,
113 const Identity& identity, 113 const Identity& identity,
114 const CapabilitySpec& capability_spec) 114 const CapabilitySpec& capability_spec)
115 : shell_(shell), 115 : shell_(shell),
116 id_(GenerateUniqueID()), 116 id_(GenerateUniqueID()),
117 identity_(identity), 117 identity_(identity),
118 capability_spec_(capability_spec), 118 capability_spec_(capability_spec),
119 allow_any_application_(capability_spec.required.count("*") == 1), 119 allow_any_application_(capability_spec.required.count("*") == 1),
120 pid_receiver_binding_(this), 120 pid_receiver_binding_(this),
121 weak_factory_(this) { 121 weak_factory_(this) {
122 if (identity_.name() == kShellName || 122 if (identity_.name() == kShellName ||
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 } 188 }
189 189
190 void StartWithFilePath(const base::FilePath& path) { 190 void StartWithFilePath(const base::FilePath& path) {
191 CHECK(!shell_client_); 191 CHECK(!shell_client_);
192 scoped_ptr<NativeRunner> runner = 192 scoped_ptr<NativeRunner> runner =
193 shell_->native_runner_factory_->Create(path); 193 shell_->native_runner_factory_->Create(path);
194 bool start_sandboxed = false; 194 bool start_sandboxed = false;
195 mojom::ShellClientPtr client = runner->Start( 195 mojom::ShellClientPtr client = runner->Start(
196 path, identity_, start_sandboxed, 196 path, identity_, start_sandboxed,
197 base::Bind(&Instance::PIDAvailable, weak_factory_.GetWeakPtr()), 197 base::Bind(&Instance::PIDAvailable, weak_factory_.GetWeakPtr()),
198 base::Bind(&mojo::shell::Shell::CleanupRunner, 198 base::Bind(&shell::Shell::CleanupRunner,
199 shell_->weak_ptr_factory_.GetWeakPtr(), runner.get())); 199 shell_->weak_ptr_factory_.GetWeakPtr(), runner.get()));
200 shell_->native_runners_.push_back(std::move(runner)); 200 shell_->native_runners_.push_back(std::move(runner));
201 StartWithClient(std::move(client)); 201 StartWithClient(std::move(client));
202 } 202 }
203 203
204 mojom::InstanceInfoPtr CreateInstanceInfo() const { 204 mojom::InstanceInfoPtr CreateInstanceInfo() const {
205 mojom::InstanceInfoPtr info(mojom::InstanceInfo::New()); 205 mojom::InstanceInfoPtr info(mojom::InstanceInfo::New());
206 info->id = id_; 206 info->id = id_;
207 info->identity = mojom::Identity::From(identity_); 207 info->identity = mojom::Identity::From(identity_);
208 info->pid = pid_; 208 info->pid = pid_;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 ++id; 372 ++id;
373 CHECK_NE(mojom::kInvalidInstanceID, id); 373 CHECK_NE(mojom::kInvalidInstanceID, id);
374 return id; 374 return id;
375 } 375 }
376 376
377 void PIDAvailable(base::ProcessId pid) { 377 void PIDAvailable(base::ProcessId pid) {
378 pid_ = pid; 378 pid_ = pid;
379 shell_->NotifyPIDAvailable(id_, pid_); 379 shell_->NotifyPIDAvailable(id_, pid_);
380 } 380 }
381 381
382 void OnShellClientLost(base::WeakPtr<mojo::shell::Shell> shell) { 382 void OnShellClientLost(base::WeakPtr<shell::Shell> shell) {
383 shell_client_.reset(); 383 shell_client_.reset();
384 OnConnectionLost(shell); 384 OnConnectionLost(shell);
385 } 385 }
386 386
387 void OnConnectionLost(base::WeakPtr<mojo::shell::Shell> shell) { 387 void OnConnectionLost(base::WeakPtr<shell::Shell> shell) {
388 // Any time a Connector is lost or we lose the ShellClient connection, it 388 // Any time a Connector is lost or we lose the ShellClient connection, it
389 // may have been the last pipe using this Instance. If so, clean up. 389 // may have been the last pipe using this Instance. If so, clean up.
390 if (shell && connectors_.empty() && !shell_client_) { 390 if (shell && connectors_.empty() && !shell_client_) {
391 // Deletes |this|. 391 // Deletes |this|.
392 shell->OnInstanceError(this); 392 shell->OnInstanceError(this);
393 } 393 }
394 } 394 }
395 395
396 void OnInitializeResponse(mojom::ConnectorRequest connector_request) { 396 void OnInitializeResponse(mojom::ConnectorRequest connector_request) {
397 if (connector_request.is_pending()) { 397 if (connector_request.is_pending()) {
398 connectors_.AddBinding(this, std::move(connector_request)); 398 connectors_.AddBinding(this, std::move(connector_request));
399 connectors_.set_connection_error_handler( 399 connectors_.set_connection_error_handler(
400 base::Bind(&Instance::OnConnectionLost, base::Unretained(this), 400 base::Bind(&Instance::OnConnectionLost, base::Unretained(this),
401 shell_->GetWeakPtr())); 401 shell_->GetWeakPtr()));
402 } 402 }
403 } 403 }
404 404
405 mojo::shell::Shell* const shell_; 405 shell::Shell* const shell_;
406 406
407 // An id that identifies this instance. Distinct from pid, as a single process 407 // An id that identifies this instance. Distinct from pid, as a single process
408 // may vend multiple application instances, and this object may exist before a 408 // may vend multiple application instances, and this object may exist before a
409 // process is launched. 409 // process is launched.
410 const uint32_t id_; 410 const uint32_t id_;
411 const Identity identity_; 411 const Identity identity_;
412 const CapabilitySpec capability_spec_; 412 const CapabilitySpec capability_spec_;
413 const bool allow_any_application_; 413 const bool allow_any_application_;
414 mojom::ShellClientPtr shell_client_; 414 mojom::ShellClientPtr shell_client_;
415 Binding<mojom::PIDReceiver> pid_receiver_binding_; 415 Binding<mojom::PIDReceiver> pid_receiver_binding_;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 518
519 void Shell::InitCatalog(mojom::ShellClientPtr catalog) { 519 void Shell::InitCatalog(mojom::ShellClientPtr catalog) {
520 Instance* instance = CreateInstance(CreateShellIdentity(), 520 Instance* instance = CreateInstance(CreateShellIdentity(),
521 CreateCatalogIdentity(), 521 CreateCatalogIdentity(),
522 CapabilitySpec()); 522 CapabilitySpec());
523 singletons_.insert(kCatalogName); 523 singletons_.insert(kCatalogName);
524 instance->StartWithClient(std::move(catalog)); 524 instance->StartWithClient(std::move(catalog));
525 525
526 // TODO(beng): this doesn't work anymore. 526 // TODO(beng): this doesn't work anymore.
527 // Seed the catalog with manifest info for the shell & catalog. 527 // Seed the catalog with manifest info for the shell & catalog.
528 mojo::shell::mojom::ShellResolverPtr resolver; 528 shell::mojom::ShellResolverPtr resolver;
529 shell_connection_->connector()->ConnectToInterface(kCatalogName, &resolver); 529 shell_connection_->connector()->ConnectToInterface(kCatalogName, &resolver);
530 resolver->ResolveMojoName(kCatalogName, base::Bind(&EmptyResolverCallback)); 530 resolver->ResolveMojoName(kCatalogName, base::Bind(&EmptyResolverCallback));
531 resolver->ResolveMojoName(kShellName, base::Bind(&EmptyResolverCallback)); 531 resolver->ResolveMojoName(kShellName, base::Bind(&EmptyResolverCallback));
532 } 532 }
533 533
534 void Shell::TerminateShellConnections() { 534 void Shell::TerminateShellConnections() {
535 Instance* instance = GetExistingInstance(CreateShellIdentity()); 535 Instance* instance = GetExistingInstance(CreateShellIdentity());
536 DCHECK(instance); 536 DCHECK(instance);
537 OnInstanceError(instance); 537 OnInstanceError(instance);
538 } 538 }
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) { 782 for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) {
783 if (it->get() == runner) { 783 if (it->get() == runner) {
784 native_runners_.erase(it); 784 native_runners_.erase(it);
785 return; 785 return;
786 } 786 }
787 } 787 }
788 } 788 }
789 789
790 } // namespace shell 790 } // namespace shell
791 } // namespace mojo 791 } // namespace mojo
OLDNEW
« no previous file with comments | « services/shell/shell.h ('k') | services/shell/standalone/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698