blob: 318366d805aaa382034563fade31aaa0e9746a8a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_COMMON_MOJO_STATIC_APPLICATION_LOADER_H_
#define CONTENT_COMMON_MOJO_STATIC_APPLICATION_LOADER_H_
#include <list>
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "mojo/shell/loader.h"
namespace base {
class SimpleThread;
}
namespace mojo {
class ShellClient;
}
namespace content {
// An Loader which loads a single type of app from a given
// mojo::ShellClientFactory. A Load() request is fulfilled by creating an
// instance of the app on a new thread. Only one instance of the app will run at
// a time. Any Load requests received while the app is running will be dropped.
class StaticLoader : public mojo::shell::Loader {
public:
using ApplicationFactory = base::Callback<scoped_ptr<mojo::ShellClient>()>;
// Constructs a static loader for |factory|.
explicit StaticLoader(const ApplicationFactory& factory);
// Constructs a static loader for |factory| with a closure that will be called
// when the loaded application quits.
StaticLoader(const ApplicationFactory& factory,
const base::Closure& quit_callback);
~StaticLoader() override;
// mojo::shell::Loader:
void Load(const std::string& name,
mojo::shell::mojom::ShellClientRequest request) override;
private:
void StopAppThread();
// The factory used t create new instances of the application delegate.
ApplicationFactory factory_;
// If not null, this is run when the loaded application quits.
base::Closure quit_callback_;
// Thread for the application if currently running.
scoped_ptr<base::SimpleThread> thread_;
base::WeakPtrFactory<StaticLoader> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(StaticLoader);
};
} // namespace content
#endif // CONTENT_COMMON_MOJO_STATIC_APPLICATION_LOADER_H_
|