OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CONTENT_PUBLIC_COMMON_STATIC_MOJO_APPLICATION_LOADER_H_ |
| 6 #define CONTENT_PUBLIC_COMMON_STATIC_MOJO_APPLICATION_LOADER_H_ |
| 7 |
| 8 #include <list> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "content/common/content_export.h" |
| 14 #include "mojo/shell/application_loader.h" |
| 15 |
| 16 namespace base { |
| 17 class Thread; |
| 18 } |
| 19 |
| 20 namespace mojo { |
| 21 class ApplicationDelegate; |
| 22 } |
| 23 |
| 24 namespace content { |
| 25 |
| 26 // An ApplicationLoader which knows how to instantiate a corresponding |
| 27 // ApplicationDelegate directly. Used to load applications which are linked |
| 28 // into content or its embedder. |
| 29 class CONTENT_EXPORT StaticMojoApplicationLoader |
| 30 : public mojo::shell::ApplicationLoader { |
| 31 public: |
| 32 using ApplicationFactory = |
| 33 base::Callback<scoped_ptr<mojo::ApplicationDelegate>()>; |
| 34 |
| 35 // Constructs a static loader for |factory|. |
| 36 explicit StaticMojoApplicationLoader(const ApplicationFactory& factory); |
| 37 |
| 38 // Constructs a static loader for |factory| with a closure that will be called |
| 39 // when the loaded application quits. |
| 40 StaticMojoApplicationLoader(const ApplicationFactory& factory, |
| 41 const base::Closure& quit_callback); |
| 42 |
| 43 ~StaticMojoApplicationLoader() override; |
| 44 |
| 45 // mojo::shell::ApplicationLoader: |
| 46 void Load(const GURL& url, |
| 47 mojo::InterfaceRequest<mojo::Application> request) override; |
| 48 |
| 49 private: |
| 50 using ThreadList = std::list<scoped_ptr<base::Thread>>; |
| 51 |
| 52 void CleanUpAppThread(typename ThreadList::iterator iter); |
| 53 |
| 54 // The factory used t create new instances of the application delegate. |
| 55 ApplicationFactory factory_; |
| 56 |
| 57 // If not null, this is called when an instance of the loaded application |
| 58 // quits. |
| 59 base::Closure quit_callback_; |
| 60 |
| 61 // List of all threads started by this loader. Each running instance of an |
| 62 // application will have a corresponding thread in this list. |
| 63 ThreadList threads_; |
| 64 |
| 65 base::WeakPtrFactory<StaticMojoApplicationLoader> weak_factory_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(StaticMojoApplicationLoader); |
| 68 }; |
| 69 |
| 70 } // namespace content |
| 71 |
| 72 #endif // CONTENT_PUBLIC_COMMON_STATIC_MOJO_APPLICATION_LOADER_H_ |
OLD | NEW |