| OLD | NEW |
| 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 #ifndef SERVICES_SHELL_PUBLIC_CPP_APPLICATION_RUNNER_H_ | 5 #ifndef SERVICES_SHELL_PUBLIC_CPP_APPLICATION_RUNNER_H_ |
| 6 #define SERVICES_SHELL_PUBLIC_CPP_APPLICATION_RUNNER_H_ | 6 #define SERVICES_SHELL_PUBLIC_CPP_APPLICATION_RUNNER_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include <memory> |
| 9 |
| 9 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 10 #include "mojo/public/cpp/system/core.h" | 11 #include "mojo/public/cpp/system/core.h" |
| 11 | 12 |
| 12 namespace mojo { | 13 namespace shell { |
| 13 | 14 |
| 14 class ShellClient; | 15 class ShellClient; |
| 15 class ShellConnection; | 16 class ShellConnection; |
| 16 | 17 |
| 17 // A utility for running a chromium based mojo Application. The typical use | 18 // A utility for running a chromium based mojo Application. The typical use |
| 18 // case is to use when writing your MojoMain: | 19 // case is to use when writing your MojoMain: |
| 19 // | 20 // |
| 20 // MojoResult MojoMain(MojoHandle shell_handle) { | 21 // MojoResult MojoMain(MojoHandle shell_handle) { |
| 21 // mojo::ApplicationRunner runner(new MyDelegate()); | 22 // shell::ApplicationRunner runner(new MyDelegate()); |
| 22 // return runner.Run(shell_handle); | 23 // return runner.Run(shell_handle); |
| 23 // } | 24 // } |
| 24 // | 25 // |
| 25 // ApplicationRunner takes care of chromium environment initialization and | 26 // ApplicationRunner takes care of chromium environment initialization and |
| 26 // shutdown, and starting a MessageLoop from which your application can run and | 27 // shutdown, and starting a MessageLoop from which your application can run and |
| 27 // ultimately Quit(). | 28 // ultimately Quit(). |
| 28 class ApplicationRunner { | 29 class ApplicationRunner { |
| 29 public: | 30 public: |
| 30 // Takes ownership of |client|. | 31 // Takes ownership of |client|. |
| 31 explicit ApplicationRunner(ShellClient* client); | 32 explicit ApplicationRunner(ShellClient* client); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 51 // shell notices the pipe has closed, it will no longer track an instance of | 52 // shell notices the pipe has closed, it will no longer track an instance of |
| 52 // this application, though this application may continue to run and service | 53 // this application, though this application may continue to run and service |
| 53 // requests from others. | 54 // requests from others. |
| 54 void DestroyShellConnection(); | 55 void DestroyShellConnection(); |
| 55 | 56 |
| 56 // Allows the caller to explicitly quit the application. Must be called from | 57 // Allows the caller to explicitly quit the application. Must be called from |
| 57 // the thread which created the ApplicationRunner. | 58 // the thread which created the ApplicationRunner. |
| 58 void Quit(); | 59 void Quit(); |
| 59 | 60 |
| 60 private: | 61 private: |
| 61 scoped_ptr<ShellConnection> connection_; | 62 std::unique_ptr<ShellConnection> connection_; |
| 62 scoped_ptr<ShellClient> client_; | 63 std::unique_ptr<ShellClient> client_; |
| 63 | 64 |
| 64 // MessageLoop type. TYPE_CUSTOM is default (MessagePumpMojo will be used as | 65 // MessageLoop type. TYPE_CUSTOM is default (MessagePumpMojo will be used as |
| 65 // the underlying message pump). | 66 // the underlying message pump). |
| 66 base::MessageLoop::Type message_loop_type_; | 67 base::MessageLoop::Type message_loop_type_; |
| 67 // Whether Run() has been called. | 68 // Whether Run() has been called. |
| 68 bool has_run_; | 69 bool has_run_; |
| 69 | 70 |
| 70 DISALLOW_COPY_AND_ASSIGN(ApplicationRunner); | 71 DISALLOW_COPY_AND_ASSIGN(ApplicationRunner); |
| 71 }; | 72 }; |
| 72 | 73 |
| 73 } // namespace mojo | 74 } // namespace shell |
| 74 | 75 |
| 75 #endif // SERVICES_SHELL_PUBLIC_CPP_APPLICATION_RUNNER_H_ | 76 #endif // SERVICES_SHELL_PUBLIC_CPP_APPLICATION_RUNNER_H_ |
| OLD | NEW |