| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MOJO_SHELL_PUBLIC_CPP_APPLICATION_RUNNER_H_ | |
| 6 #define MOJO_SHELL_PUBLIC_CPP_APPLICATION_RUNNER_H_ | |
| 7 | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/message_loop/message_loop.h" | |
| 10 #include "mojo/public/cpp/system/core.h" | |
| 11 | |
| 12 namespace mojo { | |
| 13 | |
| 14 class ShellClient; | |
| 15 class ShellConnection; | |
| 16 | |
| 17 // A utility for running a chromium based mojo Application. The typical use | |
| 18 // case is to use when writing your MojoMain: | |
| 19 // | |
| 20 // MojoResult MojoMain(MojoHandle shell_handle) { | |
| 21 // mojo::ApplicationRunner runner(new MyDelegate()); | |
| 22 // return runner.Run(shell_handle); | |
| 23 // } | |
| 24 // | |
| 25 // ApplicationRunner takes care of chromium environment initialization and | |
| 26 // shutdown, and starting a MessageLoop from which your application can run and | |
| 27 // ultimately Quit(). | |
| 28 class ApplicationRunner { | |
| 29 public: | |
| 30 // Takes ownership of |client|. | |
| 31 explicit ApplicationRunner(ShellClient* client); | |
| 32 ~ApplicationRunner(); | |
| 33 | |
| 34 static void InitBaseCommandLine(); | |
| 35 | |
| 36 void set_message_loop_type(base::MessageLoop::Type type); | |
| 37 | |
| 38 // Once the various parameters have been set above, use Run to initialize an | |
| 39 // ShellConnection wired to the provided delegate, and run a MessageLoop until | |
| 40 // the application exits. | |
| 41 // | |
| 42 // Iff |init_base| is true, the runner will perform some initialization of | |
| 43 // base globals (e.g. CommandLine and AtExitManager) before starting the | |
| 44 // application. | |
| 45 MojoResult Run(MojoHandle shell_handle, bool init_base); | |
| 46 | |
| 47 // Calls Run above with |init_base| set to |true|. | |
| 48 MojoResult Run(MojoHandle shell_handle); | |
| 49 | |
| 50 // Allows the caller to shut down the connection with the shell. After the | |
| 51 // 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 // requests from others. | |
| 54 void DestroyShellConnection(); | |
| 55 | |
| 56 // Allows the caller to explicitly quit the application. Must be called from | |
| 57 // the thread which created the ApplicationRunner. | |
| 58 void Quit(); | |
| 59 | |
| 60 private: | |
| 61 scoped_ptr<ShellConnection> connection_; | |
| 62 scoped_ptr<ShellClient> client_; | |
| 63 | |
| 64 // MessageLoop type. TYPE_CUSTOM is default (MessagePumpMojo will be used as | |
| 65 // the underlying message pump). | |
| 66 base::MessageLoop::Type message_loop_type_; | |
| 67 // Whether Run() has been called. | |
| 68 bool has_run_; | |
| 69 | |
| 70 DISALLOW_COPY_AND_ASSIGN(ApplicationRunner); | |
| 71 }; | |
| 72 | |
| 73 } // namespace mojo | |
| 74 | |
| 75 #endif // MOJO_SHELL_PUBLIC_CPP_APPLICATION_RUNNER_H_ | |
| OLD | NEW |