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