Chromium Code Reviews| 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> | |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "mojo/edk/embedder/process_delegate.h" | 14 #include "mojo/edk/embedder/process_delegate.h" |
| 14 #include "mojo/runner/scoped_user_data_dir.h" | 15 #include "mojo/runner/scoped_user_data_dir.h" |
| 15 #include "mojo/runner/task_runners.h" | 16 #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" | |
| 18 | 19 |
| 19 namespace mojo { | 20 namespace mojo { |
| 20 namespace runner { | 21 namespace runner { |
| 21 | 22 |
| 22 class NativeApplicationLoader; | 23 class NativeApplicationLoader; |
| 23 | 24 |
| 24 // The "global" context for the shell's main process. | 25 // The "global" context for the shell's main process. |
| 25 class Context : public shell::ApplicationManager::Delegate, | 26 class Context : public embedder::ProcessDelegate { |
| 26 public embedder::ProcessDelegate { | |
| 27 public: | 27 public: |
| 28 Context(); | 28 Context(const base::FilePath& shell_file_root); |
|
sky
2015/09/11 23:05:27
explicit.
| |
| 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 | |
| 51 // This must be called with a message loop set up for the current thread, | 33 // This must be called with a message loop set up for the current thread, |
| 52 // which must remain alive until after Shutdown() is called. Returns true on | 34 // which must remain alive until after Shutdown() is called. Returns true on |
| 53 // success. | 35 // success. |
| 54 bool Init(); | 36 bool Init(); |
| 55 | 37 |
| 56 // If Init() was called and succeeded, this must be called before destruction. | 38 // If Init() was called and succeeded, this must be called before destruction. |
| 57 void Shutdown(); | 39 void Shutdown(); |
| 58 | 40 |
| 59 // NOTE: call either Run() or RunCommandLineApplication(), but not both. | 41 // NOTE: call either Run() or RunCommandLineApplication(), but not both. |
| 60 | 42 |
| 61 // Runs the app specified by |url|. | 43 // Runs the app specified by |url|. |
| 62 void Run(const GURL& url); | 44 void Run(const GURL& url); |
| 63 | 45 |
| 64 // Run the application specified on the commandline. When the app finishes, | 46 // Run the application specified on the commandline. When the app finishes, |
| 65 // |callback| is run if not null, otherwise the message loop is quit. | 47 // |callback| is run if not null, otherwise the message loop is quit. |
| 66 void RunCommandLineApplication(const base::Closure& callback); | 48 void RunCommandLineApplication(const base::Closure& callback); |
| 67 | 49 |
| 68 TaskRunners* task_runners() { return task_runners_.get(); } | 50 TaskRunners* task_runners() { return task_runners_.get(); } |
| 69 shell::ApplicationManager* application_manager() { | 51 shell::ApplicationManager* application_manager() { |
| 70 return &application_manager_; | 52 return application_manager_.get(); |
| 71 } | 53 } |
| 72 URLResolver* url_resolver() { return &url_resolver_; } | |
| 73 | 54 |
| 74 private: | 55 private: |
| 75 class NativeViewportApplicationLoader; | 56 class NativeViewportApplicationLoader; |
| 76 | 57 |
| 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 | |
| 84 // ProcessDelegate implementation. | 58 // ProcessDelegate implementation. |
| 85 void OnShutdownComplete() override; | 59 void OnShutdownComplete() override; |
| 86 | 60 |
| 87 void OnApplicationEnd(const GURL& url); | 61 void OnApplicationEnd(const GURL& url); |
| 88 | 62 |
| 89 ScopedUserDataDir scoped_user_data_dir; | 63 ScopedUserDataDir scoped_user_data_dir; |
| 90 std::set<GURL> app_urls_; | 64 std::set<GURL> app_urls_; |
| 91 scoped_ptr<TaskRunners> task_runners_; | 65 scoped_ptr<TaskRunners> task_runners_; |
| 92 shell::ApplicationManager application_manager_; | 66 scoped_ptr<shell::ApplicationManager> application_manager_; |
| 93 URLResolver url_resolver_; | |
| 94 GURL shell_file_root_; | |
| 95 GURL command_line_cwd_; | |
| 96 base::Closure app_complete_callback_; | 67 base::Closure app_complete_callback_; |
| 97 base::Time main_entry_time_; | 68 base::Time main_entry_time_; |
| 98 | 69 |
| 99 DISALLOW_COPY_AND_ASSIGN(Context); | 70 DISALLOW_COPY_AND_ASSIGN(Context); |
| 100 }; | 71 }; |
| 101 | 72 |
| 102 } // namespace runner | 73 } // namespace runner |
| 103 } // namespace mojo | 74 } // namespace mojo |
| 104 | 75 |
| 105 #endif // MOJO_RUNNER_CONTEXT_H_ | 76 #endif // MOJO_RUNNER_CONTEXT_H_ |
| OLD | NEW |