| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 MOJO_RUNNER_CONTEXT_H_ | 5 #ifndef MOJO_RUNNER_CONTEXT_H_ |
| 6 #define MOJO_RUNNER_CONTEXT_H_ | 6 #define MOJO_RUNNER_CONTEXT_H_ |
| 7 | 7 |
| 8 #include <set> | |
| 9 #include <string> | 8 #include <string> |
| 10 | 9 |
| 11 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 12 #include "base/macros.h" | 11 #include "base/macros.h" |
| 13 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 14 #include "mojo/edk/embedder/process_delegate.h" | 13 #include "mojo/edk/embedder/process_delegate.h" |
| 15 #include "mojo/runner/scoped_user_data_dir.h" | 14 #include "mojo/runner/scoped_user_data_dir.h" |
| 16 #include "mojo/runner/task_runners.h" | 15 #include "mojo/runner/task_runners.h" |
| 16 #include "mojo/runner/url_resolver.h" |
| 17 #include "mojo/shell/application_manager.h" | 17 #include "mojo/shell/application_manager.h" |
| 18 #include "url/gurl.h" | |
| 19 | 18 |
| 20 namespace mojo { | 19 namespace mojo { |
| 21 namespace runner { | 20 namespace runner { |
| 22 | 21 |
| 23 class NativeApplicationLoader; | 22 class NativeApplicationLoader; |
| 24 | 23 |
| 25 // The "global" context for the shell's main process. | 24 // The "global" context for the shell's main process. |
| 26 class Context : public embedder::ProcessDelegate { | 25 class Context : public shell::ApplicationManager::Delegate, |
| 26 public embedder::ProcessDelegate { |
| 27 public: | 27 public: |
| 28 explicit Context(const base::FilePath& shell_file_root); | 28 Context(); |
| 29 ~Context() override; | 29 ~Context() override; |
| 30 | 30 |
| 31 static void EnsureEmbedderIsInitialized(); | 31 static void EnsureEmbedderIsInitialized(); |
| 32 | 32 |
| 33 // Point to the directory containing installed services, such as the network |
| 34 // service. By default this directory is used as the base URL for resolving |
| 35 // unknown mojo: URLs. The network service will be loaded from this directory, |
| 36 // even when the base URL for unknown mojo: URLs is overridden. |
| 37 void SetShellFileRoot(const base::FilePath& path); |
| 38 |
| 39 // Resolve an URL relative to the shell file root. This is a nop for |
| 40 // everything but relative file URLs or URLs without a scheme. |
| 41 GURL ResolveShellFileURL(const std::string& path); |
| 42 |
| 43 // Override the CWD, which is used for resolving file URLs passed in from the |
| 44 // command line. |
| 45 void SetCommandLineCWD(const base::FilePath& path); |
| 46 |
| 47 // Resolve an URL relative to the CWD mojo_shell was invoked from. This is a |
| 48 // nop for everything but relative file URLs or URLs without a scheme. |
| 49 GURL ResolveCommandLineURL(const std::string& path); |
| 50 |
| 33 // This must be called with a message loop set up for the current thread, | 51 // This must be called with a message loop set up for the current thread, |
| 34 // which must remain alive until after Shutdown() is called. Returns true on | 52 // which must remain alive until after Shutdown() is called. Returns true on |
| 35 // success. | 53 // success. |
| 36 bool Init(); | 54 bool Init(); |
| 37 | 55 |
| 38 // If Init() was called and succeeded, this must be called before destruction. | 56 // If Init() was called and succeeded, this must be called before destruction. |
| 39 void Shutdown(); | 57 void Shutdown(); |
| 40 | 58 |
| 41 // NOTE: call either Run() or RunCommandLineApplication(), but not both. | 59 // NOTE: call either Run() or RunCommandLineApplication(), but not both. |
| 42 | 60 |
| 43 // Runs the app specified by |url|. | 61 // Runs the app specified by |url|. |
| 44 void Run(const GURL& url); | 62 void Run(const GURL& url); |
| 45 | 63 |
| 46 // Run the application specified on the commandline. When the app finishes, | 64 // Run the application specified on the commandline. When the app finishes, |
| 47 // |callback| is run if not null, otherwise the message loop is quit. | 65 // |callback| is run if not null, otherwise the message loop is quit. |
| 48 void RunCommandLineApplication(const base::Closure& callback); | 66 void RunCommandLineApplication(const base::Closure& callback); |
| 49 | 67 |
| 50 TaskRunners* task_runners() { return task_runners_.get(); } | 68 TaskRunners* task_runners() { return task_runners_.get(); } |
| 51 shell::ApplicationManager* application_manager() { | 69 shell::ApplicationManager* application_manager() { |
| 52 return application_manager_.get(); | 70 return &application_manager_; |
| 53 } | 71 } |
| 72 URLResolver* url_resolver() { return &url_resolver_; } |
| 54 | 73 |
| 55 private: | 74 private: |
| 56 class NativeViewportApplicationLoader; | 75 class NativeViewportApplicationLoader; |
| 57 | 76 |
| 77 // ApplicationManager::Delegate overrides. |
| 78 GURL ResolveMappings(const GURL& url) override; |
| 79 GURL ResolveMojoURL(const GURL& url) override; |
| 80 bool CreateFetcher( |
| 81 const GURL& url, |
| 82 const shell::Fetcher::FetchCallback& loader_callback) override; |
| 83 |
| 58 // ProcessDelegate implementation. | 84 // ProcessDelegate implementation. |
| 59 void OnShutdownComplete() override; | 85 void OnShutdownComplete() override; |
| 60 | 86 |
| 61 void OnApplicationEnd(const GURL& url); | 87 void OnApplicationEnd(const GURL& url); |
| 62 | 88 |
| 63 ScopedUserDataDir scoped_user_data_dir; | 89 ScopedUserDataDir scoped_user_data_dir; |
| 64 std::set<GURL> app_urls_; | 90 std::set<GURL> app_urls_; |
| 65 scoped_ptr<TaskRunners> task_runners_; | 91 scoped_ptr<TaskRunners> task_runners_; |
| 66 scoped_ptr<shell::ApplicationManager> application_manager_; | 92 shell::ApplicationManager application_manager_; |
| 93 URLResolver url_resolver_; |
| 94 GURL shell_file_root_; |
| 95 GURL command_line_cwd_; |
| 67 base::Closure app_complete_callback_; | 96 base::Closure app_complete_callback_; |
| 68 base::Time main_entry_time_; | 97 base::Time main_entry_time_; |
| 69 | 98 |
| 70 DISALLOW_COPY_AND_ASSIGN(Context); | 99 DISALLOW_COPY_AND_ASSIGN(Context); |
| 71 }; | 100 }; |
| 72 | 101 |
| 73 } // namespace runner | 102 } // namespace runner |
| 74 } // namespace mojo | 103 } // namespace mojo |
| 75 | 104 |
| 76 #endif // MOJO_RUNNER_CONTEXT_H_ | 105 #endif // MOJO_RUNNER_CONTEXT_H_ |
| OLD | NEW |