| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <memory> | 6 #include <memory> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "mojo/public/c/system/main.h" | 10 #include "mojo/public/c/system/main.h" |
| 11 #include "mojo/public/cpp/bindings/binding_set.h" | 11 #include "mojo/public/cpp/bindings/binding_set.h" |
| 12 #include "services/shell/public/cpp/application_runner.h" | 12 #include "services/shell/public/cpp/application_runner.h" |
| 13 #include "services/shell/public/cpp/shell_connection.h" | 13 #include "services/shell/public/cpp/service_context.h" |
| 14 #include "services/shell/public/interfaces/service_factory.mojom.h" | 14 #include "services/shell/public/interfaces/service_factory.mojom.h" |
| 15 #include "services/shell/tests/lifecycle/app_client.h" | 15 #include "services/shell/tests/lifecycle/app_client.h" |
| 16 #include "services/shell/tests/lifecycle/lifecycle_unittest.mojom.h" | 16 #include "services/shell/tests/lifecycle/lifecycle_unittest.mojom.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 class PackagedApp : public shell::Service, | 20 class PackagedApp : public shell::Service, |
| 21 public shell::InterfaceFactory<LifecycleControl>, | 21 public shell::InterfaceFactory<LifecycleControl>, |
| 22 public LifecycleControl { | 22 public LifecycleControl { |
| 23 public: | 23 public: |
| 24 using DestructCallback = base::Callback<void(PackagedApp*)>; | 24 using DestructCallback = base::Callback<void(PackagedApp*)>; |
| 25 | 25 |
| 26 PackagedApp(shell::mojom::ServiceRequest request, | 26 PackagedApp(shell::mojom::ServiceRequest request, |
| 27 const DestructCallback& shell_connection_closed_callback, | 27 const DestructCallback& shell_connection_closed_callback, |
| 28 const DestructCallback& destruct_callback) | 28 const DestructCallback& destruct_callback) |
| 29 : connection_(new shell::ShellConnection(this, std::move(request))), | 29 : connection_(new shell::ServiceContext(this, std::move(request))), |
| 30 shell_connection_closed_callback_(shell_connection_closed_callback), | 30 shell_connection_closed_callback_(shell_connection_closed_callback), |
| 31 destruct_callback_(destruct_callback) { | 31 destruct_callback_(destruct_callback) { |
| 32 bindings_.set_connection_error_handler(base::Bind(&PackagedApp::BindingLost, | 32 bindings_.set_connection_error_handler(base::Bind(&PackagedApp::BindingLost, |
| 33 base::Unretained(this))); | 33 base::Unretained(this))); |
| 34 } | 34 } |
| 35 ~PackagedApp() override { | 35 ~PackagedApp() override { |
| 36 destruct_callback_.Run(this); | 36 destruct_callback_.Run(this); |
| 37 } | 37 } |
| 38 | 38 |
| 39 private: | 39 private: |
| (...skipping 28 matching lines...) Expand all Loading... |
| 68 connection_.reset(); | 68 connection_.reset(); |
| 69 // This only closed our relationship with the shell, existing |bindings_| | 69 // This only closed our relationship with the shell, existing |bindings_| |
| 70 // remain active. | 70 // remain active. |
| 71 } | 71 } |
| 72 | 72 |
| 73 void BindingLost() { | 73 void BindingLost() { |
| 74 if (bindings_.empty()) | 74 if (bindings_.empty()) |
| 75 delete this; | 75 delete this; |
| 76 } | 76 } |
| 77 | 77 |
| 78 std::unique_ptr<shell::ShellConnection> connection_; | 78 std::unique_ptr<shell::ServiceContext> connection_; |
| 79 mojo::BindingSet<LifecycleControl> bindings_; | 79 mojo::BindingSet<LifecycleControl> bindings_; |
| 80 // Run when this object's connection to the shell is closed. | 80 // Run when this object's connection to the shell is closed. |
| 81 DestructCallback shell_connection_closed_callback_; | 81 DestructCallback shell_connection_closed_callback_; |
| 82 // Run when this object is destructed. | 82 // Run when this object is destructed. |
| 83 DestructCallback destruct_callback_; | 83 DestructCallback destruct_callback_; |
| 84 | 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(PackagedApp); | 85 DISALLOW_COPY_AND_ASSIGN(PackagedApp); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 class Package | 88 class Package |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 }; | 144 }; |
| 145 | 145 |
| 146 } // namespace | 146 } // namespace |
| 147 | 147 |
| 148 MojoResult MojoMain(MojoHandle shell_handle) { | 148 MojoResult MojoMain(MojoHandle shell_handle) { |
| 149 Package* package = new Package; | 149 Package* package = new Package; |
| 150 shell::ApplicationRunner runner(package); | 150 shell::ApplicationRunner runner(package); |
| 151 package->set_runner(&runner); | 151 package->set_runner(&runner); |
| 152 return runner.Run(shell_handle); | 152 return runner.Run(shell_handle); |
| 153 } | 153 } |
| OLD | NEW |