Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / mojo / runner / context.h
blob7e15a77b77dda3d61cc98743a22b74f4be59e3df
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
3 // found in the LICENSE file.
5 #ifndef MOJO_RUNNER_CONTEXT_H_
6 #define MOJO_RUNNER_CONTEXT_H_
8 #include <string>
10 #include "base/callback_forward.h"
11 #include "base/macros.h"
12 #include "base/time/time.h"
13 #include "mojo/edk/embedder/process_delegate.h"
14 #include "mojo/runner/scoped_user_data_dir.h"
15 #include "mojo/runner/task_runners.h"
16 #include "mojo/runner/url_resolver.h"
17 #include "mojo/shell/application_manager.h"
19 namespace mojo {
20 namespace runner {
22 class NativeApplicationLoader;
24 // The "global" context for the shell's main process.
25 class Context : public shell::ApplicationManager::Delegate,
26 public embedder::ProcessDelegate {
27 public:
28 Context();
29 ~Context() override;
31 static void EnsureEmbedderIsInitialized();
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);
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);
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);
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);
51 // 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
53 // success.
54 bool Init();
56 // If Init() was called and succeeded, this must be called before destruction.
57 void Shutdown();
59 // NOTE: call either Run() or RunCommandLineApplication(), but not both.
61 // Runs the app specified by |url|.
62 void Run(const GURL& url);
64 // Run the application specified on the commandline. When the app finishes,
65 // |callback| is run if not null, otherwise the message loop is quit.
66 void RunCommandLineApplication(const base::Closure& callback);
68 TaskRunners* task_runners() { return task_runners_.get(); }
69 shell::ApplicationManager* application_manager() {
70 return &application_manager_;
72 URLResolver* url_resolver() { return &url_resolver_; }
74 private:
75 class NativeViewportApplicationLoader;
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;
84 // ProcessDelegate implementation.
85 void OnShutdownComplete() override;
87 void OnApplicationEnd(const GURL& url);
89 ScopedUserDataDir scoped_user_data_dir;
90 std::set<GURL> app_urls_;
91 scoped_ptr<TaskRunners> task_runners_;
92 shell::ApplicationManager application_manager_;
93 URLResolver url_resolver_;
94 GURL shell_file_root_;
95 GURL command_line_cwd_;
96 base::Closure app_complete_callback_;
97 base::Time main_entry_time_;
99 DISALLOW_COPY_AND_ASSIGN(Context);
102 } // namespace runner
103 } // namespace mojo
105 #endif // MOJO_RUNNER_CONTEXT_H_