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