gn: 'platform_impl' should be a group instead of component (since it has no code...
[chromium-blink-merge.git] / mojo / shell / static_application_loader.h
blobcbf611a0dac337cbb86cee8dda725e6481b62a6e
1 // Copyright 2015 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_SHELL_STATIC_APPLICATION_LOADER_H_
6 #define MOJO_SHELL_STATIC_APPLICATION_LOADER_H_
8 #include <list>
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h"
13 #include "mojo/shell/application_loader.h"
15 namespace base {
16 class SimpleThread;
19 namespace mojo {
20 class ApplicationDelegate;
23 namespace mojo {
24 namespace shell {
26 // An ApplicationLoader which loads a single type of app from a given
27 // ApplicationDelegate factory. A Load() request is fulfilled by creating an
28 // instance of the app on a new thread. Only one instance of the app will run at
29 // a time. Any Load requests received while the app is running will be dropped.
30 class StaticApplicationLoader : public mojo::shell::ApplicationLoader {
31 public:
32 using ApplicationFactory =
33 base::Callback<scoped_ptr<mojo::ApplicationDelegate>()>;
35 // Constructs a static loader for |factory|.
36 explicit StaticApplicationLoader(const ApplicationFactory& factory);
38 // Constructs a static loader for |factory| with a closure that will be called
39 // when the loaded application quits.
40 StaticApplicationLoader(const ApplicationFactory& factory,
41 const base::Closure& quit_callback);
43 ~StaticApplicationLoader() override;
45 // mojo::shell::ApplicationLoader:
46 void Load(const GURL& url,
47 mojo::InterfaceRequest<mojo::Application> request) override;
49 private:
50 void StopAppThread();
52 // The factory used t create new instances of the application delegate.
53 ApplicationFactory factory_;
55 // If not null, this is run when the loaded application quits.
56 base::Closure quit_callback_;
58 // Thread for the application if currently running.
59 scoped_ptr<base::SimpleThread> thread_;
61 base::WeakPtrFactory<StaticApplicationLoader> weak_factory_;
63 DISALLOW_COPY_AND_ASSIGN(StaticApplicationLoader);
66 } // namespace shell
67 } // namespace mojo
69 #endif // MOJO_SHELL_STATIC_APPLICATION_LOADER_H_